3 # This file may help you build the dependency packages that
4 # are needed to cross compile the Win64 bit version of the Bacula
5 # File daemon. This file is provided as is, and we don't guarantee
6 # that it will work. We run it only on Ubuntu Hardy. Trying to use
7 # it on any other GNU/Linux distro will probably require changes.
9 # This file is driven by the parameters that are defined in
10 # the file External-mingw-w64
15 echo "usage: $0 [-h] [-C] [<dependency 1>] [<dependency 2>] ..."
16 echo " -h Displays this usage"
17 echo " -C Clobbers (overwrites) the source code by "
18 echo " reextracting the archive and reapplying the"
21 echo "<dependency N> Optional dependency, If none are given then all"
22 echo " of them will be built."
24 echo "Valid dependencies are:"
25 grep -v '^#' < External-mingw-w64 | cut -d'|' -f1 | cut -d'_' -f1 | tr A-Z a-z | sort -u | awk '{ print " " $1 }'
30 while getopts "hHC" opt; do
32 H|h|\?) usage;exit 1;;
33 C) CLOBBER_SOURCE=true;;
37 [ ${OPTIND} -gt 1 ] && shift `expr ${OPTIND} - 1`
45 TOP_DIR=${DEPKGS:-${TOP_DIR}}
47 if [ -e ${TOP_DIR}/cross-tools/mingw-w64/bin/x86_64-pc-mingw32-gcc ]
49 cd ${TOP_DIR}/cross-tools/mingw-w64/bin
52 echo "The GCC cross compiler is not installed."
53 echo "You must run build-win64-cross-tools first"
57 [ ! -e ${TOP_DIR}/depkgs-mingw-w64 ] && mkdir ${TOP_DIR}/depkgs-mingw-w64
58 cd ${TOP_DIR}/depkgs-mingw-w64
61 export PATH=${BIN_DIR}:${PATH}
63 [ ! -e bin ] && mkdir bin
64 [ ! -e src ] && mkdir src
65 [ ! -e include ] && mkdir include
66 [ ! -e lib ] && mkdir lib
68 OLD_IFS=${IFS};IFS="|";
69 while read package url dir mkd; do
70 echo "Got package ${package}"
73 *) eval "URL_${package}=${url};DIR_${package}=${dir};MKD_${package}=${mkd}";;
75 done < ${SCRIPT_DIR}/External-mingw-w64
76 IFS=${OLD_IFS};unset OLD_IFS
83 echo "Processing ${URL}"
84 ARCHIVE=`basename ${URL}`
87 *.tar.gz) ARCHIVER="tar xzf"; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.gz'`;;
88 *.tar.bz2) ARCHIVER="tar xjf"; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.bz2'`;;
89 *.zip) ARCHIVER="unzip -q"; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.zip'`;;
90 *.exe) ARCHIVER=""; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.zip'`;;
91 *) echo Unsupported archive type - $ARCHIVE; exit 1;;
96 if [ ! -e "${ARCHIVE}" ]
98 echo Downloading "${URL}"
99 if wget --passive-ftp "${URL}"
103 echo Unable to download ${ARCHIVE}
108 [ -z "${ARCHIVER}" ] && return 0
110 if [ ! -e "${SRC_DIR}" -o "${CLOBBER_SOURCE}" = "true" ]
113 echo Extracting ${ARCHIVE}
114 if [ "${MAKE_DIR}" = "true" ]
118 ${ARCHIVER} ../${ARCHIVE} > ../${ARCHIVE}.log 2>&1
120 ${ARCHIVER} ${ARCHIVE} > ${ARCHIVE}.log 2>&1
132 sed -ne '/\\$/N' -e 's/\\\n//' -e 's/\t\+/ /g' -e 's/ \+/ /g' \
134 -e "s%.*Entering directory[ ]\\+.${DEPPKG_DIR}/\\([^ ]\+\).%Entering \\1%p" \
135 -e "s%.*Leaving directory[ ]\\+.${DEPPKG_DIR}/\\([^ ]\+.\).%Leaving \\1%p" \
136 -e '/gcc \|g\+\+ \|ar /!d' \
137 -e 's/ \(\.\.\/\)\+/ /g' \
138 -e 's/.* \([^ ]\+\(\.c\|\.cpp\|\.cc\|\.cxx\)\)\( .*\|\)$/Compiling \1/p' \
139 -e 's/.* \([^ ]\+\.s\)\( .*\|\)$/Assembling \1/p' \
140 -e 's/.*ar [^ ]\+ \([^ ]\+\)\(\( [^ ]\+\.o\)\+\)/Updating \1 -\2/p' \
141 -e 's/.* -o \([^ ]\+\)\( .*\|\)$/Linking \1/p'
146 PATCH_FILE=${SCRIPT_DIR}/patches/$1; shift
148 if patch -f -p0 "$@" >>patch.log < ${PATCH_FILE}
152 echo "Patch failed - Check `pwd`/patch.log" > /dev/tty
163 echo "Make failed - Check `pwd`/make.log" > /dev/tty
165 fi | tee -a make.log | parse_output
170 get_source "${URL_RSYNC}" "${DIR_RSYNC}" "${MKD_RSYNC}"
171 ./configure --host=x86_64-pc-mingw32
172 make -k # rdiff.exe has a problem
173 cp .libs/librsync.a ${DEPPKG_DIR}/lib
174 cp librsync*h ${DEPPKG_DIR}/include
179 if get_source "${URL_ZLIB}" "${DIR_ZLIB}" "${MKD_ZLIB}"
187 do_make win32/Makefile.mingw32 PREFIX=${DEPPKG_DIR} all
189 do_make win32/Makefile.mingw32 PREFIX=${DEPPKG_DIR} install
194 if get_source "${URL_PCRE}" "${DIR_PCRE}" "${MKD_PCRE}"
199 echo Configuring PCRE
200 ./configure CC_FOR_BUILD=gcc \
202 --host=x86_64-pc-mingw32 \
203 --prefix=${DEPPKG_DIR} \
205 --enable-unicode-properties >make.log 2>&1
208 do_make Makefile PREFIX=${DEPPKG_DIR} all
210 do_make Makefile PREFIX=${DEPPKG_DIR} install
215 if get_source "${URL_DB}" "${DIR_DB}" "${MKD_DB}"
220 ../dist/configure --host=x86_64-pc-mingw32 --enable-mingw --prefix=${DEPPKG_DIR}
225 do_make Makefile install_setup install_include install_lib
230 if get_source "${URL_PTHREADS}" "${DIR_PTHREADS}" "${MKD_PTHREADS}"
232 echo Patching pthreads
234 do_patch pthreads-w64.patch
236 echo Building pthreads
238 do_make GNUmakefile GCE
239 echo Installing pthreads
240 rm -rf ${DEPPKG_DIR}/include/pthreads
241 mkdir ${DEPPKG_DIR}/include/pthreads
242 cp -p *.h ${DEPPKG_DIR}/include/pthreads
243 cp -p *.dll ${DEPPKG_DIR}/bin
244 cp -p *.a ${DEPPKG_DIR}/lib
249 if get_source "${URL_OPENSSL}" "${DIR_OPENSSL}" "${MKD_OPENSSL}"
251 echo Patching openssl
253 do_patch openssl-w64.patch
254 echo Configuring openssl
255 echo ./Configure --prefix=${DEPPKG_DIR} \
256 shared zlib-dynamic no-dso no-hw \
258 --with-zlib-include=${DEPPKG_DIR}/include \
260 ./Configure --prefix=${DEPPKG_DIR} \
261 shared zlib-dynamic no-dso no-hw \
263 --with-zlib-include=${DEPPKG_DIR}/include \
264 mingw64 > make.log 2>&1
266 echo Building openssl
267 perl util/mkdef.pl 32 libeay no-static-engine >ms/libeay32.def
268 perl util/mkdef.pl 32 ssleay >ms/ssleay32.def
269 perl util/mkdef.pl crypto ssl NT update
270 sed -i 's/CC=/CC=mingw32-gcc #/' crypto/comp/Makefile
271 sed -i 's/AR=/AR=mingw32-ar r #/' crypto/comp/Makefile
272 sed -i "s:^CFLAGS=:CFLAGS= -I${DEPPKG_DIR}/include:" crypto/comp/Makefile
276 touch lib4758cca.bad libaep.bad libatalla.bad libcswift.bad libchil.bad libgmp.bad libnuron.bad libsureware.bad libubsec.bad libcapi.bad
279 echo Installing openssl
280 do_make Makefile install_sw install
281 cp *.dll ${DEPPKG_DIR}/bin
292 for dependency in "$@"
294 eval "process_${dependency}"
298 #Need to download from Microsoft