]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/build-depkgs-mingw32
Update
[bacula/bacula] / bacula / src / win32 / build-depkgs-mingw32
1 #!/bin/sh
2
3 usage()
4 {
5         echo "usage: $0 [-h] [-C] [<dependency 1>] [<dependency 2>] ..."
6         echo "       -h      Displays this usage"
7         echo "       -C      Clobbers (overwrites) the source code by "
8         echo "               reextracting the archive and reapplying the"
9         echo "               patches."
10         echo ""
11         echo "<dependency N> Optional dependency, If none are given then all"
12         echo "               of them will be built."
13         echo ""
14         echo "Valid dependencies are:"
15         grep -v '^#' < External-mingw32 | cut -d'|' -f1 | cut -d'_' -f1 | tr A-Z a-z | sort -u | awk '{ print "        " $1 }'
16 }
17
18 CLOBBER_SOURCE=
19
20 while getopts "hHC" opt; do
21         case ${opt} in
22         H|h|\?) usage;exit 1;;
23         C)      CLOBBER_SOURCE=true;;
24         esac
25 done
26
27 [ ${OPTIND} -gt 1 ] && shift `expr ${OPTIND} - 1`
28
29 cwd=`pwd`
30 cd `dirname $0`
31 SCRIPT_DIR=`pwd`
32
33 cd ../../..
34 TOP_DIR=`pwd`
35
36 if [ -e ${TOP_DIR}/cross-tools/mingw32/bin/mingw32-gcc ]
37 then
38         cd ${TOP_DIR}/cross-tools/mingw32/bin
39         BIN_DIR=`pwd`
40 elif [ -e /mingw/bin/mingw32-gcc ] 
41 then
42         BIN_DIR=/mingw/bin
43 else
44         echo The GCC cross compiler isn\'t installed.
45         echo You must run build-win32-cross-tools first
46         exit 1
47 fi
48
49 [ ! -e ${TOP_DIR}/depkgs-mingw32 ] && mkdir ${TOP_DIR}/depkgs-mingw32
50 cd ${TOP_DIR}/depkgs-mingw32
51 DEPPKG_DIR=`pwd`
52
53 export PATH=${BIN_DIR}:${PATH}
54
55 [ ! -e bin ] && mkdir bin
56 [ ! -e src ] && mkdir src
57 [ ! -e include ] && mkdir include
58 [ ! -e lib ] && mkdir lib
59
60 OLD_IFS=${IFS};IFS="|";
61 while read package url dir mkd; do
62         case ${package} in
63         \#*) ;;
64         *) eval "URL_${package}=${url};DIR_${package}=${dir};MKD_${package}=${mkd}";;
65         esac
66 done < ${SCRIPT_DIR}/External-mingw32
67 IFS=${OLD_IFS};unset OLD_IFS
68
69 get_source()
70 {
71         URL=$1
72         SRC_DIR=$2
73         MAKE_DIR=$3
74         ARCHIVE=`basename ${URL}`
75         
76         case ${ARCHIVE} in
77         *.tar.gz)       ARCHIVER="tar xzf"; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.gz'`;;
78         *.tar.bz2)      ARCHIVER="tar xjf"; [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.tar\.bz2'`;;
79         *.zip)          ARCHIVER="unzip -q";   [ -z "${SRC_DIR}" ] && SRC_DIR=`expr "${ARCHIVE}" : '\(.*\)\.zip'`;;
80         *)              echo Unsupported archive type - $ARCHIVE; exit 1;;
81         esac
82         
83         cd ${DEPPKG_DIR}/src
84         
85         if [ ! -e "${ARCHIVE}" ]
86         then 
87                 echo Downloading "${URL}"
88                 if wget --passive-ftp "${URL}"
89                 then
90                         :
91                 else
92                         echo Unable to download ${ARCHIVE}
93                         exit 1
94                 fi
95         fi
96
97         if [ ! -e "${SRC_DIR}" -o "${CLOBBER_SOURCE}" = "true" ]
98         then
99                 rm -rf ${SRC_DIR}
100                 [ "${MAKE_DIR}" = "true" ] && mkdir ${SRC_DIR} && cd ${SRC_DIR}
101                 echo Extracting ${ARCHIVE}
102                 ${ARCHIVER} ${ARCHIVE} &> ${ARCHIVE}.log
103                 cd ${SRC_DIR}
104                 return 0
105         fi
106
107         cd ${SRC_DIR}
108         return 1
109 }
110
111 parse_output()
112 {
113         sed -ne '/\\$/N' -e 's/\\\n//' -e 's/\t\+/ /g' -e 's/ \+/ /g' \
114             -e '/ error: /p' \
115             -e "s%.*Entering directory[ ]\\+.${DEPPKG_DIR}/\\([^ ]\+\).%Entering \\1%p" \
116             -e "s%.*Leaving directory[ ]\\+.${DEPPKG_DIR}/\\([^ ]\+.\).%Leaving \\1%p" \
117             -e '/gcc \|g\+\+ \|ar /!d' \
118             -e 's/ \(\.\.\/\)\+/ /g' \
119             -e 's/.* \([^ ]\+\(\.c\|\.cpp\|\.cc\|\.cxx\)\)\( .*\|\)$/Compiling \1/p' \
120             -e 's/.* \([^ ]\+\.s\)\( .*\|\)$/Assembling \1/p' \
121             -e 's/.*ar [^ ]\+ \([^ ]\+\)\(\( [^ ]\+\.o\)\+\)/Updating \1 -\2/p' \
122             -e 's/.* -o \([^ ]\+\)\( .*\|\)$/Linking \1/p'
123 }
124
125 do_patch()
126 {
127         PATCH_FILE=${SCRIPT_DIR}/patches/$1; shift
128         
129         if patch -f -p0 "$@" >>patch.log < ${PATCH_FILE}
130         then
131                 :
132         else
133                 echo Patch failed - Check `pwd`/patch.log > /dev/tty
134                 exit 1
135         fi
136 }
137
138 do_make()
139 {
140         if make -f "$@" 2>&1
141         then
142                 :
143         else
144                 echo Make failed - Check `pwd`/make.log > /dev/tty
145                 exit 1
146         fi | tee -a make.log | parse_output
147 }
148
149 process_zlib()
150 {
151         if get_source "${URL_ZLIB}" "${DIR_ZLIB}" "${MKD_ZLIB}"
152         then
153                 echo Patching zlib
154                 >patch.log
155                 do_patch zlib.patch
156         fi
157         echo Building zlib
158         > make.log
159         do_make win32/Makefile.mingw32 PREFIX=${DEPPKG_DIR} all
160         echo Installing zlib
161         do_make win32/Makefile.mingw32 PREFIX=${DEPPKG_DIR} install
162 }
163
164 process_pcre()
165 {
166         if get_source "${URL_PCRE}" "${DIR_PCRE}" "${MKD_PCRE}"
167         then
168                 echo Patching PCRE
169                 >patch.log
170                 do_patch pcre.patch
171                 echo Configuring PCRE
172                 ./configure CC_FOR_BUILD=gcc \
173                             CXX_FOR_BUILD=g++ \
174                             --host=mingw32 \
175                             --prefix=${DEPPKG_DIR} \
176                             --enable-utf8 \
177                             --enable-unicode-properties &>make.log
178         fi
179         echo Building PCRE
180         do_make Makefile PREFIX=${DEPPKG_DIR} all
181         echo Installing PCRE
182         do_make Makefile PREFIX=${DEPPKG_DIR} install
183 }
184
185 process_pthreads()
186 {
187         if get_source "${URL_PTHREADS}" "${DIR_PTHREADS}" "${MKD_PTHREADS}"
188         then
189                 echo Patching pthreads
190                 >patch.log
191                 do_patch pthreads.patch
192         fi
193         echo Building pthreads
194         > make.log
195         do_make GNUmakefile GCE
196         echo Installing pthreads
197         rm -rf ${DEPPKG_DIR}/include/pthreads
198         mkdir ${DEPPKG_DIR}/include/pthreads
199         cp -p *.h ${DEPPKG_DIR}/include/pthreads
200         cp -p *.dll ${DEPPKG_DIR}/bin
201         cp -p *.a ${DEPPKG_DIR}/lib
202 }
203
204 process_openssl()
205 {
206         if get_source "${URL_OPENSSL}" "${DIR_OPENSSL}" "${MKD_OPENSSL}"
207         then
208                 echo Patching openssl
209                 >patch.log
210                 do_patch openssl.patch
211                 echo Configuring openssl
212                 ./Configure --prefix=${DEPPKG_DIR} \
213                             shared zlib-dynamic \
214                             threads \
215                             --with-zlib-include=${DEPPKG_DIR}/include \
216                             mingw32 &> make.log
217         fi
218         echo Building openssl
219         perl util/mkdef.pl 32 libeay no-static-engine >ms/libeay32.def
220         perl util/mkdef.pl 32 ssleay >ms/ssleay32.def
221         do_make Makefile all
222         echo Installing openssl
223         do_make Makefile install_sw
224 }
225
226 process_mysql()
227 {
228         get_source "${URL_MYSQL}" "${DIR_MYSQL}" "${DIR_MYSQL}" "${MKD_MYSQL}"
229         echo Converting mysql lib file
230         if [ -e ${BIN_DIR}/reimp ]
231         then
232                 reimp --dlltool ${BIN_DIR}/mingw32-dlltool --as ${BIN_DIR}/mingw32-as lib/opt/libmysql.lib
233         else
234                 ${BIN_DIR}/../mingw32/bin/reimp --dlltool ${BIN_DIR}/mingw32-dlltool --as ${BIN_DIR}/mingw32-as lib/opt/libmysql.lib
235         fi
236         echo Installing mysql
237         cp -p liblibmysql.a ../../lib/libmysql.a
238         rm -rf ../../include/mysql
239         mkdir ../../include/mysql
240         cp -p include/* ../../include/mysql 2>&1 | grep -v 'omitting directory'
241         cp -p lib/opt/libmysql.dll ../../bin
242 }
243
244 process_postgresql()
245 {
246         if get_source "${URL_POSTGRESQL}" "${DIR_POSTGRESQL}" "${MKD_POSTGRESQL}"
247         then
248                 echo Patching postgreSQL
249                 >patch.log
250                 do_patch postgresql.patch
251                 echo Configuring postgreSQL
252                 ./configure --host=mingw32 \
253                             --enable-shared \
254                             --enable-thread-safety \
255                             --prefix=${DEPPKG_DIR} \
256                             --with-includes=${DEPPKG_DIR}/include:${DEPPKG_DIR}/include/pthreads \
257                             --with-libraries=${DEPPKG_DIR}/lib &> make.log
258         fi
259         echo Building postgreSQL
260         if [ -e /usr/sbin/zic ]; then ZIC=/usr/sbin/zic
261         elif [ -e /sbin/zic ]; then ZIC=/sbin/zic
262         elif [ -e /usr/bin/zic ]; then ZIC=/usr/bin/zic
263         elif [ -e /bin/zic ]; then ZIC=/bin/zic
264         else ZIC=./zic
265         fi
266         do_make Makefile AR=mingw32-ar DLLTOOL=mingw32-dlltool DLLWRAP=mingw32-dllwrap WINDRES=mingw32-windres PTHREAD_LIBS=-lpthreadGCE ZIC=${ZIC}
267         echo Installing postgreSQL
268         do_make Makefile AR=mingw32-ar DLLTOOL=mingw32-dlltool DLLWRAP=mingw32-dllwrap WINDRES=mingw32-windres PTHREAD_LIBS=-lpthreadGCE ZIC=${ZIC} install
269 }
270
271 process_sqlite()
272 {
273         if get_source "${URL_SQLITE}" "${DIR_SQLITE}" "${MKD_SQLITE}"
274         then
275                 echo Patching SQLite
276                 >patch.log
277                 do_patch sqlite.patch
278         fi
279         echo Building SQLite
280         [ ! -e bld ] && mkdir bld
281         cd bld
282         > make.log
283         do_make ../Makefile.mingw32 CROSSTOOLS=${BIN_DIR} TLIBS="-L${DEPPKG_DIR}/lib" TCL_FLAGS="-I${DEPPKG_DIR}/include"
284         echo Installing SQLite
285         cp -p sqlite3.exe ${DEPPKG_DIR}/bin
286         cp -p libsqlite3.a ${DEPPKG_DIR}/lib
287         cp -p sqlite3.h ${DEPPKG_DIR}/include
288 }
289
290 process_wx()
291 {
292         if get_source "${URL_WX}" "${DIR_WX}" "${MKD_WX}"
293         then
294                 echo Patching wxWidgets
295                 >patch.log
296                 do_patch wx1.patch -o build/msw/config.mingw32
297                 do_patch wx2.patch
298                 find . -name makefile.gcc -exec sh -c "sed -f ${SCRIPT_DIR}/patches/wx.sed {} > \`echo {} | sed -e 's/\.gcc$/\.mingw32/'\`" \;
299         fi
300         echo Building wxWidgets
301         cd build/msw
302         > make.log
303         do_make makefile.mingw32 SHARED=1 VENDOR=bacula DEBUG_INFO=1
304         echo Installing wxWidgets
305         cd ../..
306         rm -rf ../../include/wx
307         mkdir ../../include/wx
308         cp -p include/wx/* ../../include/wx 2>&1 | grep -v 'omitting directory'
309         mkdir ../../include/wx/generic
310         cp -p include/wx/generic/* ../../include/wx/generic 2>&1 | grep -v 'omitting directory'
311         mkdir ../../include/wx/msw
312         cp -p include/wx/msw/* ../../include/wx/msw 2>&1 | grep -v 'omitting directory'
313         cp -p lib/gcc_dll/*.dll ../../bin
314         rm -rf ../../lib/wx_dll
315         mkdir ../../lib/wx_dll
316         cp -p lib/gcc_dll/*.a ../../lib/wx_dll
317         mkdir ../../lib/wx_dll/msw
318         cp -p lib/gcc_dll/msw/* ../../lib/wx_dll/msw 2>&1 | grep -v 'omitting directory'
319         mkdir ../../lib/wx_dll/msw/wx
320         cp -p lib/gcc_dll/msw/wx/* ../../lib/wx_dll/msw/wx 2>&1 | grep -v 'omitting directory'
321         mkdir ../../lib/wx_dll/msw/wx/msw
322         cp -p lib/gcc_dll/msw/wx/msw/* ../../lib/wx_dll/msw/wx/msw 2>&1 | grep -v 'omitting directory'
323 }
324
325 process_scons()
326 {
327         get_source "${URL_SCONS}" "${DIR_SCONS}" "${MKD_SCONS}"
328         echo Installing scons
329         if python setup.py install --prefix=${DEPPKG_DIR}/scons &> make.log
330         then
331                 :
332         else
333                 echo Make failed - Check `pwd`/make.log
334                 exit 1
335         fi
336 }
337
338 process_nsis()
339 {
340         get_source "${URL_NSIS_BIN}" "${DIR_NSIS_BIN}" "${MKD_NSIS_BIN}"
341         cd ..
342         rm -rf ../nsis
343         mv nsis-2.17 ../nsis
344         if get_source "${URL_NSIS_SRC}" "${DIR_NSIS_SRC}" "${MKD_NSIS_SRC}"
345         then
346                 echo Patching nsis
347                 >patch.log
348                 do_patch nsis.patch
349         fi
350         echo Building nsis
351         if ../../scons/bin/scons SKIPSTUBS=all SKIPPLUGINS=all SKIPUTILS=all SKIPMISC=all \
352                 PREFIX=${DEPPKG_DIR}/nsis PREFIX_BIN=${DEPPKG_DIR}/nsis/Bin \
353                 PREFIX_CONF=${DEPPKG_DIR}/nsis PREFIX_DATA=${DEPPKG_DIR}/nsis \
354                 PREFIX_DOC=${DEPPKG_DIR}/nsis/Docs 2>&1 | tee make.log | parse_output
355         then
356                 :
357         else
358                 echo Scons failed - Check `pwd`/make.log
359                 exit 1
360         fi
361         echo Installing nsis
362         cp -p build/release/makensis/makensis ../../nsis
363 }
364
365 process_mtx()
366 {
367         if get_source "${URL_MTX}" "${DIR_MTX}" "${MKD_MTX}"
368         then
369                 echo Patching mtx
370                 # We can't run configure in a cross-compile environment so we
371                 # patch the files to the correct values
372                 cp -f config.h.in config.h
373                 cp -f Makefile.in Makefile
374                 rm -f configure
375                 >patch.log
376                 do_patch mtx.patch
377         fi
378         echo Building mtx
379         do_make Makefile prefix=${DEPPKG_DIR} all
380         echo Installing mtx
381         do_make Makefile prefix=${DEPPKG_DIR} install
382 }
383
384 process_mt()
385 {
386         if get_source "${URL_MT}" "${DIR_MT}" "${MKD_MT}"
387         then
388                 echo Patching mt
389                 >patch.log
390                 do_patch mt.patch
391         fi
392         echo Building mt
393         do_make Makefile PREFIX=${DEPPKG_DIR} all
394         echo Installing mt
395         do_make Makefile PREFIX=${DEPPKG_DIR} install
396 }
397
398 if [ "$#" -eq 0 ]
399 then
400         process_zlib
401         process_pcre
402         process_pthreads
403         process_openssl
404         process_mysql
405         process_sqlite
406         process_postgresql
407         process_wx
408         process_scons
409         process_nsis
410         process_mtx
411         process_mt
412 else
413         for dependency in "$@"
414         do
415                 eval "process_${dependency}"
416         done
417
418 fi
419 #vss
420 #Need to download from Microsoft