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