build-scripts/fatbuild.sh
author Ryan C. Gordon <icculus@icculus.org>
Wed, 06 Jan 2010 06:44:23 +0000
changeset 3609 72a1c4dda07c
parent 3524 5668e43c256b
child 3629 102be1cdd2bb
permissions -rwxr-xr-x
Merged r3808:3809 from branches/SDL-1.2: install_name_tool fix for fatbuild.sh.
     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 if test x$NJOB = x; then
     8     NJOB=$NCPU
     9 fi
    10 
    11 # Generic, cross-platform CFLAGS you always want go here.
    12 CFLAGS="-O3 -g -pipe"
    13 
    14 # PowerPC 32-bit configure flags (10.4 runtime compatibility)
    15 # We dynamically load X11, so using the system X11 headers is fine.
    16 CONFIG_PPC="--build=`uname -p`-apple-darwin --host=powerpc-apple-darwin \
    17 --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
    18 
    19 # PowerPC 32-bit compiler flags
    20 CC_PPC="gcc-4.0 -arch ppc"
    21 CXX_PPC="g++-4.0 -arch ppc"
    22 CFLAGS_PPC="-mmacosx-version-min=10.4"
    23 CPPFLAGS_PPC="-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/powerpc-apple-darwin10/4.0.1/include \
    27 -isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
    28 
    29 # PowerPC 32-bit linker flags
    30 LFLAGS_PPC="-arch ppc -Wl,-headerpad_max_install_names -mmacosx-version-min=10.4 \
    31 -F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
    32 -L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1 \
    33 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
    34 
    35 # PowerPC 64-bit configure flags (10.5 runtime compatibility)
    36 # We dynamically load X11, so using the system X11 headers is fine.
    37 CONFIG_PPC64="--build=`uname -p`-apple-darwin --host=powerpc-apple-darwin \
    38 --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
    39 
    40 # PowerPC 64-bit compiler flags
    41 CC_PPC64="gcc-4.0 -arch ppc64"
    42 CXX_PPC64="g++-4.0 -arch ppc64"
    43 CFLAGS_PPC64="-mmacosx-version-min=10.5"
    44 CPPFLAGS_PPC64="-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
    45 -nostdinc \
    46 -F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
    47 -I/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/include \
    48 -isystem /Developer/SDKs/MacOSX10.5.sdk/usr/include"
    49 
    50 # PowerPC 64-bit linker flags
    51 LFLAGS_PPC64="-arch ppc64 -Wl,-headerpad_max_install_names -mmacosx-version-min=10.5 \
    52 -F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
    53 -L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/powerpc-apple-darwin10/4.0.1/ppc64 \
    54 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
    55 
    56 # Intel 32-bit configure flags (10.4 runtime compatibility)
    57 # We dynamically load X11, so using the system X11 headers is fine.
    58 CONFIG_X86="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
    59 --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
    60 
    61 # Intel 32-bit configure flags (10.4 runtime compatibility)
    62 # We dynamically load X11, so using the system X11 headers is fine.
    63 CONFIG_X86="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
    64 --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
    65 
    66 # Intel 32-bit compiler flags
    67 CC_X86="gcc-4.0 -arch i386"
    68 CXX_X86="g++-4.0 -arch i386"
    69 CFLAGS_X86="-mmacosx-version-min=10.4"
    70 CPPFLAGS_X86="-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
    71 -nostdinc \
    72 -F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
    73 -I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/include \
    74 -isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
    75 
    76 # Intel 32-bit linker flags
    77 LFLAGS_X86="-arch i386 -Wl,-headerpad_max_install_names -mmacosx-version-min=10.4 \
    78 -F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
    79 -L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1 \
    80 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
    81 
    82 # Intel 64-bit configure flags (10.5 runtime compatibility)
    83 # We dynamically load X11, so using the system X11 headers is fine.
    84 CONFIG_X64="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
    85 --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
    86 
    87 # Intel 64-bit compiler flags
    88 CC_X64="gcc-4.0 -arch x86_64"
    89 CXX_X64="g++-4.0 -arch x86_64"
    90 CFLAGS_X64="-mmacosx-version-min=10.5"
    91 CPPFLAGS_X64="-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
    92 -nostdinc \
    93 -F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
    94 -I/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/include \
    95 -isystem /Developer/SDKs/MacOSX10.5.sdk/usr/include"
    96 
    97 # Intel 64-bit linker flags
    98 LFLAGS_X64="-arch x86_64 -Wl,-headerpad_max_install_names -mmacosx-version-min=10.5 \
    99 -F/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks \
   100 -L/Developer/SDKs/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin10/4.0.1/x86_64 \
   101 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk"
   102 
   103 #
   104 # Find the configure script
   105 #
   106 srcdir=`dirname $0`/..
   107 auxdir=$srcdir/build-scripts
   108 cd $srcdir
   109 
   110 #
   111 # Figure out which phase to build:
   112 # all,
   113 # configure, configure-ppc, configure-ppc64, configure-x86, configure-x64
   114 # make, make-ppc, make-ppc64, make-x86, make-x64, merge
   115 # install
   116 # clean
   117 if test x"$1" = x; then
   118     phase=all
   119 else
   120     phase="$1"
   121 fi
   122 case $phase in
   123     all)
   124         configure_ppc="yes"
   125         configure_ppc64="yes"
   126         configure_x86="yes"
   127         configure_x64="yes"
   128         make_ppc="yes"
   129         make_ppc64="yes"
   130         make_x86="yes"
   131         make_x64="yes"
   132         merge="yes"
   133         ;;
   134     configure)
   135         configure_ppc="yes"
   136         configure_ppc64="yes"
   137         configure_x86="yes"
   138         configure_x64="yes"
   139         ;;
   140     configure-ppc)
   141         configure_ppc="yes"
   142         ;;
   143     configure-ppc64)
   144         configure_ppc64="yes"
   145         ;;
   146     configure-x86)
   147         configure_x86="yes"
   148         ;;
   149     configure-x64)
   150         configure_x64="yes"
   151         ;;
   152     make)
   153         make_ppc="yes"
   154         make_ppc64="yes"
   155         make_x86="yes"
   156         make_x64="yes"
   157         merge="yes"
   158         ;;
   159     make-ppc)
   160         make_ppc="yes"
   161         ;;
   162     make-ppc64)
   163         make_ppc64="yes"
   164         ;;
   165     make-x86)
   166         make_x86="yes"
   167         ;;
   168     make-x64)
   169         make_x64="yes"
   170         ;;
   171     merge)
   172         merge="yes"
   173         ;;
   174     install)
   175         install_bin="yes"
   176         install_hdrs="yes"
   177         install_lib="yes"
   178         install_data="yes"
   179         install_man="yes"
   180         ;;
   181     install-bin)
   182         install_bin="yes"
   183         ;;
   184     install-hdrs)
   185         install_hdrs="yes"
   186         ;;
   187     install-lib)
   188         install_lib="yes"
   189         ;;
   190     install-data)
   191         install_data="yes"
   192         ;;
   193     install-man)
   194         install_man="yes"
   195         ;;
   196     clean)
   197         clean_ppc="yes"
   198         clean_ppc64="yes"
   199         clean_x86="yes"
   200         clean_x64="yes"
   201         ;;
   202     clean-ppc)
   203         clean_ppc="yes"
   204         ;;
   205     clean-ppc64)
   206         clean_ppc64="yes"
   207         ;;
   208     clean-x86)
   209         clean_x86="yes"
   210         ;;
   211     clean-x64)
   212         clean_x64="yes"
   213         ;;
   214     *)
   215         echo "Usage: $0 [all|configure[-ppc|-ppc64|-x86|-x64]|make[-ppc|-ppc64|-x86|-x64]|merge|install|clean[-ppc|-ppc64|-x86|-x64]]"
   216         exit 1
   217         ;;
   218 esac
   219 case `uname -p` in
   220     powerpc)
   221         native_path=ppc
   222         ;;
   223     powerpc64)
   224         native_path=ppc64
   225         ;;
   226     *86)
   227         native_path=x86
   228         ;;
   229     x86_64)
   230         native_path=x64
   231         ;;
   232     *)
   233         echo "Couldn't figure out native architecture path"
   234         exit 1
   235         ;;
   236 esac
   237 
   238 #
   239 # Create the build directories
   240 #
   241 for dir in build build/ppc build/ppc64 build/x86 build/x64; do
   242     if test -d $dir; then
   243         :
   244     else
   245         mkdir $dir || exit 1
   246     fi
   247 done
   248 
   249 #
   250 # Build the PowerPC 32-bit binary
   251 #
   252 if test x$configure_ppc = xyes; then
   253     (cd build/ppc && \
   254      sh ../../configure $CONFIG_PPC CC="$CC_PPC" CXX="$CXX_PPC" CFLAGS="$CFLAGS $CFLAGS_PPC" CPPFLAGS="$CPPFLAGS_PPC" LDFLAGS="$LFLAGS_PPC") || exit 2
   255 fi
   256 if test x$make_ppc = xyes; then
   257     (cd build/ppc && ls include && make -j$NJOB) || exit 3
   258 fi
   259 
   260 #
   261 # Build the PowerPC 64-bit binary
   262 #
   263 if test x$configure_ppc64 = xyes; then
   264     (cd build/ppc64 && \
   265      sh ../../configure $CONFIG_PPC64 CC="$CC_PPC64" CXX="$CXX_PPC64" CFLAGS="$CFLAGS $CFLAGS_PPC64" CPPFLAGS="$CPPFLAGS_PPC64" LDFLAGS="$LFLAGS_PPC64") || exit 2
   266 fi
   267 if test x$make_ppc64 = xyes; then
   268     (cd build/ppc64 && ls include && make -j$NJOB) || exit 3
   269 fi
   270 
   271 #
   272 # Build the Intel 32-bit binary
   273 #
   274 if test x$configure_x86 = xyes; then
   275     (cd build/x86 && \
   276      sh ../../configure $CONFIG_X86 CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $CFLAGS_X86" CPPFLAGS="$CPPFLAGS_X86" LDFLAGS="$LFLAGS_X86") || exit 2
   277 fi
   278 if test x$make_x86 = xyes; then
   279     (cd build/x86 && make -j$NJOB) || exit 3
   280 fi
   281 
   282 #
   283 # Build the Intel 32-bit binary
   284 #
   285 if test x$configure_x64 = xyes; then
   286     (cd build/x64 && \
   287      sh ../../configure $CONFIG_X64 CC="$CC_X64" CXX="$CXX_X64" CFLAGS="$CFLAGS $CFLAGS_X64" CPPFLAGS="$CPPFLAGS_X64" LDFLAGS="$LFLAGS_X64") || exit 2
   288 fi
   289 if test x$make_x64 = xyes; then
   290     (cd build/x64 && make -j$NJOB) || exit 3
   291 fi
   292 
   293 #
   294 # Combine into fat binary
   295 #
   296 if test x$merge = xyes; then
   297     output=.libs
   298     sh $auxdir/mkinstalldirs build/$output
   299     cd build
   300     target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
   301     (lipo -create -o $output/$target `find . -mindepth 4 -maxdepth 4 -type f -name "*.dylib"` &&
   302      ln -sf $target $output/libSDL.dylib &&
   303      lipo -create -o $output/libSDL.a */build/.libs/libSDL.a &&
   304      cp $native_path/build/.libs/libSDL.la $output &&
   305      cp $native_path/build/.libs/libSDL.lai $output &&
   306      cp $native_path/build/libSDL.la . &&
   307      lipo -create -o libSDLmain.a */build/libSDLmain.a &&
   308      echo "Build complete!" &&
   309      echo "Files can be found in the build directory.") || exit 4
   310     cd ..
   311 fi
   312 
   313 #
   314 # Install
   315 #
   316 do_install()
   317 {
   318     echo $*
   319     $* || exit 5
   320 }
   321 if test x$prefix = x; then
   322     prefix=/usr/local
   323 fi
   324 if test x$exec_prefix = x; then
   325     exec_prefix=$prefix
   326 fi
   327 if test x$bindir = x; then
   328     bindir=$exec_prefix/bin
   329 fi
   330 if test x$libdir = x; then
   331     libdir=$exec_prefix/lib
   332 fi
   333 if test x$includedir = x; then
   334     includedir=$prefix/include
   335 fi
   336 if test x$datadir = x; then
   337     datadir=$prefix/share
   338 fi
   339 if test x$mandir = x; then
   340     mandir=$prefix/man
   341 fi
   342 if test x$install_bin = xyes; then
   343     do_install sh $auxdir/mkinstalldirs $bindir
   344     do_install /usr/bin/install -c -m 755 build/$native_path/sdl-config $bindir/sdl-config
   345 fi
   346 if test x$install_hdrs = xyes; then
   347     do_install sh $auxdir/mkinstalldirs $includedir/SDL
   348     for src in $srcdir/include/*.h; do \
   349         file=`echo $src | sed -e 's|^.*/||'`; \
   350         do_install /usr/bin/install -c -m 644 $src $includedir/SDL/$file; \
   351     done
   352     do_install /usr/bin/install -c -m 644 $srcdir/include/SDL_config_macosx.h $includedir/SDL/SDL_config.h
   353 fi
   354 if test x$install_lib = xyes; then
   355     do_install sh $auxdir/mkinstalldirs $libdir
   356     do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDL.la $libdir/libSDL.la
   357     do_install /usr/bin/install -c -m 644 build/libSDLmain.a $libdir/libSDLmain.a
   358     do_install ranlib $libdir/libSDLmain.a
   359 fi
   360 if test x$install_data = xyes; then
   361     do_install sh $auxdir/mkinstalldirs $datadir/aclocal
   362     do_install /usr/bin/install -c -m 644 $srcdir/sdl.m4 $datadir/aclocal/sdl.m4
   363 fi
   364 if test x$install_man = xyes; then
   365     do_install sh $auxdir/mkinstalldirs $mandir/man3
   366     for src in $srcdir/docs/man3/*.3; do \
   367         file=`echo $src | sed -e 's|^.*/||'`; \
   368         do_install /usr/bin/install -c -m 644 $src $mandir/man3/$file; \
   369     done
   370 fi
   371 
   372 #
   373 # Clean up
   374 #
   375 do_clean()
   376 {
   377     echo $*
   378     $* || exit 6
   379 }
   380 if test x$clean_x86 = xyes; then
   381     do_clean rm -r build/x86
   382 fi
   383 if test x$clean_ppc = xyes; then
   384     do_clean rm -r build/ppc
   385 fi
   386