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