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