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