]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/build-win32-cross-tools
Add skeleton of system state plugin
[bacula/bacula] / bacula / src / win32 / build-win32-cross-tools
1 #!/bin/sh
2
3 # This is my script for building a complete MinGW cross-compiler toolchain
4 # that runs under Linux to produce executables that run under Windows.  It
5 # probably works (or can easily be adapted to work) under any unix system.
6 #
7 # It is based in large part on Sam Lantinga's script, which in turn was
8 # based partly on Ray Kelm's script, which in turn was built on
9 # Mo Dejong's script for doing the same, but with some added fixes.
10 #
11 # My changes:
12 #       1. Adapted the script to the new packaging of MinGW GCC, which is
13 #          currently split into core and auxiliary components.
14 #       2. The script now determines the GCC and BINUTILS directory name
15 #          directly from the tar file contents.  This gets around common
16 #          problems due to the directory names not always following the
17 #          expected patterns.
18 #       3. Grouped together and simplified the macros that users need to
19 #          define.
20 #       4. Made optional components truly optional -- leave the
21 #          corresponding archive names blank and they will be ignored.
22 #       5. Included an option to purge the installation directory before
23 #          installing the current cross-compiler.
24 #
25 # NOTE: If you choose a destination directory for the installation (set
26 # in the macro PREFIX) for which you do not have write access, you will
27 # need to run this script with root (or equivalent) privileges.
28 #
29 #
30 # Updated by Igor Mikolic-Torreira <igormt@alumni.caltech.edu>
31
32
33
34 #-----------------------------------------------------
35 #
36 # BEGIN USER SETTINGS
37 #
38 # You need to review and adjust the macros that follow
39 #
40 #-----------------------------------------------------
41
42
43 # Directory where cross-tools directory will be placed
44 TOPDIR=../../..
45 # Cross tools directory name under TOPDIR
46 CROSSTOOLS=cross-tools
47 # What flavor of GCC cross-compiler are we building? under CROSSTOOLS
48 TARGET=mingw32
49
50 cwd=`pwd`
51
52 cd ${TOPDIR}
53 # Make TOPDIR absolute 
54 TOPDIR=`pwd`
55 TOPDIR=${DEPKGS:-${TOPDIR}}
56
57 cd ${cwd}/`dirname $0`
58 SCRIPTDIR=`pwd`
59
60 cd ${cwd}
61
62 BUILDDIR=${TOPDIR}/${CROSSTOOLS}
63
64 # Where does the cross-compiler go?
65 # This should be the directory into which your cross-compiler
66 # will be installed.  Remember that if you set this to a directory
67 # that only root has write access to, you will need to run this
68 # script as root.
69
70 PREFIX=${BUILDDIR}/${TARGET}
71 mkdir -p ${BUILDDIR}
72 mkdir -p ${BUILDDIR}/${TARGET}
73
74 echo "Building cross tools in ${BUILDDIR} ..."
75 echo " "
76
77 # Purge anything and everything already in the $PREFIX
78 #(also known as the destination or installation) directory?
79 # Set to "Y" to purge, any other value omits the purge step.
80
81 PURGE_DIR="Y"
82
83
84 # Set the following to the files from the current MinGW release
85 # (or whichever MinGW release you wish to build and install)
86 # You need to set both the URL they will be downloaded from
87 # and the exact name of the individual component files.
88
89 #MINGW_URL="http://superb-west.dl.sourceforge.net/sourceforge/mingw"
90 MINGW_URL="http://www.bacula.org/cross-tools"
91
92 # GCC_CORE is required; the other components are optional.
93 # Set any you don't want to "".  You need binutils,
94 # mingw runtime and w32api; do not ever set those to "".
95
96 GCC_CORE_ARCHIVE="gcc-core-3.4.5-20060117-1-src.tar.gz"
97 GCC_GPP_ARCHIVE="gcc-g++-3.4.5-20060117-1-src.tar.gz"
98 GCC_G77_ARCHIVE=""
99 GCC_OBJC_ARCHIVE=""
100 GCC_JAVA_ARCHIVE=""
101 GCC_ADA_ARCHIVE=""
102 GCC_PATCH=""
103
104 # GCC_G77_ARCHIVE="gcc-g77-3.4.2-20040916-1-src.tar.gz"
105 # GCC_OBJC_ARCHIVE="gcc-objc-3.4.2-20040916-1-src.tar.gz"
106 # GCC_JAVA_ARCHIVE="gcc-java-3.4.2-20040916-1-src.tar.gz"
107
108 BINUTILS_ARCHIVE="binutils-2.16.91-20060119-1-src.tar.gz"
109 BINUTILS_PATCH="binutils_texinfo_version.patch"
110
111 MINGW_ARCHIVE="mingw-runtime-3.9.tar.gz"
112
113 W32API_ARCHIVE="w32api-3.7.tar.gz"
114
115 MINGW_UTILS_ARCHIVE="mingw-utils-0.3-src.tar.gz"
116
117 # These are the files from the SDL website
118 # These are optional, set them to "" if you don't want them)
119
120 #SDL_URL="http://www.libsdl.org/extras/win32/common"
121 SDL_URL="http://www.bacula.org/cross-tools"
122
123 OPENGL_ARCHIVE="opengl-devel.tar.gz"
124 DIRECTX_ARCHIVE="directx-devel.tar.gz"
125
126
127
128 #-----------------------------------------------------
129 #
130 # END USER SETTINGS
131 #
132 # The remainder of the script should not neet any edits
133 #
134 #-----------------------------------------------------
135
136
137
138 # Make sure these are initialized as we want them
139
140 GCC_CORE=""
141 BINUTILS=""
142 GCC_LANGS="c"
143
144
145 # Set our build directory and where our sources will go
146
147 if [ "x$BUILDDIR" = "x" ]; then
148         # Default to the current directory
149         BUILDDIR=$(pwd)
150 fi
151 SRCDIR="$BUILDDIR/source"
152
153
154 # Need install directory first on the path so gcc can find binutils
155
156 PATH="$PREFIX/bin:$PATH"
157
158
159
160 #-----------------------------------------------------
161 #
162 # Functions that do most of the work
163 #
164 #-----------------------------------------------------
165
166
167 download_files()
168 {
169         # Download a file from a given url, only if it is not present
170         mkdir -p "$SRCDIR"
171
172         # Make sure wget is installed
173         if test "x`which wget`" = "x" ; then
174                 echo "You need to install wget."
175                 exit 1
176         fi
177         download_file "$GCC_CORE_ARCHIVE" "$MINGW_URL"
178         if [ "x$GCC_GPP_ARCHIVE" != "x" ]; then
179                 download_file "$GCC_GPP_ARCHIVE" "$MINGW_URL"
180         fi
181         if [ "x$GCC_G77_ARCHIVE" != "x" ]; then
182                 download_file "$GCC_G77_ARCHIVE" "$MINGW_URL"
183         fi
184         if [ "x$GCC_OBJC_ARCHIVE" != "x" ]; then
185                 download_file "$GCC_OBJC_ARCHIVE" "$MINGW_URL"
186         fi
187         if [ "x$GCC_JAVA_ARCHIVE" != "x" ]; then
188                 download_file "$GCC_JAVA_ARCHIVE" "$MINGW_URL"
189         fi
190         if [ "x$GCC_ADA_ARCHIVE" != "x" ]; then
191                 download_file "$GCC_ADA_ARCHIVE" "$MINGW_URL"
192         fi
193
194         download_file "$BINUTILS_ARCHIVE" "$MINGW_URL"
195         download_file "$MINGW_ARCHIVE" "$MINGW_URL"
196         download_file "$W32API_ARCHIVE" "$MINGW_URL"
197
198         if [ "x$MINGW_UTILS_ARCHIVE" != "x" ]; then
199                 download_file "$MINGW_UTILS_ARCHIVE" "$MINGW_URL"
200         fi
201
202         if [ "x$OPENGL_ARCHIVE" != "x" ]; then
203                 download_file "$OPENGL_ARCHIVE" "$SDL_URL"
204         fi
205         if [ "x$DIRECTX_ARCHIVE" != "x" ]; then
206                 download_file "$DIRECTX_ARCHIVE" "$SDL_URL"
207         fi
208 }
209
210
211 download_file()
212 {
213         cd "$SRCDIR"
214         if test ! -f $1 ; then
215                 echo "Downloading $1"
216                 wget "$2/$1"
217                 if test ! -f $1 ; then
218                         echo "Could not download $1"
219                         exit 1
220                 fi
221         else
222                 echo "Found $1 in the srcdir $SRCDIR"
223         fi
224         cd "$BUILDDIR"
225 }
226
227
228 purge_existing_install()
229 {
230         echo "Purging the existing files in $PREFIX"
231         if cd "$PREFIX"; then
232                 rm -rf *
233         fi
234         cd "$BUILDDIR"
235 }
236
237
238 install_libs()
239 {
240         echo "Installing cross libs and includes"
241         mkdir -p "$PREFIX/$TARGET"
242         cd "$PREFIX/$TARGET"
243
244         tar -xzf "$SRCDIR/$MINGW_ARCHIVE"
245         tar -xzf "$SRCDIR/$W32API_ARCHIVE"
246
247         if [ "x$OPENGL_ARCHIVE" != "x" ]; then
248                 tar -xzf "$SRCDIR/$OPENGL_ARCHIVE"
249         fi
250
251         if [ "x$DIRECTX_ARCHIVE" != "x" ]; then
252                 tar -xzf "$SRCDIR/$DIRECTX_ARCHIVE"
253         fi
254
255         cd "$BUILDDIR"
256 }
257
258
259 extract_binutils()
260 {
261         cd "$SRCDIR"
262         BINUTILS=`tar -tzf "$SRCDIR/$BINUTILS_ARCHIVE" | head -n 1`
263         if [ "x${BINUTILS}" != "x./" ]; then
264            rm -rf "$BINUTILS"
265         fi
266         echo "Extracting binutils"
267         tar -xzf "$SRCDIR/$BINUTILS_ARCHIVE"
268         cd "$BUILDDIR"
269 }
270
271 patch_binutils()
272 {
273         if [ "$BINUTILS_PATCH" != "" ]; then
274                 echo "Patching binutils"
275                 cd "$SRCDIR/$BINUTILS"
276                 patch -p1 < "${cwd}/patches/$BINUTILS_PATCH"
277                 cd "$BUILDDIR"
278         fi
279 }
280
281
282 configure_binutils()
283 {
284         cd "$BUILDDIR"
285         rm -rf "binutils-$TARGET"
286         mkdir "binutils-$TARGET"
287         cd "binutils-$TARGET"
288         echo "Configuring binutils"
289         "$SRCDIR/$BINUTILS/configure" --prefix="$PREFIX" --target=$TARGET --disable-nls \
290                 --with-gcc --with-gnu-as --with-gnu-ld --disable-shared 2>&1 > configure.log
291         cd "$BUILDDIR"
292 }
293
294
295 build_binutils()
296 {
297         cd "$BUILDDIR/binutils-$TARGET"
298         echo "Building binutils"
299         make CFLAGS="-O2 -fno-exceptions" LDFLAGS="-s" 2>&1 > make.log
300         if test $? -ne 0; then
301                 echo "make of binutils failed - log available: binutils-$TARGET/make.log"
302                 exit 1
303         fi
304         cd "$BUILDDIR"
305 }
306
307
308 install_binutils()
309 {
310         cd "$BUILDDIR/binutils-$TARGET"
311         echo "Installing binutils"
312         make install 2>&1 > make-install.log
313         if test $? -ne 0; then
314                 echo "install of binutils failed - log available: binutils-$TARGET/make-install.log"
315                 exit 1
316         fi
317         cd "$BUILDDIR"
318 }
319
320
321 extract_gcc()
322 {
323         cd "$SRCDIR"
324         GCC=`tar -tzf "$SRCDIR/$GCC_CORE_ARCHIVE" | head -n 1`
325 #       rm -rf "$GCC"
326         echo "====== GCC ${GCC} ========="
327         echo "Extracting gcc"
328         tar -xzf "$SRCDIR/$GCC_CORE_ARCHIVE"
329         if [ "x$GCC_GPP_ARCHIVE" != "x" ]; then
330                 GCC_LANGS=${GCC_LANGS}",c++"
331                 tar -xzf "$SRCDIR/$GCC_GPP_ARCHIVE"
332         fi
333         if [ "x$GCC_G77_ARCHIVE" != "x" ]; then
334                 GCC_LANGS=${GCC_LANGS}",f77"
335                 tar -xzf "$SRCDIR/$GCC_G77_ARCHIVE"
336         fi
337         if [ "x$GCC_OBJC_ARCHIVE" != "x" ]; then
338                 GCC_LANGS=${GCC_LANGS}",objc"
339                 tar -xzf "$SRCDIR/$GCC_OBJC_ARCHIVE"
340         fi
341         if [ "x$GCC_JAVA_ARCHIVE" != "x" ]; then
342                 GCC_LANGS=${GCC_LANGS}",java"
343                 tar -xzf "$SRCDIR/$GCC_JAVA_ARCHIVE"
344         fi
345         if [ "x$GCC_ADA_ARCHIVE" != "x" ]; then
346                 GCC_LANGS=${GCC_LANGS}",ada"
347                 tar -xzf "$SRCDIR/$GCC_ADA_ARCHIVE"
348         fi
349         cd "$BUILDDIR"
350 }
351
352
353 patch_gcc()
354 {
355         if [ "$GCC_PATCH" != "" ]; then
356                 echo "Patching gcc"
357                 cd "$SRCDIR/$GCC"
358                 patch -p1 < "$SRCDIR/$GCC_PATCH"
359                 cd "$BUILDDIR"
360         fi
361 }
362
363
364 configure_gcc()
365 {
366         cd "$BUILDDIR"
367         rm -rf "gcc-$TARGET"
368         mkdir "gcc-$TARGET"
369         cd "gcc-$TARGET"
370         echo "Configuring gcc"
371         "$SRCDIR/$GCC/configure" -v \
372                 --prefix="$PREFIX" --target=$TARGET \
373                 --with-headers="$PREFIX/$TARGET/include" \
374                 --with-gcc --with-gnu-ld --with-gnu-as \
375                 --enable-threads --disable-nls --enable-languages=$GCC_LANGS \
376                 --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj \
377                 --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug \
378                 --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug \
379                 2>&1 > configure.log
380         cd "$BUILDDIR"
381 }
382
383
384 build_gcc()
385 {
386         cd "$BUILDDIR/gcc-$TARGET"
387         echo "Building gcc"
388         make CFLAGS="-O2" CXXFLAGS="-O2" GCJFLAGS="-O2" LDFLAGS="-s" DEBUG_FLAGS="-g0" 2>&1 > make.log
389         if test $? -ne 0; then
390                 echo "make of gcc failed - log available: gcc-$TARGET/make.log"
391                 exit 1
392         fi
393         if [ "x$GCC_ADA" != "x" ]; then
394                 cd gcc
395                 make "CFLAGS=-O2" "LDFLAGS=-s" gnatlib_and_tools 2>&1 > make-gnatlib.log
396                 if test $? -ne 0; then
397                         echo "make of gnatlib and tools failed - log available: gcc-$TARGET/make-gnatlib.log"
398                         exit 1
399                 fi
400         fi
401         cd "$BUILDDIR"
402 }
403
404
405 install_gcc()
406 {
407         cd "$BUILDDIR/gcc-$TARGET"
408         echo "Installing gcc"
409         make install 2>&1 > make-install.log
410         if test $? -ne 0; then
411                 echo "install of gcc failed - log available: gcc-$TARGET/make-install.log"
412                 exit 1
413         fi
414         cd "$BUILDDIR"
415 }
416
417
418 extract_mingw_utils()
419 {
420         cd "$SRCDIR"
421         MINGW_UTILS=`tar -tzf "$SRCDIR/$MINGW_UTILS_ARCHIVE" | head -n 1`
422         if [ "x${MINGW_UTILS}" != "x./" ]; then
423            rm -rf "$MINGW_UTILS"
424         fi
425         echo "Extracting mingw-utils"
426         tar -xzf "$SRCDIR/$MINGW_UTILS_ARCHIVE"
427         cd "$BUILDDIR"
428 }
429
430
431 patch_mingw_utils()
432 {
433         MINGW_UTILS=`tar -tzf "$SRCDIR/$MINGW_UTILS_ARCHIVE" | head -n 1`
434         cd "${SRCDIR}/${MINGW_UTILS}"
435         echo "Patching mingw-utils"
436         patch -p0 < ${SCRIPTDIR}/patches/mingw-utils.patch 2>&1 > patch.log
437         cd "$BUILDDIR"
438 }
439
440
441 configure_mingw_utils()
442 {
443         cd "$BUILDDIR"
444         rm -rf "mingw-utils"
445         mkdir "mingw-utils"
446         cd "mingw-utils"
447         echo "Configuring mingw-utils"
448         "$SRCDIR/$MINGW_UTILS/configure" --disable-nonportable --prefix="${PREFIX}/${TARGET}" 2>&1 > configure.log
449         cd "$BUILDDIR"
450 }
451
452
453 build_mingw_utils()
454 {
455         cd "$BUILDDIR/mingw-utils"
456         echo "Building mingw-utils"
457         make CFLAGS="-O2 -fno-exceptions" LDFLAGS="-s" 2>&1 > make.log
458         if test $? -ne 0; then
459                 echo "make of mingw-utils failed - log available: mingw-utils/make.log"
460                 exit 1
461         fi
462         cd "$BUILDDIR"
463 }
464
465
466 install_mingw_utils()
467 {
468         cd "$BUILDDIR/mingw-utils"
469         echo "Installing mingw-utils"
470         make install 2>&1 > make-install.log
471         if test $? -ne 0; then
472                 echo "install of mingw-utils failed - log available: mingw-utils/make-install.log"
473                 exit 1
474         fi
475         cd "$BUILDDIR"
476 }
477
478
479 final_tweaks()
480 {
481         echo "Finalizing installation"
482
483         # remove gcc build headers
484         rm -rf "$PREFIX/$TARGET/sys-include"
485
486         # Add extra binary links
487         if [ ! -f "$PREFIX/$TARGET/bin/objdump" ]; then
488                 ln "$PREFIX/bin/$TARGET-objdump" "$PREFIX/$TARGET/bin/objdump"
489         fi
490         if [ ! -f "$PREFIX/$TARGET/bin/dllwrap" ]; then
491                 ln "$PREFIX/bin/$TARGET-dllwrap" "$PREFIX/$TARGET/bin/dllwrap"
492         fi
493
494         # make cc and c++ symlinks to gcc and g++
495         if [ ! -f "$PREFIX/$TARGET/bin/g++" ]; then
496                 ln "$PREFIX/bin/$TARGET-g++" "$PREFIX/$TARGET/bin/g++"
497         fi
498         if [ ! -f "$PREFIX/$TARGET/bin/cc" ]; then
499                 ln -s "gcc" "$PREFIX/$TARGET/bin/cc"
500         fi
501         if [ ! -f "$PREFIX/$TARGET/bin/c++" ]; then
502                 ln -s "g++" "$PREFIX/$TARGET/bin/c++"
503         fi
504
505         # strip all the binaries
506         ls "$PREFIX"/bin/* "$PREFIX/$TARGET"/bin/* | egrep -v '.dll$' | egrep -v 'gccbug$' |
507         while read file; do
508                 strip "$file"
509         done
510
511         echo "Installation complete!"
512 }
513
514
515
516 #
517 # Main part of the script
518 #
519
520 download_files
521
522 if [ "x$PURGE_DIR" = "xY" ]; then
523         purge_existing_install
524 fi
525
526 install_libs
527
528 extract_binutils
529 patch_binutils
530 configure_binutils
531 build_binutils
532 install_binutils
533
534 extract_gcc
535 patch_gcc
536 configure_gcc
537 build_gcc
538 install_gcc
539
540 if test -n "${MINGW_UTILS_ARCHIVE}"; then
541         extract_mingw_utils
542         patch_mingw_utils
543         configure_mingw_utils
544         build_mingw_utils
545         install_mingw_utils
546 fi
547
548 final_tweaks
549
550
551 #
552 # End
553 #