3 # Copyright (C) 2000-2018 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
6 # This file may help you build the dependency packages that
7 # are needed to cross compile the Win64 bit version of the Bacula
8 # File daemon. This file is provided as is, and we don't guarantee
9 # that it will work. We run it only on Ubuntu Hardy. Trying to use
10 # it on any other GNU/Linux distro will probably require changes.
12 # This file is driven by the parameters that are defined in
13 # the file External-mingw-w64
18 echo "usage: $0 [-h] [-C] [<dependency 1>] [<dependency 2>] ..."
19 echo " -h Displays this usage"
20 echo " -C Clobbers (overwrites) the source code by "
21 echo " reextracting the archive and reapplying the"
24 echo "<dependency N> Optional dependency, If none are given then all"
25 echo " of them will be built."
27 echo "Valid dependencies are:"
28 grep -v '^#' < External-mingw-w64 | cut -d'|' -f1 | cut -d'_' -f1 | tr A-Z a-z | sort -u | awk '{ print " " $1 }'
33 while getopts "hHC" opt; do
35 H|h|\?) usage;exit 1;;
36 C) CLOBBER_SOURCE=true;;
40 [ ${OPTIND} -gt 1 ] && shift `expr ${OPTIND} - 1`
48 TOP_DIR=${DEPKGS:-${TOP_DIR}}
50 if [ -e ${TOP_DIR}/cross-tools/mingw-w64/bin/x86_64-pc-mingw32-gcc ]
52 cd ${TOP_DIR}/cross-tools/mingw-w64/bin
55 elif which x86_64-w64-mingw32-gcc > /dev/null; then
57 BASE=x86_64-w64-mingw32
60 echo "The GCC cross compiler is not installed."
61 echo "You must run build-win64-cross-tools first"
65 [ ! -e ${TOP_DIR}/depkgs-mingw-w64 ] && mkdir ${TOP_DIR}/depkgs-mingw-w64
66 cd ${TOP_DIR}/depkgs-mingw-w64
69 export PATH=${BIN_DIR}:${PATH}
71 [ ! -e bin ] && mkdir bin
72 [ ! -e src ] && mkdir src
73 [ ! -e include ] && mkdir include
74 [ ! -e lib ] && mkdir lib
76 OLD_IFS=${IFS};IFS="|";
77 while read package url dir mkd; do
78 echo "Got package ${package}"
81 *) eval "URL_${package}=${url};DIR_${package}=${dir};MKD_${package}=${mkd}";;
83 done < ${SCRIPT_DIR}/External-mingw-w64
84 IFS=${OLD_IFS};unset OLD_IFS
91 echo "Processing ${URL}"
92 ARCHIVE=`basename ${URL}`
95 *.tar.gz) ARCHIVER="tar xzf"; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.gz'`;;
96 *.tar.bz2) ARCHIVER="tar xjf"; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.bz2'`;;
97 *.zip) ARCHIVER="unzip -d ."; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.zip'`;;
98 *.exe) ARCHIVER=""; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.zip'`;;
99 *) echo Unsupported archive type - $ARCHIVE; exit 1;;
104 if [ ! -e "${ARCHIVE}" ]
106 echo Downloading "${URL}"
107 if wget --passive-ftp "${URL}"
111 echo Unable to download ${ARCHIVE}
116 [ -z "${ARCHIVER}" ] && return 0
118 if [ ! -e "${SRC_DIR}" -o "${CLOBBER_SOURCE}" = "true" ]
121 echo Extracting ${ARCHIVE}
122 if [ "${MAKE_DIR}" = "true" ]
126 ${ARCHIVER} ../${ARCHIVE} > ../${ARCHIVE}.log 2>&1
128 ${ARCHIVER} ${ARCHIVE} > ${ARCHIVE}.log 2>&1
140 sed -ne '/\\$/N' -e 's/\\\n//' -e 's/\t\+/ /g' -e 's/ \+/ /g' \
142 -e "s%.*Entering directory[ ]\\+.${DEPPKG_DIR}/\\([^ ]\+\).%Entering \\1%p" \
143 -e "s%.*Leaving directory[ ]\\+.${DEPPKG_DIR}/\\([^ ]\+.\).%Leaving \\1%p" \
144 -e '/gcc \|g\+\+ \|ar /!d' \
145 -e 's/ \(\.\.\/\)\+/ /g' \
146 -e 's/.* \([^ ]\+\(\.c\|\.cpp\|\.cc\|\.cxx\)\)\( .*\|\)$/Compiling \1/p' \
147 -e 's/.* \([^ ]\+\.s\)\( .*\|\)$/Assembling \1/p' \
148 -e 's/.*ar [^ ]\+ \([^ ]\+\)\(\( [^ ]\+\.o\)\+\)/Updating \1 -\2/p' \
149 -e 's/.* -o \([^ ]\+\)\( .*\|\)$/Linking \1/p'
154 PATCH_FILE=${SCRIPT_DIR}/patches/$1; shift
156 if patch -f -p0 "$@" >>patch.log < ${PATCH_FILE}
160 echo "Patch failed - Check `pwd`/patch.log" > /dev/tty
171 echo "Make failed - Check `pwd`/make.log" > /dev/tty
173 fi | tee -a make.log | parse_output
178 get_source "${URL_RSYNC}" "${DIR_RSYNC}" "${MKD_RSYNC}"
179 ./configure --host=${BASE}
180 make -k # rdiff.exe has a problem
181 cp .libs/librsync.a ${DEPPKG_DIR}/lib
182 cp librsync*h ${DEPPKG_DIR}/include
187 if get_source "${URL_ZLIB}" "${DIR_ZLIB}" "${MKD_ZLIB}"
193 do_make win32/Makefile.gcc PREFIX=${BASE}- DESTDIR=${DEPPKG_DIR}/ all
195 do_make win32/Makefile.gcc PREFIX=${BASE}- DESTDIR=${DEPPKG_DIR}/ LIBRARY_PATH=lib BINARY_PATH=bin INCLUDE_PATH=include SHARED_MODE=1 install
200 if get_source "${URL_PCRE}" "${DIR_PCRE}" "${MKD_PCRE}"
205 echo Configuring PCRE
206 ./configure CC_FOR_BUILD=gcc \
209 --prefix=${DEPPKG_DIR} \
211 --enable-unicode-properties >make.log 2>&1
214 do_make Makefile PREFIX=${DEPPKG_DIR} all
216 do_make Makefile PREFIX=${DEPPKG_DIR} install
221 if get_source "${URL_DB}" "${DIR_DB}" "${MKD_DB}"
223 echo "No patch needed for this package"
226 ../dist/configure --host=${BASE} --enable-mingw --prefix=${DEPPKG_DIR}
231 do_make Makefile install_setup install_include install_lib
236 if get_source "${URL_PTHREADS}" "${DIR_PTHREADS}" "${MKD_PTHREADS}"
238 echo "No patch needed for this package"
240 echo Building pthreads
243 do_make GNUmakefile CROSS=${BASE}- clean GCE-inlined
244 echo Installing pthreads
245 rm -rf ${DEPPKG_DIR}/include/pthreads
246 mkdir ${DEPPKG_DIR}/include/pthreads
247 cp -p *.h ${DEPPKG_DIR}/include/pthreads
248 cp -p *.dll ${DEPPKG_DIR}/bin
249 cp -p *.a ${DEPPKG_DIR}/lib
254 if get_source "${URL_OPENSSL}" "${DIR_OPENSSL}" "${MKD_OPENSSL}"
256 echo Configuring openssl
257 CROSS_COMPILE=${BASE}- ./Configure --prefix=${DEPPKG_DIR} \
258 shared zlib-dynamic \
260 --with-zlib-include=${DEPPKG_DIR}/include \
261 mingw64 > make.log 2>&1
263 echo Building openssl
265 echo Installing openssl
266 do_make Makefile -k install_sw install
267 cp *.dll ${DEPPKG_DIR}/bin
272 if get_source "${URL_LZO}" "${DIR_LZO}" "${MKD_LZO}"
274 sed -i s/-lwinmm// configure
277 ./configure --host=${BASE} --prefix=${DEPPKG_DIR}/
279 do_make Makefile -k PREFIX=${DEPPKG_DIR}/ all
280 do_make Makefile -k PREFIX=${DEPPKG_DIR}/ install
285 if get_source "${URL_Qt4}" "${DIR_Qt4}" "${MKD_Qt4}"
289 patch -p1 < ${SCRIPT_DIR}/patches/qt4-intrinsics.patch
290 patch -p1 < ${SCRIPT_DIR}/patches/qt4-widget-ui.patch
291 patch -p1 < ${SCRIPT_DIR}/patches/qt4-compilation-see.patch
292 patch -p1 < ${SCRIPT_DIR}/patches/qt4-compilation.patch
294 echo "Configuring Qt4"
295 ./configure -opensource -confirm-license -fast -xplatform win32-g++-4.6 \
296 -device-option CROSS_COMPILE=x86_64-w64-mingw32- -device-option \
297 PKG_CONFIG='x86_64-w64-mingw32-pkg-config' -force-pkg-config -release \
298 -exceptions -shared -prefix ${DEPPKG_DIR}/qt-out -prefix-install -no-script \
299 -no-iconv -no-webkit -no-glib -no-gstreamer -no-phonon -no-phonon-backend \
300 -accessibility -no-reduce-exports -no-rpath -make libs -nomake demos \
301 -nomake docs -nomake examples -system-zlib -no-mitshm -no-libjpeg \
302 -no-libmng -no-libtiff -no-sql-db2 -no-sql-ibase -no-sql-mysql -no-sql-oci \
303 -no-sql-odbc -no-sql-psql -no-sql-sqlite -no-sql-sqlite2 \
304 -no-sql-sqlite_symbian -no-sql-symsql -no-sql-tds -no-nis -no-cups -no-dbus \
305 -no-openvg -no-openssl -no-nas-sound -no-audio-backend -no-sm -no-opengl \
306 -no-javascript-jit -no-qt3support -nomake tools \
307 -no-xmlpatterns -no-multimedia -nomake tools -silent
309 local qt_source_dir=`pwd`
310 # Required libz.dll.a, zlib.h and zconf.h for proper Qt build purpose
312 cd "${qt_source_dir}"
313 local zlib_dir=`basename "${URL_ZLIB}" | sed 's/.tar.gz//'`
314 cp "../${zlib_dir}/libz.dll.a" ./lib/
315 cp "../${zlib_dir}/zlib.h" ./include/
316 cp "../${zlib_dir}/zconf.h" ./include/
320 echo "Installing Qt4"
321 rm -rf ${DEPPKG_DIR}/include/qt ${DEPPKG_DIR}/lib/qt
322 mkdir -p ${DEPPKG_DIR}/include/qt ${DEPPKG_DIR}/lib/qt
323 cp -rf include/* ${DEPPKG_DIR}/include/qt
324 cp -rf lib/* ${DEPPKG_DIR}/lib/qt
325 cp -rf src/corelib ${DEPPKG_DIR}/src/
326 cp -rf src/gui ${DEPPKG_DIR}/src/
327 cp -rf lib/QtCore4.dll lib/QtGui4.dll ${DEPPKG_DIR}/bin/
328 cp -rf lib/QtCore4.dll lib/QtGui4.dll ${DEPPKG_DIR}/lib/qt/
334 if test -f /usr/lib/gcc/${BASE}/*posix/libstdc++-6.dll; then
335 cp -f /usr/lib/gcc/${BASE}/*posix/libstdc++-6.dll ${DEPPKG_DIR}/bin
336 cp -f /usr/lib/gcc/${BASE}/*posix/libgcc*dll ${DEPPKG_DIR}/bin
337 elif test -f /usr/lib/gcc/${BASE}/*/libstdc++-6.dll; then
338 cp -f /usr/${BASE}/lib/libstdc++-6.dll ${DEPPKG_DIR}/bin
339 cp -f /usr/${BASE}/lib/libgcc*dll ${DEPPKG_DIR}/bin
341 echo "ERROR: Unable to find ${BASE} on this system"
343 if test -f /usr/$BASE/lib/libwinpthread-1.dll; then
344 cp -f /usr/$BASE/lib/libwinpthread-1.dll ${DEPPKG_DIR}/bin
350 if get_source "${URL_MTX}" "${DIR_MTX}" "${MKD_MTX}"
353 # We can't run configure in a cross-compile environment so we
354 # patch the files to the correct values
355 cp -f config.h.in config.h
356 cp -f Makefile.in Makefile
362 do_make Makefile prefix=${DEPPKG_DIR} all
364 do_make Makefile prefix=${DEPPKG_DIR} install
369 if get_source "${URL_MT}" "${DIR_MT}" "${MKD_MT}"
376 do_make Makefile PREFIX=${DEPPKG_DIR} all
378 do_make Makefile PREFIX=${DEPPKG_DIR} install
383 if get_source "${URL_SED}" "${DIR_SED}" "${MKD_SED}"
387 # patch not needed for 4.2k which is already updated
390 ./configure --host=$BASE \
391 --prefix=${DEPPKG_DIR} \
392 --disable-nls >make.log 2>&1
397 do_make Makefile install
402 if get_source "${URL_CMD_UTILS}" "${DIR_CMD_UTILS}" "${MKD_CMD_UTILS}"
404 # echo Patching cmd-utils
406 # do_patch cmd-utils.patch
407 sed -i "s:strrchr:NULL;//:" expr64/expr64.cpp
408 echo Configuring cmd-utils
409 ./configure --host=$BASE \
410 --prefix=${DEPPKG_DIR} \
413 echo Building cmd-utils
415 echo Installing cmd-utils
416 do_make Makefile install
419 # MSSQL dlls are created from Visual Studio
422 get_source "${URL_MSSQL}" "${DIR_MSSQL}" "${MKD_MSSQL}"
423 echo Installing MSSQL driver
424 cp include/*.h ${DEPPKG_DIR}/include
425 cp x64/mssql-driver.dll ${DEPPKG_DIR}/bin
426 cp x64/mssql-regression.exe ${DEPPKG_DIR}/bin
445 for dependency in "$@"
447 eval "process_${dependency}"
451 #Need to download from Microsoft