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