]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/build-depkgs-mingw-w64
Tweak win32 build for Zdeflate changes
[bacula/bacula] / bacula / src / win32 / build-depkgs-mingw-w64
1 #!/bin/sh
2 #
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.
8 #
9 #  This file is driven by the parameters that are defined in
10 #    the file External-mingw-w64
11 #
12
13 usage()
14 {
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"
19    echo "               patches."
20    echo ""
21    echo "<dependency N> Optional dependency, If none are given then all"
22    echo "               of them will be built."
23    echo ""
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 }'
26 }
27
28 CLOBBER_SOURCE=
29
30 while getopts "hHC" opt; do
31    case ${opt} in
32    H|h|\?) usage;exit 1;;
33    C)      CLOBBER_SOURCE=true;;
34    esac
35 done
36
37 [ ${OPTIND} -gt 1 ] && shift `expr ${OPTIND} - 1`
38
39 cwd=`pwd`
40 cd `dirname $0`
41 SCRIPT_DIR=`pwd`
42
43 cd ../../..
44 TOP_DIR=`pwd`
45 TOP_DIR=${DEPKGS:-${TOP_DIR}}
46
47 if [ -e ${TOP_DIR}/cross-tools/mingw-w64/bin/x86_64-pc-mingw32-gcc ]
48 then
49    cd ${TOP_DIR}/cross-tools/mingw-w64/bin
50    BIN_DIR=`pwd`
51 else
52    echo "The GCC cross compiler is not installed."
53    echo "You must run build-win64-cross-tools first"
54    exit 1
55 fi
56
57 [ ! -e ${TOP_DIR}/depkgs-mingw-w64 ] && mkdir ${TOP_DIR}/depkgs-mingw-w64
58 cd ${TOP_DIR}/depkgs-mingw-w64
59 DEPPKG_DIR=`pwd`
60
61 export PATH=${BIN_DIR}:${PATH}
62
63 [ ! -e bin ] && mkdir bin
64 [ ! -e src ] && mkdir src
65 [ ! -e include ] && mkdir include
66 [ ! -e lib ] && mkdir lib
67
68 OLD_IFS=${IFS};IFS="|";
69 while read package url dir mkd; do
70    echo "Got package ${package}"
71    case ${package} in
72    \#*) ;;
73    *) eval "URL_${package}=${url};DIR_${package}=${dir};MKD_${package}=${mkd}";;
74         esac
75 done < ${SCRIPT_DIR}/External-mingw-w64
76 IFS=${OLD_IFS};unset OLD_IFS
77
78 get_source()
79 {
80    URL=$1
81    SRC_DIR=$2
82    MAKE_DIR=$3
83    echo "Processing ${URL}"
84    ARCHIVE=`basename ${URL}`
85    
86    case ${ARCHIVE} in
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;;
92    esac
93    
94    cd ${DEPPKG_DIR}/src
95    
96    if [ ! -e "${ARCHIVE}" ]
97    then 
98       echo Downloading "${URL}"
99       if wget --passive-ftp "${URL}"
100       then
101          :
102       else
103          echo Unable to download ${ARCHIVE}
104          exit 1
105       fi
106    fi
107
108    [ -z "${ARCHIVER}" ] && return 0
109
110    if [ ! -e "${SRC_DIR}" -o "${CLOBBER_SOURCE}" = "true" ]
111    then
112       rm -rf ${SRC_DIR}
113       echo Extracting ${ARCHIVE}
114       if [ "${MAKE_DIR}" = "true" ]
115       then
116          mkdir ${SRC_DIR}
117          cd ${SRC_DIR}
118          ${ARCHIVER} ../${ARCHIVE} > ../${ARCHIVE}.log 2>&1
119       else
120          ${ARCHIVER} ${ARCHIVE} > ${ARCHIVE}.log 2>&1
121          cd ${SRC_DIR}
122       fi
123       return 0
124    fi
125
126    cd ${SRC_DIR}
127    return 1
128 }
129
130 parse_output()
131 {
132    sed -ne '/\\$/N' -e 's/\\\n//' -e 's/\t\+/ /g' -e 's/ \+/ /g' \
133        -e '/ error: /p' \
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'
142 }
143
144 do_patch()
145 {
146    PATCH_FILE=${SCRIPT_DIR}/patches/$1; shift
147    
148    if patch -f -p0 "$@" >>patch.log < ${PATCH_FILE}
149    then
150       :
151    else
152       echo "Patch failed - Check `pwd`/patch.log" > /dev/tty
153       exit 1
154    fi
155 }
156
157 do_make()
158 {
159    if make -f "$@" 2>&1
160    then
161       :
162    else
163       echo "Make failed - Check `pwd`/make.log" > /dev/tty
164       exit 1
165    fi | tee -a make.log | parse_output
166 }
167
168 process_rsync()
169 {
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
175 }
176
177 process_zlib()
178 {
179    if get_source "${URL_ZLIB}" "${DIR_ZLIB}" "${MKD_ZLIB}"
180    then
181       echo "Patching zlib"
182       >patch.log
183       do_patch zlib.patch
184    fi
185    echo Building zlib
186    > make.log
187    do_make win32/Makefile.mingw32 PREFIX=${DEPPKG_DIR} all
188    echo Installing zlib
189    do_make win32/Makefile.mingw32 PREFIX=${DEPPKG_DIR} install
190 }
191
192 process_pcre()
193 {
194    if get_source "${URL_PCRE}" "${DIR_PCRE}" "${MKD_PCRE}"
195    then
196            echo Patching PCRE
197            >patch.log
198            do_patch pcre.patch
199            echo Configuring PCRE
200            ./configure CC_FOR_BUILD=gcc \
201                        CXX_FOR_BUILD=g++ \
202                        --host=x86_64-pc-mingw32 \
203                        --prefix=${DEPPKG_DIR} \
204                        --enable-utf8 \
205                        --enable-unicode-properties >make.log 2>&1
206    fi
207    echo Building PCRE
208    do_make Makefile PREFIX=${DEPPKG_DIR} all
209    echo Installing PCRE
210    do_make Makefile PREFIX=${DEPPKG_DIR} install
211 }
212
213 process_db()
214 {
215    if get_source "${URL_DB}" "${DIR_DB}" "${MKD_DB}"
216    then
217           echo No Patch
218    fi
219    cd build_unix
220    ../dist/configure --host=x86_64-pc-mingw32 --enable-mingw --prefix=${DEPPKG_DIR}
221    > make.log
222    echo Building DB
223    do_make Makefile
224    echo Installing DB
225    do_make Makefile install_setup install_include install_lib
226 }
227
228 process_pthreads()
229 {
230    if get_source "${URL_PTHREADS}" "${DIR_PTHREADS}" "${MKD_PTHREADS}"
231    then
232            echo Patching pthreads
233            >patch.log
234            do_patch pthreads-w64.patch
235    fi
236    echo Building pthreads
237    > make.log
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
245 }
246
247 process_openssl()
248 {
249    if get_source "${URL_OPENSSL}" "${DIR_OPENSSL}" "${MKD_OPENSSL}"
250    then
251            echo Patching openssl
252            >patch.log
253            do_patch openssl-w64.patch
254            echo Configuring openssl
255            echo ./Configure --prefix=${DEPPKG_DIR} \
256                        shared zlib-dynamic no-dso no-hw \
257                        threads \
258                        --with-zlib-include=${DEPPKG_DIR}/include \
259                        mingw64
260            ./Configure --prefix=${DEPPKG_DIR} \
261                        shared zlib-dynamic no-dso no-hw \
262                        threads \
263                        --with-zlib-include=${DEPPKG_DIR}/include \
264                        mingw64 > make.log 2>&1
265    fi
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
273
274    do_make Makefile all
275    cd engines
276    touch lib4758cca.bad libaep.bad libatalla.bad libcswift.bad libchil.bad libgmp.bad libnuron.bad libsureware.bad libubsec.bad libcapi.bad
277    cd ..
278    do_make Makefile all
279    echo Installing openssl
280    do_make Makefile install_sw install
281    cp *.dll ${DEPPKG_DIR}/bin
282 }
283
284 if [ "$#" -eq 0 ]
285 then
286    process_zlib
287    process_rsync
288    process_pcre
289    process_pthreads
290    process_openssl
291 else
292    for dependency in "$@"
293    do
294       eval "process_${dependency}"
295    done
296 fi
297 #vss
298 #Need to download from Microsoft