]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/build-depkgs-mingw-w64
ebl Add script to build w64 dependencies
[bacula/bacula] / bacula / src / win32 / build-depkgs-mingw-w64
1 #!/bin/sh
2 #
3 #  This file is driven by the parameters that are defined in
4 #    the file External-mingw-w64
5 #
6
7 usage()
8 {
9    echo "usage: $0 [-h] [-C] [<dependency 1>] [<dependency 2>] ..."
10    echo "       -h      Displays this usage"
11    echo "       -C      Clobbers (overwrites) the source code by "
12    echo "               reextracting the archive and reapplying the"
13    echo "               patches."
14    echo ""
15    echo "<dependency N> Optional dependency, If none are given then all"
16    echo "               of them will be built."
17    echo ""
18    echo "Valid dependencies are:"
19    grep -v '^#' < External-mingw-w64 | cut -d'|' -f1 | cut -d'_' -f1 | tr A-Z a-z | sort -u | awk '{ print "        " $1 }'
20 }
21
22 CLOBBER_SOURCE=
23
24 while getopts "hHC" opt; do
25    case ${opt} in
26    H|h|\?) usage;exit 1;;
27    C)      CLOBBER_SOURCE=true;;
28    esac
29 done
30
31 [ ${OPTIND} -gt 1 ] && shift `expr ${OPTIND} - 1`
32
33 cwd=`pwd`
34 cd `dirname $0`
35 SCRIPT_DIR=`pwd`
36
37 cd ../../..
38 TOP_DIR=`pwd`
39
40 if [ -e ${TOP_DIR}/cross-tools/mingw-w64/bin/x86_64-pc-mingw32-gcc ]
41 then
42    cd ${TOP_DIR}/cross-tools/mingw-w64/bin
43    BIN_DIR=`pwd`
44 else
45    echo "The GCC cross compiler isn\'t installed."
46    echo "You must run build-win64-cross-tools first"
47    exit 1
48 fi
49
50 [ ! -e ${TOP_DIR}/depkgs-mingw-w64 ] && mkdir ${TOP_DIR}/depkgs-mingw-w64
51 cd ${TOP_DIR}/depkgs-mingw-w64
52 DEPPKG_DIR=`pwd`
53
54 export PATH=${BIN_DIR}:${PATH}
55
56 [ ! -e bin ] && mkdir bin
57 [ ! -e src ] && mkdir src
58 [ ! -e include ] && mkdir include
59 [ ! -e lib ] && mkdir lib
60
61 OLD_IFS=${IFS};IFS="|";
62 while read package url dir mkd; do
63    echo "Got package ${package}"
64    case ${package} in
65    \#*) ;;
66    *) eval "URL_${package}=${url};DIR_${package}=${dir};MKD_${package}=${mkd}";;
67         esac
68 done < ${SCRIPT_DIR}/External-mingw-w64
69 IFS=${OLD_IFS};unset OLD_IFS
70
71 get_source()
72 {
73    URL=$1
74    SRC_DIR=$2
75    MAKE_DIR=$3
76    echo "Processing ${URL}"
77    ARCHIVE=`basename ${URL}`
78    
79    case ${ARCHIVE} in
80    *.tar.gz)       ARCHIVER="tar xzf";    [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.gz'`;;
81    *.tar.bz2)      ARCHIVER="tar xjf";    [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.bz2'`;;
82    *.zip)          ARCHIVER="unzip -q";   [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.zip'`;;
83    *.exe)          ARCHIVER="";           [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.zip'`;;
84    *)              echo Unsupported archive type - $ARCHIVE; exit 1;;
85    esac
86    
87    cd ${DEPPKG_DIR}/src
88    
89    if [ ! -e "${ARCHIVE}" ]
90    then 
91       echo Downloading "${URL}"
92       if wget --passive-ftp "${URL}"
93       then
94          :
95       else
96          echo Unable to download ${ARCHIVE}
97          exit 1
98       fi
99    fi
100
101    [ -z "${ARCHIVER}" ] && return 0
102
103    if [ ! -e "${SRC_DIR}" -o "${CLOBBER_SOURCE}" = "true" ]
104    then
105       rm -rf ${SRC_DIR}
106       echo Extracting ${ARCHIVE}
107       if [ "${MAKE_DIR}" = "true" ]
108       then
109          mkdir ${SRC_DIR}
110          cd ${SRC_DIR}
111          ${ARCHIVER} ../${ARCHIVE} > ../${ARCHIVE}.log 2>&1
112       else
113          ${ARCHIVER} ${ARCHIVE} > ${ARCHIVE}.log 2>&1
114          cd ${SRC_DIR}
115       fi
116       return 0
117    fi
118
119    cd ${SRC_DIR}
120    return 1
121 }
122
123 parse_output()
124 {
125    sed -ne '/\\$/N' -e 's/\\\n//' -e 's/\t\+/ /g' -e 's/ \+/ /g' \
126        -e '/ error: /p' \
127        -e "s%.*Entering directory[ ]\\+.${DEPPKG_DIR}/\\([^ ]\+\).%Entering \\1%p" \
128        -e "s%.*Leaving directory[ ]\\+.${DEPPKG_DIR}/\\([^ ]\+.\).%Leaving \\1%p" \
129        -e '/gcc \|g\+\+ \|ar /!d' \
130        -e 's/ \(\.\.\/\)\+/ /g' \
131        -e 's/.* \([^ ]\+\(\.c\|\.cpp\|\.cc\|\.cxx\)\)\( .*\|\)$/Compiling \1/p' \
132        -e 's/.* \([^ ]\+\.s\)\( .*\|\)$/Assembling \1/p' \
133        -e 's/.*ar [^ ]\+ \([^ ]\+\)\(\( [^ ]\+\.o\)\+\)/Updating \1 -\2/p' \
134        -e 's/.* -o \([^ ]\+\)\( .*\|\)$/Linking \1/p'
135 }
136
137 do_patch()
138 {
139    PATCH_FILE=${SCRIPT_DIR}/patches/$1; shift
140    
141    if patch -f -p0 "$@" >>patch.log < ${PATCH_FILE}
142    then
143       :
144    else
145       echo "Patch failed - Check `pwd`/patch.log" > /dev/tty
146       exit 1
147    fi
148 }
149
150 do_make()
151 {
152    if make -f "$@" 2>&1
153    then
154       :
155    else
156       echo "Make failed - Check `pwd`/make.log" > /dev/tty
157       exit 1
158    fi | tee -a make.log | parse_output
159 }
160
161 process_zlib()
162 {
163    if get_source "${URL_ZLIB}" "${DIR_ZLIB}" "${MKD_ZLIB}"
164    then
165       echo "Patching zlib"
166       >patch.log
167       do_patch zlib.patch
168    fi
169    echo Building zlib
170    > make.log
171    do_make win32/Makefile.mingw32 PREFIX=${DEPPKG_DIR} all
172    echo Installing zlib
173    do_make win32/Makefile.mingw32 PREFIX=${DEPPKG_DIR} install
174 }
175
176 process_pcre()
177 {
178    if get_source "${URL_PCRE}" "${DIR_PCRE}" "${MKD_PCRE}"
179    then
180            echo Patching PCRE
181            >patch.log
182            do_patch pcre.patch
183            echo Configuring PCRE
184            ./configure CC_FOR_BUILD=gcc \
185                        CXX_FOR_BUILD=g++ \
186                        --host=x86_64-pc-mingw32 \
187                        --prefix=${DEPPKG_DIR} \
188                        --enable-utf8 \
189                        --enable-unicode-properties >make.log 2>&1
190    fi
191    echo Building PCRE
192    do_make Makefile PREFIX=${DEPPKG_DIR} all
193    echo Installing PCRE
194    do_make Makefile PREFIX=${DEPPKG_DIR} install
195 }
196
197 process_db()
198 {
199    if get_source "${URL_DB}" "${DIR_DB}" "${MKD_DB}"
200    then
201           echo No Patch
202    fi
203    cd build_unix
204    ../dist/configure --host=x86_64-pc-mingw32 --enable-mingw --prefix=${DEPPKG_DIR}
205    > make.log
206    echo Building DB
207    do_make Makefile
208    echo Installing DB
209    do_make Makefile install_setup install_include install_lib
210 }
211
212 process_pthreads()
213 {
214    if get_source "${URL_PTHREADS}" "${DIR_PTHREADS}" "${MKD_PTHREADS}"
215    then
216            echo Patching pthreads
217            >patch.log
218            do_patch pthreads-w64+bacula.patch
219    fi
220    echo Building pthreads
221    > make.log
222    do_make GNUmakefile GCE
223    echo Installing pthreads
224    rm -rf ${DEPPKG_DIR}/include/pthreads
225    mkdir ${DEPPKG_DIR}/include/pthreads
226    cp -p *.h ${DEPPKG_DIR}/include/pthreads
227    cp -p *.dll ${DEPPKG_DIR}/bin
228    cp -p *.a ${DEPPKG_DIR}/lib
229 }
230
231 process_openssl()
232 {
233    if get_source "${URL_OPENSSL}" "${DIR_OPENSSL}" "${MKD_OPENSSL}"
234    then
235            echo Patching openssl
236            >patch.log
237            do_patch openssl-w64.patch
238            echo Configuring openssl
239            ./Configure --prefix=${DEPPKG_DIR} \
240                        shared zlib-dynamic no-dso no-hw \
241                        threads \
242                        --with-zlib-include=${DEPPKG_DIR}/include \
243                        mingw64 > make.log 2>&1
244    fi
245    echo Building openssl
246    perl util/mkdef.pl 32 libeay no-static-engine >ms/libeay32.def
247    perl util/mkdef.pl 32 ssleay >ms/ssleay32.def
248    perl util/mkdef.pl crypto ssl NT update
249    CFLAG=-I${DEPPKG_DIR}/include do_make Makefile all
250    echo Installing openssl
251    do_make Makefile install_sw
252 }
253
254 if [ "$#" -eq 0 ]
255 then
256 #   process_zlib
257 #   process_pcre
258 #   process_pthreads
259    process_openssl
260 else
261    for dependency in "$@"
262    do
263       eval "process_${dependency}"
264    done
265 fi
266 #vss
267 #Need to download from Microsoft