]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/build-depkgs-mingw-w64
Drop AFS detection.
[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_rsync()
168 {
169    get_source "${URL_RSYNC}" "${DIR_RSYNC}" "${MKD_RSYNC}"
170    ./configure --host=x86_64-pc-mingw32
171    make -k # rdiff.exe has a problem
172    cp .libs/librsync.a ${DEPPKG_DIR}/lib
173    cp librsync*h ${DEPPKG_DIR}/include
174 }
175
176 process_zlib()
177 {
178    if get_source "${URL_ZLIB}" "${DIR_ZLIB}" "${MKD_ZLIB}"
179    then
180       echo "Patching zlib"
181       >patch.log
182       do_patch zlib.patch
183    fi
184    echo Building zlib
185    > make.log
186    do_make win32/Makefile.mingw32 PREFIX=${DEPPKG_DIR} all
187    echo Installing zlib
188    do_make win32/Makefile.mingw32 PREFIX=${DEPPKG_DIR} install
189 }
190
191 process_pcre()
192 {
193    if get_source "${URL_PCRE}" "${DIR_PCRE}" "${MKD_PCRE}"
194    then
195            echo Patching PCRE
196            >patch.log
197            do_patch pcre.patch
198            echo Configuring PCRE
199            ./configure CC_FOR_BUILD=gcc \
200                        CXX_FOR_BUILD=g++ \
201                        --host=x86_64-pc-mingw32 \
202                        --prefix=${DEPPKG_DIR} \
203                        --enable-utf8 \
204                        --enable-unicode-properties >make.log 2>&1
205    fi
206    echo Building PCRE
207    do_make Makefile PREFIX=${DEPPKG_DIR} all
208    echo Installing PCRE
209    do_make Makefile PREFIX=${DEPPKG_DIR} install
210 }
211
212 process_db()
213 {
214    if get_source "${URL_DB}" "${DIR_DB}" "${MKD_DB}"
215    then
216           echo No Patch
217    fi
218    cd build_unix
219    ../dist/configure --host=x86_64-pc-mingw32 --enable-mingw --prefix=${DEPPKG_DIR}
220    > make.log
221    echo Building DB
222    do_make Makefile
223    echo Installing DB
224    do_make Makefile install_setup install_include install_lib
225 }
226
227 process_pthreads()
228 {
229    if get_source "${URL_PTHREADS}" "${DIR_PTHREADS}" "${MKD_PTHREADS}"
230    then
231            echo Patching pthreads
232            >patch.log
233            do_patch pthreads-w64.patch
234    fi
235    echo Building pthreads
236    > make.log
237    do_make GNUmakefile GCE
238    echo Installing pthreads
239    rm -rf ${DEPPKG_DIR}/include/pthreads
240    mkdir ${DEPPKG_DIR}/include/pthreads
241    cp -p *.h ${DEPPKG_DIR}/include/pthreads
242    cp -p *.dll ${DEPPKG_DIR}/bin
243    cp -p *.a ${DEPPKG_DIR}/lib
244 }
245
246 process_openssl()
247 {
248    if get_source "${URL_OPENSSL}" "${DIR_OPENSSL}" "${MKD_OPENSSL}"
249    then
250            echo Patching openssl
251            >patch.log
252            do_patch openssl-w64.patch
253            echo Configuring openssl
254            echo ./Configure --prefix=${DEPPKG_DIR} \
255                        shared zlib-dynamic no-dso no-hw \
256                        threads \
257                        --with-zlib-include=${DEPPKG_DIR}/include \
258                        mingw64
259            ./Configure --prefix=${DEPPKG_DIR} \
260                        shared zlib-dynamic no-dso no-hw \
261                        threads \
262                        --with-zlib-include=${DEPPKG_DIR}/include \
263                        mingw64 > make.log 2>&1
264    fi
265    echo Building openssl
266    perl util/mkdef.pl 32 libeay no-static-engine >ms/libeay32.def
267    perl util/mkdef.pl 32 ssleay >ms/ssleay32.def
268    perl util/mkdef.pl crypto ssl NT update
269    sed -i 's/CC=/CC=mingw32-gcc #/' crypto/comp/Makefile
270    sed -i 's/AR=/AR=mingw32-ar r #/'  crypto/comp/Makefile
271    sed -i "s:^CFLAGS=:CFLAGS= -I${DEPPKG_DIR}/include:" crypto/comp/Makefile
272
273    do_make Makefile all
274    cd engines
275    touch lib4758cca.bad libaep.bad libatalla.bad libcswift.bad libchil.bad libgmp.bad libnuron.bad libsureware.bad libubsec.bad libcapi.bad
276    cd ..
277    do_make Makefile all
278    echo Installing openssl
279    do_make Makefile install_sw install
280    cp *.dll ${DEPPKG_DIR}/bin
281 }
282
283 if [ "$#" -eq 0 ]
284 then
285    process_zlib
286    process_rsync
287    process_pcre
288    process_pthreads
289    process_openssl
290 else
291    for dependency in "$@"
292    do
293       eval "process_${dependency}"
294    done
295 fi
296 #vss
297 #Need to download from Microsoft