build-scripts/fatbuild.sh
author Sam Lantinga <slouken@libsdl.org>
Sun, 09 Jan 2011 08:35:18 -0800
changeset 4968 379361d5e425
parent 4926 ab02a7242f08
child 5609 3619f9bc639a
permissions -rwxr-xr-x
Jcw87 to Sam

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