build-scripts/fatbuild.sh
author Ryan C. Gordon <icculus@icculus.org>
Sun, 10 Jan 2010 08:15:25 +0000
changeset 3629 102be1cdd2bb
parent 3609 72a1c4dda07c
child 4924 455c0dad84df
permissions -rwxr-xr-x
Merge r5179:5180 from branches/SDL-1.2: fatbuild.sh Xcode 3.2 fix.
     1 #!/bin/sh
     2 #
     3 # Build a fat binary on Mac OS X, thanks Ryan!
     4 
     5 # Number of CPUs (for make -j)
     6 NCPU=`sysctl -n hw.ncpu`
     7 if test x$NJOB = x; then
     8     NJOB=$NCPU
     9 fi
    10 
    11 # Generic, cross-platform CFLAGS you always want go here.
    12 CFLAGS="-O3 -g -pipe"
    13 
    14 # PowerPC 32-bit configure flags (10.4 runtime compatibility)
    15 # We dynamically load X11, so using the system X11 headers is fine.
    16 CONFIG_PPC="--build=`uname -p`-apple-darwin --host=powerpc-apple-darwin \
    17 --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
    18 
    19 # PowerPC 32-bit compiler flags
    20 CC_PPC="gcc-4.0 -arch ppc"
    21 CXX_PPC="g++-4.0 -arch ppc"
    22 CFLAGS_PPC="-mmacosx-version-min=10.4"
    23 CPPFLAGS_PPC="-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
    24 -nostdinc \
    25 -F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
    26 -I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/include \
    27 -isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
    28 
    29 # PowerPC 32-bit linker flags
    30 LFLAGS_PPC="-arch ppc -Wl,-headerpad_max_install_names -mmacosx-version-min=10.4 \
    31 -F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
    32 -L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1 \
    33 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
    34 
    35 # PowerPC 64-bit configure flags (10.5 runtime compatibility)
    36 # We dynamically load X11, so using the system X11 headers is fine.
    37 CONFIG_PPC64="--build=`uname -p`-apple-darwin --host=powerpc-apple-darwin \
    38 --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
    39 
    40 # PowerPC 64-bit compiler flags
    41 CC_PPC64="gcc-4.0 -arch ppc64"
    42 CXX_PPC64="g++-4.0 -arch ppc64"
    43 CFLAGS_PPC64="-mmacosx-version-min=10.5"
    44 CPPFLAGS_PPC64="-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
    45 -nostdinc \
    46 -F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
    47 -I/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/include \
    48 -isystem /Developer/SDKs/MacOSX10.5.sdk/usr/include"
    49 
    50 # PowerPC 64-bit linker flags
    51 LFLAGS_PPC64="-arch ppc64 -Wl,-headerpad_max_install_names -mmacosx-version-min=10.5 \
    52 -F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
    53 -L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/ppc64 \
    54 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
    55 
    56 # Intel 32-bit configure flags (10.4 runtime compatibility)
    57 # We dynamically load X11, so using the system X11 headers is fine.
    58 CONFIG_X86="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
    59 --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
    60 
    61 # Intel 32-bit configure flags (10.4 runtime compatibility)
    62 # We dynamically load X11, so using the system X11 headers is fine.
    63 CONFIG_X86="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
    64 --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
    65 
    66 # They changed this to "darwin10" in Xcode 3.2 (Snow Leopard).
    67 GCCUSRPATH_X86="$SDK_PATH/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin9/4.0.1"
    68 if [ ! -d "$GCCUSRPATH" ]; then
    69     GCCUSRPATH_X86="$SDK_PATH/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1"
    70 fi
    71 if [ ! -d "$GCCUSRPATH_X86" ]; then
    72     echo "Couldn't find any GCC usr path for x86"
    73     exit 1
    74 fi
    75 
    76 # Intel 32-bit compiler flags
    77 CC_X86="gcc-4.0 -arch i386"
    78 CXX_X86="g++-4.0 -arch i386"
    79 CFLAGS_X86="-mmacosx-version-min=10.4"
    80 CPPFLAGS_X86="-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
    81 -nostdinc \
    82 -F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
    83 -I$GCCUSRPATH_X86/include \
    84 -isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
    85 
    86 # Intel 32-bit linker flags
    87 LFLAGS_X86="-arch i386 -Wl,-headerpad_max_install_names -mmacosx-version-min=10.4 \
    88 -F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
    89 -L$GCCUSRPATH_X86 \
    90 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
    91 
    92 # Intel 64-bit configure flags (10.5 runtime compatibility)
    93 # We dynamically load X11, so using the system X11 headers is fine.
    94 CONFIG_X64="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
    95 --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
    96 
    97 # Intel 64-bit compiler flags
    98 CC_X64="gcc-4.0 -arch x86_64"
    99 CXX_X64="g++-4.0 -arch x86_64"
   100 CFLAGS_X64="-mmacosx-version-min=10.5"
   101 CPPFLAGS_X64="-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
   102 -nostdinc \
   103 -F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
   104 -I/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/include \
   105 -isystem /Developer/SDKs/MacOSX10.5.sdk/usr/include"
   106 
   107 # Intel 64-bit linker flags
   108 LFLAGS_X64="-arch x86_64 -Wl,-headerpad_max_install_names -mmacosx-version-min=10.5 \
   109 -F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
   110 -L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/x86_64 \
   111 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
   112 
   113 #
   114 # Find the configure script
   115 #
   116 srcdir=`dirname $0`/..
   117 auxdir=$srcdir/build-scripts
   118 cd $srcdir
   119 
   120 #
   121 # Figure out which phase to build:
   122 # all,
   123 # configure, configure-ppc, configure-ppc64, configure-x86, configure-x64
   124 # make, make-ppc, make-ppc64, make-x86, make-x64, merge
   125 # install
   126 # clean
   127 if test x"$1" = x; then
   128     phase=all
   129 else
   130     phase="$1"
   131 fi
   132 case $phase in
   133     all)
   134         configure_ppc="yes"
   135         configure_ppc64="yes"
   136         configure_x86="yes"
   137         configure_x64="yes"
   138         make_ppc="yes"
   139         make_ppc64="yes"
   140         make_x86="yes"
   141         make_x64="yes"
   142         merge="yes"
   143         ;;
   144     configure)
   145         configure_ppc="yes"
   146         configure_ppc64="yes"
   147         configure_x86="yes"
   148         configure_x64="yes"
   149         ;;
   150     configure-ppc)
   151         configure_ppc="yes"
   152         ;;
   153     configure-ppc64)
   154         configure_ppc64="yes"
   155         ;;
   156     configure-x86)
   157         configure_x86="yes"
   158         ;;
   159     configure-x64)
   160         configure_x64="yes"
   161         ;;
   162     make)
   163         make_ppc="yes"
   164         make_ppc64="yes"
   165         make_x86="yes"
   166         make_x64="yes"
   167         merge="yes"
   168         ;;
   169     make-ppc)
   170         make_ppc="yes"
   171         ;;
   172     make-ppc64)
   173         make_ppc64="yes"
   174         ;;
   175     make-x86)
   176         make_x86="yes"
   177         ;;
   178     make-x64)
   179         make_x64="yes"
   180         ;;
   181     merge)
   182         merge="yes"
   183         ;;
   184     install)
   185         install_bin="yes"
   186         install_hdrs="yes"
   187         install_lib="yes"
   188         install_data="yes"
   189         install_man="yes"
   190         ;;
   191     install-bin)
   192         install_bin="yes"
   193         ;;
   194     install-hdrs)
   195         install_hdrs="yes"
   196         ;;
   197     install-lib)
   198         install_lib="yes"
   199         ;;
   200     install-data)
   201         install_data="yes"
   202         ;;
   203     install-man)
   204         install_man="yes"
   205         ;;
   206     clean)
   207         clean_ppc="yes"
   208         clean_ppc64="yes"
   209         clean_x86="yes"
   210         clean_x64="yes"
   211         ;;
   212     clean-ppc)
   213         clean_ppc="yes"
   214         ;;
   215     clean-ppc64)
   216         clean_ppc64="yes"
   217         ;;
   218     clean-x86)
   219         clean_x86="yes"
   220         ;;
   221     clean-x64)
   222         clean_x64="yes"
   223         ;;
   224     *)
   225         echo "Usage: $0 [all|configure[-ppc|-ppc64|-x86|-x64]|make[-ppc|-ppc64|-x86|-x64]|merge|install|clean[-ppc|-ppc64|-x86|-x64]]"
   226         exit 1
   227         ;;
   228 esac
   229 case `uname -p` in
   230     powerpc)
   231         native_path=ppc
   232         ;;
   233     powerpc64)
   234         native_path=ppc64
   235         ;;
   236     *86)
   237         native_path=x86
   238         ;;
   239     x86_64)
   240         native_path=x64
   241         ;;
   242     *)
   243         echo "Couldn't figure out native architecture path"
   244         exit 1
   245         ;;
   246 esac
   247 
   248 #
   249 # Create the build directories
   250 #
   251 for dir in build build/ppc build/ppc64 build/x86 build/x64; do
   252     if test -d $dir; then
   253         :
   254     else
   255         mkdir $dir || exit 1
   256     fi
   257 done
   258 
   259 #
   260 # Build the PowerPC 32-bit binary
   261 #
   262 if test x$configure_ppc = xyes; then
   263     (cd build/ppc && \
   264      sh ../../configure $CONFIG_PPC CC="$CC_PPC" CXX="$CXX_PPC" CFLAGS="$CFLAGS $CFLAGS_PPC" CPPFLAGS="$CPPFLAGS_PPC" LDFLAGS="$LFLAGS_PPC") || exit 2
   265 fi
   266 if test x$make_ppc = xyes; then
   267     (cd build/ppc && ls include && make -j$NJOB) || exit 3
   268 fi
   269 
   270 #
   271 # Build the PowerPC 64-bit binary
   272 #
   273 if test x$configure_ppc64 = xyes; then
   274     (cd build/ppc64 && \
   275      sh ../../configure $CONFIG_PPC64 CC="$CC_PPC64" CXX="$CXX_PPC64" CFLAGS="$CFLAGS $CFLAGS_PPC64" CPPFLAGS="$CPPFLAGS_PPC64" LDFLAGS="$LFLAGS_PPC64") || exit 2
   276 fi
   277 if test x$make_ppc64 = xyes; then
   278     (cd build/ppc64 && ls include && make -j$NJOB) || exit 3
   279 fi
   280 
   281 #
   282 # Build the Intel 32-bit binary
   283 #
   284 if test x$configure_x86 = xyes; then
   285     (cd build/x86 && \
   286      sh ../../configure $CONFIG_X86 CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $CFLAGS_X86" CPPFLAGS="$CPPFLAGS_X86" LDFLAGS="$LFLAGS_X86") || exit 2
   287 fi
   288 if test x$make_x86 = xyes; then
   289     (cd build/x86 && make -j$NJOB) || exit 3
   290 fi
   291 
   292 #
   293 # Build the Intel 32-bit binary
   294 #
   295 if test x$configure_x64 = xyes; then
   296     (cd build/x64 && \
   297      sh ../../configure $CONFIG_X64 CC="$CC_X64" CXX="$CXX_X64" CFLAGS="$CFLAGS $CFLAGS_X64" CPPFLAGS="$CPPFLAGS_X64" LDFLAGS="$LFLAGS_X64") || exit 2
   298 fi
   299 if test x$make_x64 = xyes; then
   300     (cd build/x64 && make -j$NJOB) || exit 3
   301 fi
   302 
   303 #
   304 # Combine into fat binary
   305 #
   306 if test x$merge = xyes; then
   307     output=.libs
   308     sh $auxdir/mkinstalldirs build/$output
   309     cd build
   310     target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
   311     (lipo -create -o $output/$target `find . -mindepth 4 -maxdepth 4 -type f -name "*.dylib"` &&
   312      ln -sf $target $output/libSDL.dylib &&
   313      lipo -create -o $output/libSDL.a */build/.libs/libSDL.a &&
   314      cp $native_path/build/.libs/libSDL.la $output &&
   315      cp $native_path/build/.libs/libSDL.lai $output &&
   316      cp $native_path/build/libSDL.la . &&
   317      lipo -create -o libSDLmain.a */build/libSDLmain.a &&
   318      echo "Build complete!" &&
   319      echo "Files can be found in the build directory.") || exit 4
   320     cd ..
   321 fi
   322 
   323 #
   324 # Install
   325 #
   326 do_install()
   327 {
   328     echo $*
   329     $* || exit 5
   330 }
   331 if test x$prefix = x; then
   332     prefix=/usr/local
   333 fi
   334 if test x$exec_prefix = x; then
   335     exec_prefix=$prefix
   336 fi
   337 if test x$bindir = x; then
   338     bindir=$exec_prefix/bin
   339 fi
   340 if test x$libdir = x; then
   341     libdir=$exec_prefix/lib
   342 fi
   343 if test x$includedir = x; then
   344     includedir=$prefix/include
   345 fi
   346 if test x$datadir = x; then
   347     datadir=$prefix/share
   348 fi
   349 if test x$mandir = x; then
   350     mandir=$prefix/man
   351 fi
   352 if test x$install_bin = xyes; then
   353     do_install sh $auxdir/mkinstalldirs $bindir
   354     do_install /usr/bin/install -c -m 755 build/$native_path/sdl-config $bindir/sdl-config
   355 fi
   356 if test x$install_hdrs = xyes; then
   357     do_install sh $auxdir/mkinstalldirs $includedir/SDL
   358     for src in $srcdir/include/*.h; do \
   359         file=`echo $src | sed -e 's|^.*/||'`; \
   360         do_install /usr/bin/install -c -m 644 $src $includedir/SDL/$file; \
   361     done
   362     do_install /usr/bin/install -c -m 644 $srcdir/include/SDL_config_macosx.h $includedir/SDL/SDL_config.h
   363 fi
   364 if test x$install_lib = xyes; then
   365     do_install sh $auxdir/mkinstalldirs $libdir
   366     do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDL.la $libdir/libSDL.la
   367     do_install /usr/bin/install -c -m 644 build/libSDLmain.a $libdir/libSDLmain.a
   368     do_install ranlib $libdir/libSDLmain.a
   369 fi
   370 if test x$install_data = xyes; then
   371     do_install sh $auxdir/mkinstalldirs $datadir/aclocal
   372     do_install /usr/bin/install -c -m 644 $srcdir/sdl.m4 $datadir/aclocal/sdl.m4
   373 fi
   374 if test x$install_man = xyes; then
   375     do_install sh $auxdir/mkinstalldirs $mandir/man3
   376     for src in $srcdir/docs/man3/*.3; do \
   377         file=`echo $src | sed -e 's|^.*/||'`; \
   378         do_install /usr/bin/install -c -m 644 $src $mandir/man3/$file; \
   379     done
   380 fi
   381 
   382 #
   383 # Clean up
   384 #
   385 do_clean()
   386 {
   387     echo $*
   388     $* || exit 6
   389 }
   390 if test x$clean_x86 = xyes; then
   391     do_clean rm -r build/x86
   392 fi
   393 if test x$clean_ppc = xyes; then
   394     do_clean rm -r build/ppc
   395 fi
   396