]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/build-depkgs-mingw-w64
Restore win32 dir from Branch-5.2 and update it
[bacula/bacula] / bacula / src / win32 / build-depkgs-mingw-w64
1 #!/bin/sh
2 #
3 # Copyright (C) 2000-2018 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
5 #
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.
11 #
12 #  This file is driven by the parameters that are defined in
13 #    the file External-mingw-w64
14 #
15
16 usage()
17 {
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"
22    echo "               patches."
23    echo ""
24    echo "<dependency N> Optional dependency, If none are given then all"
25    echo "               of them will be built."
26    echo ""
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 }'
29 }
30
31 CLOBBER_SOURCE=
32
33 while getopts "hHC" opt; do
34    case ${opt} in
35    H|h|\?) usage;exit 1;;
36    C)      CLOBBER_SOURCE=true;;
37    esac
38 done
39
40 [ ${OPTIND} -gt 1 ] && shift `expr ${OPTIND} - 1`
41
42 cwd=`pwd`
43 cd `dirname $0`
44 SCRIPT_DIR=`pwd`
45
46 cd ../../..
47 TOP_DIR=`pwd`
48 TOP_DIR=${DEPKGS:-${TOP_DIR}}
49
50 if [ -e ${TOP_DIR}/cross-tools/mingw-w64/bin/x86_64-pc-mingw32-gcc ]
51 then
52    cd ${TOP_DIR}/cross-tools/mingw-w64/bin
53    BIN_DIR=`pwd`
54
55 elif which x86_64-w64-mingw32-gcc > /dev/null; then
56    BIN_DIR=
57    BASE=x86_64-w64-mingw32
58
59 else
60    echo "The GCC cross compiler is not installed."
61    echo "You must run build-win64-cross-tools first"
62    exit 1
63 fi
64
65 [ ! -e ${TOP_DIR}/depkgs-mingw-w64 ] && mkdir ${TOP_DIR}/depkgs-mingw-w64
66 cd ${TOP_DIR}/depkgs-mingw-w64
67 DEPPKG_DIR=`pwd`
68
69 export PATH=${BIN_DIR}:${PATH}
70
71 [ ! -e bin ] && mkdir bin
72 [ ! -e src ] && mkdir src
73 [ ! -e include ] && mkdir include
74 [ ! -e lib ] && mkdir lib
75
76 OLD_IFS=${IFS};IFS="|";
77 while read package url dir mkd; do
78    echo "Got package ${package}"
79    case ${package} in
80    \#*) ;;
81    *) eval "URL_${package}=${url};DIR_${package}=${dir};MKD_${package}=${mkd}";;
82         esac
83 done < ${SCRIPT_DIR}/External-mingw-w64
84 IFS=${OLD_IFS};unset OLD_IFS
85
86 get_source()
87 {
88    URL=$1
89    SRC_DIR=$2
90    MAKE_DIR=$3
91    echo "Processing ${URL}"
92    ARCHIVE=`basename ${URL}`
93    
94    case ${ARCHIVE} in
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;;
100    esac
101    
102    cd ${DEPPKG_DIR}/src
103    
104    if [ ! -e "${ARCHIVE}" ]
105    then 
106       echo Downloading "${URL}"
107       if wget --passive-ftp "${URL}"
108       then
109          :
110       else
111          echo Unable to download ${ARCHIVE}
112          exit 1
113       fi
114    fi
115
116    [ -z "${ARCHIVER}" ] && return 0
117
118    if [ ! -e "${SRC_DIR}" -o "${CLOBBER_SOURCE}" = "true" ]
119    then
120       rm -rf ${SRC_DIR}
121       echo Extracting ${ARCHIVE}
122       if [ "${MAKE_DIR}" = "true" ]
123       then
124          mkdir ${SRC_DIR}
125          cd ${SRC_DIR}
126          ${ARCHIVER} ../${ARCHIVE} > ../${ARCHIVE}.log 2>&1
127       else
128          ${ARCHIVER} ${ARCHIVE} > ${ARCHIVE}.log 2>&1
129          cd ${SRC_DIR}
130       fi
131       return 0
132    fi
133
134    cd ${SRC_DIR}
135    return 1
136 }
137
138 parse_output()
139 {
140    sed -ne '/\\$/N' -e 's/\\\n//' -e 's/\t\+/ /g' -e 's/ \+/ /g' \
141        -e '/ error: /p' \
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'
150 }
151
152 do_patch()
153 {
154    PATCH_FILE=${SCRIPT_DIR}/patches/$1; shift
155    
156    if patch -f -p0 "$@" >>patch.log < ${PATCH_FILE}
157    then
158       :
159    else
160       echo "Patch failed - Check `pwd`/patch.log" > /dev/tty
161       exit 1
162    fi
163 }
164
165 do_make()
166 {
167    if make -f "$@" 2>&1
168    then
169       :
170    else
171       echo "Make failed - Check `pwd`/make.log" > /dev/tty
172       exit 1
173    fi | tee -a make.log | parse_output
174 }
175
176 process_rsync()
177 {
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
183 }
184
185 process_zlib()
186 {
187    if get_source "${URL_ZLIB}" "${DIR_ZLIB}" "${MKD_ZLIB}"
188    then
189       true
190    fi
191    echo Building zlib
192    > make.log
193    do_make win32/Makefile.gcc PREFIX=${BASE}-  DESTDIR=${DEPPKG_DIR}/ all
194    echo Installing zlib
195    do_make win32/Makefile.gcc PREFIX=${BASE}-  DESTDIR=${DEPPKG_DIR}/ LIBRARY_PATH=lib BINARY_PATH=bin INCLUDE_PATH=include SHARED_MODE=1 install
196 }
197
198 process_pcre()
199 {
200    if get_source "${URL_PCRE}" "${DIR_PCRE}" "${MKD_PCRE}"
201    then
202            echo Patching PCRE
203            >patch.log
204            do_patch pcre.patch
205            echo Configuring PCRE
206            ./configure CC_FOR_BUILD=gcc \
207                        CXX_FOR_BUILD=g++ \
208                        --host=${BASE} \
209                        --prefix=${DEPPKG_DIR} \
210                        --enable-utf8 \
211                        --enable-unicode-properties >make.log 2>&1
212    fi
213    echo Building PCRE
214    do_make Makefile PREFIX=${DEPPKG_DIR} all
215    echo Installing PCRE
216    do_make Makefile PREFIX=${DEPPKG_DIR} install
217 }
218
219 process_db()
220 {
221    if get_source "${URL_DB}" "${DIR_DB}" "${MKD_DB}"
222    then
223           echo "No patch needed for this package"
224    fi
225    cd build_unix
226    ../dist/configure --host=${BASE} --enable-mingw --prefix=${DEPPKG_DIR}
227    > make.log
228    echo Building DB
229    do_make Makefile
230    echo Installing DB
231    do_make Makefile install_setup install_include install_lib
232 }
233
234 process_pthreads()
235 {
236    if get_source "${URL_PTHREADS}" "${DIR_PTHREADS}" "${MKD_PTHREADS}"
237    then
238       echo "No patch needed for this package"
239    fi
240    echo Building pthreads
241    cd pthreads.2
242    > make.log
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
250 }
251
252 process_openssl()
253 {
254    if get_source "${URL_OPENSSL}" "${DIR_OPENSSL}" "${MKD_OPENSSL}"
255    then
256            echo Configuring openssl
257            CROSS_COMPILE=${BASE}- ./Configure --prefix=${DEPPKG_DIR} \
258                        shared zlib-dynamic \
259                        threads \
260                        --with-zlib-include=${DEPPKG_DIR}/include \
261                        mingw64 > make.log 2>&1
262    fi
263    echo Building openssl
264    do_make Makefile all
265    echo Installing openssl
266    do_make Makefile -k install_sw install
267    cp *.dll ${DEPPKG_DIR}/bin
268 }
269
270 process_lzo()
271 {
272    if get_source "${URL_LZO}" "${DIR_LZO}" "${MKD_LZO}"
273    then
274         sed -i s/-lwinmm// configure
275    fi
276    echo Building lzo
277    ./configure --host=${BASE} --prefix=${DEPPKG_DIR}/
278    echo Installing lzo
279    do_make Makefile -k PREFIX=${DEPPKG_DIR}/ all
280    do_make Makefile -k PREFIX=${DEPPKG_DIR}/ install
281 }
282
283 process_qt4()
284 {
285    if get_source "${URL_Qt4}" "${DIR_Qt4}" "${MKD_Qt4}"
286    then
287       echo Patching Qt4
288       >patch.log
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
293    fi
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
308
309    local qt_source_dir=`pwd`
310    # Required libz.dll.a, zlib.h and zconf.h for proper Qt build purpose
311    process_zlib
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/
317
318    make
319
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/
329 }
330
331
332 process_mingw()
333 {
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
340    else
341       echo "ERROR: Unable to find ${BASE} on this system"
342    fi
343    if test -f /usr/$BASE/lib/libwinpthread-1.dll; then
344       cp -f /usr/$BASE/lib/libwinpthread-1.dll ${DEPPKG_DIR}/bin
345    fi
346 }
347
348 process_mtx()
349 {
350    if get_source "${URL_MTX}" "${DIR_MTX}" "${MKD_MTX}"
351    then
352            echo Patching 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
357            rm -f configure
358            >patch.log
359            do_patch mtx.patch
360    fi
361    echo Building mtx
362    do_make Makefile prefix=${DEPPKG_DIR} all
363    echo Installing mtx
364    do_make Makefile prefix=${DEPPKG_DIR} install
365 }
366
367 process_mt()
368 {
369    if get_source "${URL_MT}" "${DIR_MT}" "${MKD_MT}"
370    then
371            echo "Patching mt"
372            >patch.log
373            do_patch mt.patch
374    fi
375    echo "Building mt"
376    do_make Makefile PREFIX=${DEPPKG_DIR} all
377    echo Installing mt
378    do_make Makefile PREFIX=${DEPPKG_DIR} install
379 }
380
381 process_sed()
382 {
383    if get_source "${URL_SED}" "${DIR_SED}" "${MKD_SED}"
384    then
385            echo Patching sed
386            >patch.log
387            # patch not needed for 4.2k which is already updated
388            # do_patch sed.patch
389            echo Configuring sed
390            ./configure --host=$BASE \
391                        --prefix=${DEPPKG_DIR} \
392                        --disable-nls >make.log 2>&1
393    fi
394    echo Building sed
395    do_make Makefile all
396    echo Installing sed
397    do_make Makefile install
398 }
399
400 process_cmd_utils()
401 {
402    if get_source "${URL_CMD_UTILS}" "${DIR_CMD_UTILS}" "${MKD_CMD_UTILS}"
403    then
404            # echo Patching cmd-utils
405            # >patch.log
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} \
411                        >make.log 2>&1
412    fi
413    echo Building cmd-utils
414    do_make Makefile 
415    echo Installing cmd-utils
416    do_make Makefile install
417 }
418
419 # MSSQL dlls are created from Visual Studio
420 process_mssql()
421 {
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
427 }
428
429 if [ "$#" -eq 0 ]
430 then
431    process_mingw
432    process_rsync
433    process_lzo
434    process_zlib
435 #   process_pcre
436    process_pthreads
437    process_openssl
438    process_qt4
439    process_sed
440    process_cmd_utils
441    process_mssql
442 #   process_mtx
443 #   process_mt
444 else
445    for dependency in "$@"
446    do
447       eval "process_${dependency}"
448    done
449 fi
450 #vss
451 #Need to download from Microsoft