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