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