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