]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/build-depkgs-mingw-w64
Tweak fix MySQL quoting again :-(
[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
46 if [ -e ${TOP_DIR}/cross-tools/mingw-w64/bin/x86_64-pc-mingw32-gcc ]
47 then
48    cd ${TOP_DIR}/cross-tools/mingw-w64/bin
49    BIN_DIR=`pwd`
50 else
51    echo "The GCC cross compiler isn\'t installed."
52    echo "You must run build-win64-cross-tools first"
53    exit 1
54 fi
55
56 [ ! -e ${TOP_DIR}/depkgs-mingw-w64 ] && mkdir ${TOP_DIR}/depkgs-mingw-w64
57 cd ${TOP_DIR}/depkgs-mingw-w64
58 DEPPKG_DIR=`pwd`
59
60 export PATH=${BIN_DIR}:${PATH}
61
62 [ ! -e bin ] && mkdir bin
63 [ ! -e src ] && mkdir src
64 [ ! -e include ] && mkdir include
65 [ ! -e lib ] && mkdir lib
66
67 OLD_IFS=${IFS};IFS="|";
68 while read package url dir mkd; do
69    echo "Got package ${package}"
70    case ${package} in
71    \#*) ;;
72    *) eval "URL_${package}=${url};DIR_${package}=${dir};MKD_${package}=${mkd}";;
73         esac
74 done < ${SCRIPT_DIR}/External-mingw-w64
75 IFS=${OLD_IFS};unset OLD_IFS
76
77 get_source()
78 {
79    URL=$1
80    SRC_DIR=$2
81    MAKE_DIR=$3
82    echo "Processing ${URL}"
83    ARCHIVE=`basename ${URL}`
84    
85    case ${ARCHIVE} in
86    *.tar.gz)       ARCHIVER="tar xzf";    [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.gz'`;;
87    *.tar.bz2)      ARCHIVER="tar xjf";    [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.bz2'`;;
88    *.zip)          ARCHIVER="unzip -q";   [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.zip'`;;
89    *.exe)          ARCHIVER="";           [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.zip'`;;
90    *)              echo Unsupported archive type - $ARCHIVE; exit 1;;
91    esac
92    
93    cd ${DEPPKG_DIR}/src
94    
95    if [ ! -e "${ARCHIVE}" ]
96    then 
97       echo Downloading "${URL}"
98       if wget --passive-ftp "${URL}"
99       then
100          :
101       else
102          echo Unable to download ${ARCHIVE}
103          exit 1
104       fi
105    fi
106
107    [ -z "${ARCHIVER}" ] && return 0
108
109    if [ ! -e "${SRC_DIR}" -o "${CLOBBER_SOURCE}" = "true" ]
110    then
111       rm -rf ${SRC_DIR}
112       echo Extracting ${ARCHIVE}
113       if [ "${MAKE_DIR}" = "true" ]
114       then
115          mkdir ${SRC_DIR}
116          cd ${SRC_DIR}
117          ${ARCHIVER} ../${ARCHIVE} > ../${ARCHIVE}.log 2>&1
118       else
119          ${ARCHIVER} ${ARCHIVE} > ${ARCHIVE}.log 2>&1
120          cd ${SRC_DIR}
121       fi
122       return 0
123    fi
124
125    cd ${SRC_DIR}
126    return 1
127 }
128
129 parse_output()
130 {
131    sed -ne '/\\$/N' -e 's/\\\n//' -e 's/\t\+/ /g' -e 's/ \+/ /g' \
132        -e '/ error: /p' \
133        -e "s%.*Entering directory[ ]\\+.${DEPPKG_DIR}/\\([^ ]\+\).%Entering \\1%p" \
134        -e "s%.*Leaving directory[ ]\\+.${DEPPKG_DIR}/\\([^ ]\+.\).%Leaving \\1%p" \
135        -e '/gcc \|g\+\+ \|ar /!d' \
136        -e 's/ \(\.\.\/\)\+/ /g' \
137        -e 's/.* \([^ ]\+\(\.c\|\.cpp\|\.cc\|\.cxx\)\)\( .*\|\)$/Compiling \1/p' \
138        -e 's/.* \([^ ]\+\.s\)\( .*\|\)$/Assembling \1/p' \
139        -e 's/.*ar [^ ]\+ \([^ ]\+\)\(\( [^ ]\+\.o\)\+\)/Updating \1 -\2/p' \
140        -e 's/.* -o \([^ ]\+\)\( .*\|\)$/Linking \1/p'
141 }
142
143 do_patch()
144 {
145    PATCH_FILE=${SCRIPT_DIR}/patches/$1; shift
146    
147    if patch -f -p0 "$@" >>patch.log < ${PATCH_FILE}
148    then
149       :
150    else
151       echo "Patch failed - Check `pwd`/patch.log" > /dev/tty
152       exit 1
153    fi
154 }
155
156 do_make()
157 {
158    if make -f "$@" 2>&1
159    then
160       :
161    else
162       echo "Make failed - Check `pwd`/make.log" > /dev/tty
163       exit 1
164    fi | tee -a make.log | parse_output
165 }
166
167 process_zlib()
168 {
169    if get_source "${URL_ZLIB}" "${DIR_ZLIB}" "${MKD_ZLIB}"
170    then
171       echo "Patching zlib"
172       >patch.log
173       do_patch zlib.patch
174    fi
175    echo Building zlib
176    > make.log
177    do_make win32/Makefile.mingw32 PREFIX=${DEPPKG_DIR} all
178    echo Installing zlib
179    do_make win32/Makefile.mingw32 PREFIX=${DEPPKG_DIR} install
180 }
181
182 process_pcre()
183 {
184    if get_source "${URL_PCRE}" "${DIR_PCRE}" "${MKD_PCRE}"
185    then
186            echo Patching PCRE
187            >patch.log
188            do_patch pcre.patch
189            echo Configuring PCRE
190            ./configure CC_FOR_BUILD=gcc \
191                        CXX_FOR_BUILD=g++ \
192                        --host=x86_64-pc-mingw32 \
193                        --prefix=${DEPPKG_DIR} \
194                        --enable-utf8 \
195                        --enable-unicode-properties >make.log 2>&1
196    fi
197    echo Building PCRE
198    do_make Makefile PREFIX=${DEPPKG_DIR} all
199    echo Installing PCRE
200    do_make Makefile PREFIX=${DEPPKG_DIR} install
201 }
202
203 process_db()
204 {
205    if get_source "${URL_DB}" "${DIR_DB}" "${MKD_DB}"
206    then
207           echo No Patch
208    fi
209    cd build_unix
210    ../dist/configure --host=x86_64-pc-mingw32 --enable-mingw --prefix=${DEPPKG_DIR}
211    > make.log
212    echo Building DB
213    do_make Makefile
214    echo Installing DB
215    do_make Makefile install_setup install_include install_lib
216 }
217
218 process_pthreads()
219 {
220    if get_source "${URL_PTHREADS}" "${DIR_PTHREADS}" "${MKD_PTHREADS}"
221    then
222            echo Patching pthreads
223            >patch.log
224            do_patch pthreads-w64.patch
225    fi
226    echo Building pthreads
227    > make.log
228    do_make GNUmakefile GCE
229    echo Installing pthreads
230    rm -rf ${DEPPKG_DIR}/include/pthreads
231    mkdir ${DEPPKG_DIR}/include/pthreads
232    cp -p *.h ${DEPPKG_DIR}/include/pthreads
233    cp -p *.dll ${DEPPKG_DIR}/bin
234    cp -p *.a ${DEPPKG_DIR}/lib
235 }
236
237 process_openssl()
238 {
239    if get_source "${URL_OPENSSL}" "${DIR_OPENSSL}" "${MKD_OPENSSL}"
240    then
241            echo Patching openssl
242            >patch.log
243            do_patch openssl-w64.patch
244            echo Configuring openssl
245            echo ./Configure --prefix=${DEPPKG_DIR} \
246                        shared zlib-dynamic no-dso no-hw \
247                        threads \
248                        --with-zlib-include=${DEPPKG_DIR}/include \
249                        mingw64
250            ./Configure --prefix=${DEPPKG_DIR} \
251                        shared zlib-dynamic no-dso no-hw \
252                        threads \
253                        --with-zlib-include=${DEPPKG_DIR}/include \
254                        mingw64 > make.log 2>&1
255    fi
256    echo Building openssl
257    perl util/mkdef.pl 32 libeay no-static-engine >ms/libeay32.def
258    perl util/mkdef.pl 32 ssleay >ms/ssleay32.def
259    perl util/mkdef.pl crypto ssl NT update
260    sed -i 's/CC=/CC=mingw32-gcc #/' crypto/comp/Makefile
261    sed -i 's/AR=/AR=mingw32-ar r #/'  crypto/comp/Makefile
262    sed -i "s:^CFLAGS=:CFLAGS= -I${DEPPKG_DIR}/include:" crypto/comp/Makefile
263
264    do_make Makefile all
265    cd engines
266    touch lib4758cca.bad libaep.bad libatalla.bad libcswift.bad libchil.bad libgmp.bad libnuron.bad libsureware.bad libubsec.bad libcapi.bad
267    cd ..
268    do_make Makefile all
269    echo Installing openssl
270    do_make Makefile install_sw install
271    cp *.dll ${DEPPKG_DIR}/bin
272 }
273
274 if [ "$#" -eq 0 ]
275 then
276    process_zlib
277    process_pcre
278    process_pthreads
279    process_openssl
280 else
281    for dependency in "$@"
282    do
283       eval "process_${dependency}"
284    done
285 fi
286 #vss
287 #Need to download from Microsoft