#!/bin/bash
#
# Copyright 2010, 2011 wkhtmltopdf authors
#
# This file is part of wkhtmltopdf.
#
# wkhtmltopdf is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wkhtmltopdf is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with wkhtmltopdf. If not, see .
# This script will compile static versions of wkhtmltopdf for linux and for windows (it must run in linux)
# It requires build-essential and wine to run. Please note that it will take quite a while
#Configuration for the static build
MIRROR=kent
MINGWFILES="binutils-2.19.1-mingw32-bin.tar.gz \
mingw32-make-3.81-20090910.tar.gz \
gcc-full-4.4.0-mingw32-bin-2.tar.lzma \
w32api-3.13-mingw32-dev.tar.gz \
mingwrt-3.16-mingw32-dev.tar.gz \
mingwrt-3.16-mingw32-dll.tar.gz"
GNUWIN32FILES="openssl-0.9.8h-1-lib.zip \
openssl-0.9.8h-1-bin.zip "
#freetype-2.3.5-1-bin.zip \
#freetype-2.3.5-1-lib.zip "
QTBRANCH=
J="$((1 + $(cat /proc/cpuinfo | grep -c processor)))"
function usage() {
echo "Usage: $0 [OPTIONS] target"
echo ""
echo "Options:"
echo "-h Display this help message"
echo "-q branch Use this qt branch"
echo "-v version Compile this version of wkhtmltopdf"
echo ""
echo "Target:"
echo "linux-local Compile under local linux distro"
echo "linux-amd64 Compile under debian 64bit chroot"
echo "linux-i368 Compile under debian 32bit chroot"
echo "windows Compile windows binary using wine"
}
VERSION=""
QTBRANCH="staging"
while getopts hq:v: O; do
case "$O" in
[h?])
usage
exit 1
;;
v)
shift 2
VERSION=$OPTARG
;;
q)
shift 2
QTBRANCH=$OPTARG
;;
esac
done
if file /bin/true | grep -q 64-bit; then
UPX=upx-3.03-amd64_linux
else
UPX=upx-3.03-i386_linux
fi
#Helper functions
function get() {
[ -f $2.download ] || (rm -rf $2; wget $1 -O $2 && touch $2.download)
}
function unpack() {
[ -f $1.unpack ] || (echo "unpacking $1"; (tar -xf $1 || unzip -o $1) && touch $1.unpack)
}
BASE=${PWD}
BUILD=${BASE}/static-build
VERSION=$2
function git_fetch_and_update() {
if [ ! -d "$1" ]; then
git clone "$2" "$1" || (rm -rf "$1" && return 1)
fi
cd "$1"
git fetch origin
if ! (git checkout "$3" -f 2>/dev/null && git pull origin "$3" 2>/dev/null); then
git branch -a
git checkout origin/"$3" -f 2>/dev/null || return 1
git branch -D "$3" 2>/dev/null
git checkout origin/"$3" -b "$3" || return 1
git pull origin "$3" -f || return 1
fi
cd ..
}
function checkout() {
#Create static build directory
mkdir -p $BUILD
cd ${BUILD}
#Fetch and unpack upx
get http://upx.sourceforge.net/download/${UPX}.tar.bz2 ${UPX}.tar.bz2 || exit 1
unpack ${UPX}.tar.bz2 || exit 1
#Fetch most recent version of qt
echo "Updating qt from remote"
git_fetch_and_update qt git://gitorious.org/+wkhtml2pdf/qt/wkhtmltopdf-qt.git "$QTBRANCH" || exit 1
cd qt
}
function setup_build() {
echo "Updating QT"
git_fetch_and_update qts ${BUILD}/qt "$QTBRANCH" || exit 1
cd qts
if ! [ -z "$VERSION" ] ; then
git checkout wkhtmltopdf-$VERSION || exit 1
fi
touch conf
cat ${BASE}/static_qt_conf_base ${BASE}/static_qt_conf_${1} | sed -re 's/#.*//' | sed -re '/^[ \t]*$/d' | sort -u > conf_new
cd ..
echo "$(cd ${BASE} && git branch --no-color | sed -nre 's/\* //p')"
git_fetch_and_update wkhtmltopdf "${BASE}" "$(cd ${BASE} && git branch --no-color | sed -nre 's/\* //p')" || exit 1
cd wkhtmltopdf
if ! [ -z "$VERSION" ] ; then
git checkout "$VERSION" || exit 1
fi
cd ..
[ "$1" == "win" ] && return
cat > build.sh < linux-$2/build/buildw.sh
chmod +x linux-$2/build/buildw.sh || exit 1
}
function build_linux_chroot() {
cd ${BUILD}
setup_chroot lenny $1
cd linux-$1/build
setup_build linux
if [ "$1" == 'i386' ]; then
sudo linux32 chroot ${BUILD}/linux-$1/ /build/buildw.sh || exit 1
else
sudo chroot ${BUILD}/linux-$1/ /build/buildw.sh || exit 1
fi
packandcopylinux $1
}
function build_windows() {
cd ${BUILD}
export WINEPREFIX=${BUILD}/windows
if [ ! -f ${BUILD}/windows/create ]; then
cat > tmp <