build-scripts/fatbuild.sh
author Sam Lantinga <slouken@libsdl.org>
Sun, 14 Aug 2011 17:17:17 -0400
branchSDL-1.2
changeset 5608 2bee7f46cb2b
parent 4397 fb1fc6c9289e
child 5610 e55f9d0e117a
permissions -rwxr-xr-x
Fat build doesn't support PPC anymore.
     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 # Intel 32-bit configure flags (10.4 runtime compatibility)
    20 # We dynamically load X11, so using the system X11 headers is fine.
    21 CONFIG_X86="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
    22 --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
    23 
    24 # They changed this from "darwin9" to "darwin10" in Xcode 3.2 (Snow Leopard).
    25 GCCUSRPATH_X86=`ls -d $SDK_PATH/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin*/4.0.1`
    26 if [ ! -d "$GCCUSRPATH_X86" ]; then
    27     echo "Couldn't find any GCC usr path for 32-bit x86"
    28     exit 1
    29 fi
    30 GCCUSRPATH_X64=`ls -d $SDK_PATH/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin*/4.0.1`
    31 if [ ! -d "$GCCUSRPATH_X64" ]; then
    32     echo "Couldn't find any GCC usr path for 64-bit x86"
    33     exit 1
    34 fi
    35 
    36 # Intel 32-bit compiler flags
    37 CC_X86="gcc-4.0 -arch i386"
    38 CXX_X86="g++-4.0 -arch i386"
    39 CFLAGS_X86="-mmacosx-version-min=10.4"
    40 CPPFLAGS_X86="-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
    41 -nostdinc \
    42 -F$SDK_PATH/MacOSX10.4u.sdk/System/Library/Frameworks \
    43 -I$GCCUSRPATH_X86/include \
    44 -isystem $SDK_PATH/MacOSX10.4u.sdk/usr/include"
    45 
    46 # Intel 32-bit linker flags
    47 LFLAGS_X86="-arch i386 -Wl,-headerpad_max_install_names -mmacosx-version-min=10.4 \
    48 -F$SDK_PATH/MacOSX10.4u.sdk/System/Library/Frameworks \
    49 -L$GCCUSRPATH_X86 \
    50 -Wl,-syslibroot,$SDK_PATH/MacOSX10.4u.sdk"
    51 
    52 # Intel 64-bit configure flags (10.5 runtime compatibility)
    53 # We dynamically load X11, so using the system X11 headers is fine.
    54 CONFIG_X64="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
    55 --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
    56 
    57 # Intel 64-bit compiler flags
    58 CC_X64="gcc-4.0 -arch x86_64"
    59 CXX_X64="g++-4.0 -arch x86_64"
    60 CFLAGS_X64="-mmacosx-version-min=10.5"
    61 CPPFLAGS_X64="-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
    62 -nostdinc \
    63 -F$SDK_PATH/MacOSX10.5.sdk/System/Library/Frameworks \
    64 -I$GCCUSRPATH_X64/include \
    65 -isystem $SDK_PATH/MacOSX10.5.sdk/usr/include"
    66 
    67 # Intel 64-bit linker flags
    68 LFLAGS_X64="-arch x86_64 -Wl,-headerpad_max_install_names -mmacosx-version-min=10.5 \
    69 -F$SDK_PATH/MacOSX10.5.sdk/System/Library/Frameworks \
    70 -L$GCCUSRPATH_X64/x86_64 \
    71 -Wl,-syslibroot,$SDK_PATH/MacOSX10.5.sdk"
    72 
    73 #
    74 # Find the configure script
    75 #
    76 srcdir=`dirname $0`/..
    77 auxdir=$srcdir/build-scripts
    78 cd $srcdir
    79 
    80 #
    81 # Figure out which phase to build:
    82 # all,
    83 # configure, configure-ppc, configure-ppc64, configure-x86, configure-x64
    84 # make, make-ppc, make-ppc64, make-x86, make-x64, merge
    85 # install
    86 # clean
    87 if test x"$1" = x; then
    88     phase=all
    89 else
    90     phase="$1"
    91 fi
    92 case $phase in
    93     all)
    94         configure_ppc="yes"
    95         configure_ppc64="yes"
    96         configure_x86="yes"
    97         configure_x64="yes"
    98         make_ppc="yes"
    99         make_ppc64="yes"
   100         make_x86="yes"
   101         make_x64="yes"
   102         merge="yes"
   103         ;;
   104     configure)
   105         configure_ppc="yes"
   106         configure_ppc64="yes"
   107         configure_x86="yes"
   108         configure_x64="yes"
   109         ;;
   110     configure-ppc)
   111         configure_ppc="yes"
   112         ;;
   113     configure-ppc64)
   114         configure_ppc64="yes"
   115         ;;
   116     configure-x86)
   117         configure_x86="yes"
   118         ;;
   119     configure-x64)
   120         configure_x64="yes"
   121         ;;
   122     make)
   123         make_ppc="yes"
   124         make_ppc64="yes"
   125         make_x86="yes"
   126         make_x64="yes"
   127         merge="yes"
   128         ;;
   129     make-ppc)
   130         make_ppc="yes"
   131         ;;
   132     make-ppc64)
   133         make_ppc64="yes"
   134         ;;
   135     make-x86)
   136         make_x86="yes"
   137         ;;
   138     make-x64)
   139         make_x64="yes"
   140         ;;
   141     merge)
   142         merge="yes"
   143         ;;
   144     install)
   145         install_bin="yes"
   146         install_hdrs="yes"
   147         install_lib="yes"
   148         install_data="yes"
   149         install_man="yes"
   150         ;;
   151     install-bin)
   152         install_bin="yes"
   153         ;;
   154     install-hdrs)
   155         install_hdrs="yes"
   156         ;;
   157     install-lib)
   158         install_lib="yes"
   159         ;;
   160     install-data)
   161         install_data="yes"
   162         ;;
   163     install-man)
   164         install_man="yes"
   165         ;;
   166     clean)
   167         clean_ppc="yes"
   168         clean_ppc64="yes"
   169         clean_x86="yes"
   170         clean_x64="yes"
   171         ;;
   172     clean-ppc)
   173         clean_ppc="yes"
   174         ;;
   175     clean-ppc64)
   176         clean_ppc64="yes"
   177         ;;
   178     clean-x86)
   179         clean_x86="yes"
   180         ;;
   181     clean-x64)
   182         clean_x64="yes"
   183         ;;
   184     *)
   185         echo "Usage: $0 [all|configure[-ppc|-ppc64|-x86|-x64]|make[-ppc|-ppc64|-x86|-x64]|merge|install|clean[-ppc|-ppc64|-x86|-x64]]"
   186         exit 1
   187         ;;
   188 esac
   189 case `uname -p` in
   190     powerpc)
   191         native_path=ppc
   192         ;;
   193     powerpc64)
   194         native_path=ppc64
   195         ;;
   196     *86)
   197         native_path=x86
   198         ;;
   199     x86_64)
   200         native_path=x64
   201         ;;
   202     *)
   203         echo "Couldn't figure out native architecture path"
   204         exit 1
   205         ;;
   206 esac
   207 
   208 #
   209 # Create the build directories
   210 #
   211 for dir in build build/ppc build/ppc64 build/x86 build/x64; do
   212     if test -d $dir; then
   213         :
   214     else
   215         mkdir $dir || exit 1
   216     fi
   217 done
   218 
   219 #
   220 # Build the Intel 32-bit binary
   221 #
   222 if test x$configure_x86 = xyes; then
   223     (cd build/x86 && \
   224      sh ../../configure $CONFIG_X86 CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $CFLAGS_X86" CPPFLAGS="$CPPFLAGS_X86" LDFLAGS="$LFLAGS_X86") || exit 2
   225 fi
   226 if test x$make_x86 = xyes; then
   227     (cd build/x86 && make -j$NJOB) || exit 3
   228 fi
   229 
   230 #
   231 # Build the Intel 32-bit binary
   232 #
   233 if test x$configure_x64 = xyes; then
   234     (cd build/x64 && \
   235      sh ../../configure $CONFIG_X64 CC="$CC_X64" CXX="$CXX_X64" CFLAGS="$CFLAGS $CFLAGS_X64" CPPFLAGS="$CPPFLAGS_X64" LDFLAGS="$LFLAGS_X64") || exit 2
   236 fi
   237 if test x$make_x64 = xyes; then
   238     (cd build/x64 && make -j$NJOB) || exit 3
   239 fi
   240 
   241 #
   242 # Combine into fat binary
   243 #
   244 if test x$merge = xyes; then
   245     output=.libs
   246     sh $auxdir/mkinstalldirs build/$output
   247     cd build
   248     target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
   249     (lipo -create -o $output/$target `find . -mindepth 4 -maxdepth 4 -type f -name "*.dylib"` &&
   250      ln -sf $target $output/libSDL.dylib &&
   251      lipo -create -o $output/libSDL.a */build/.libs/libSDL.a &&
   252      cp $native_path/build/.libs/libSDL.la $output &&
   253      cp $native_path/build/.libs/libSDL.lai $output &&
   254      cp $native_path/build/libSDL.la . &&
   255      lipo -create -o libSDLmain.a */build/libSDLmain.a &&
   256      echo "Build complete!" &&
   257      echo "Files can be found in the build directory.") || exit 4
   258     cd ..
   259 fi
   260 
   261 #
   262 # Install
   263 #
   264 do_install()
   265 {
   266     echo $*
   267     $* || exit 5
   268 }
   269 if test x$prefix = x; then
   270     prefix=/usr/local
   271 fi
   272 if test x$exec_prefix = x; then
   273     exec_prefix=$prefix
   274 fi
   275 if test x$bindir = x; then
   276     bindir=$exec_prefix/bin
   277 fi
   278 if test x$libdir = x; then
   279     libdir=$exec_prefix/lib
   280 fi
   281 if test x$includedir = x; then
   282     includedir=$prefix/include
   283 fi
   284 if test x$datadir = x; then
   285     datadir=$prefix/share
   286 fi
   287 if test x$mandir = x; then
   288     mandir=$prefix/man
   289 fi
   290 if test x$install_bin = xyes; then
   291     do_install sh $auxdir/mkinstalldirs $bindir
   292     do_install /usr/bin/install -c -m 755 build/$native_path/sdl-config $bindir/sdl-config
   293 fi
   294 if test x$install_hdrs = xyes; then
   295     do_install sh $auxdir/mkinstalldirs $includedir/SDL
   296     for src in $srcdir/include/*.h; do \
   297         file=`echo $src | sed -e 's|^.*/||'`; \
   298         do_install /usr/bin/install -c -m 644 $src $includedir/SDL/$file; \
   299     done
   300     do_install /usr/bin/install -c -m 644 $srcdir/include/SDL_config_macosx.h $includedir/SDL/SDL_config.h
   301 fi
   302 if test x$install_lib = xyes; then
   303     do_install sh $auxdir/mkinstalldirs $libdir
   304     do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDL.la $libdir/libSDL.la
   305     do_install /usr/bin/install -c -m 644 build/libSDLmain.a $libdir/libSDLmain.a
   306     do_install ranlib $libdir/libSDLmain.a
   307 fi
   308 if test x$install_data = xyes; then
   309     do_install sh $auxdir/mkinstalldirs $datadir/aclocal
   310     do_install /usr/bin/install -c -m 644 $srcdir/sdl.m4 $datadir/aclocal/sdl.m4
   311 fi
   312 if test x$install_man = xyes; then
   313     do_install sh $auxdir/mkinstalldirs $mandir/man3
   314     for src in $srcdir/docs/man3/*.3; do \
   315         file=`echo $src | sed -e 's|^.*/||'`; \
   316         do_install /usr/bin/install -c -m 644 $src $mandir/man3/$file; \
   317     done
   318 fi
   319 
   320 #
   321 # Clean up
   322 #
   323 do_clean()
   324 {
   325     echo $*
   326     $* || exit 6
   327 }
   328 if test x$clean_x86 = xyes; then
   329     do_clean rm -r build/x86
   330 fi
   331 if test x$clean_ppc = xyes; then
   332     do_clean rm -r build/ppc
   333 fi
   334