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