build-scripts/fatbuild.sh
author Cameron Cawley <ccawley2011@gmail.com>
Fri, 26 Apr 2019 17:41:20 +0100
branchSDL-1.2
changeset 12778 c47cdc60c1b3
parent 6279 8e98c714bb2a
permissions -rwxr-xr-x
riscos: Clean up SWI calls
     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 # SDK path
    12 if test x$SDK_PATH = x; then
    13     SDK_PATH=/Developer/SDKs
    14 fi
    15 
    16 # Generic, cross-platform CFLAGS you always want go here.
    17 CFLAGS="-O3 -g -pipe"
    18 
    19 # We dynamically load X11, so using the system X11 headers is fine.
    20 BASE_CONFIG_FLAGS="--build=`uname -p`-apple-darwin \
    21 --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
    22 
    23 # PowerPC 32-bit compiler flags
    24 CONFIG_PPC="--host=powerpc-apple-darwin"
    25 CC_PPC="gcc-4.0"
    26 CXX_PPC="g++-4.0"
    27 BUILD_FLAGS_PPC="-arch ppc -mmacosx-version-min=10.4"
    28 
    29 # Intel 32-bit compiler flags
    30 CONFIG_X86="--host=i386-apple-darwin"
    31 CC_X86="gcc"
    32 CXX_X86="g++"
    33 BUILD_FLAGS_X86="-arch i386 -mmacosx-version-min=10.4"
    34 
    35 # Intel 64-bit compiler flags
    36 CONFIG_X64="--host=x86_64-apple-darwin"
    37 CC_X64="gcc"
    38 CXX_X64="g++"
    39 BUILD_FLAGS_X64="-arch x86_64 -mmacosx-version-min=10.6"
    40 
    41 #
    42 # Find the configure script
    43 #
    44 srcdir=`dirname $0`/..
    45 srcdir=`cd $srcdir && pwd`
    46 auxdir=$srcdir/build-scripts
    47 cd $srcdir
    48 
    49 allow_ppc="yes"
    50 which gcc-4.0 >/dev/null 2>/dev/null
    51 if [ "x$?" = "x1" ]; then
    52     #echo "WARNING: Can't find gcc-4.0, which means you don't have Xcode 3."
    53     #echo "WARNING: Therefore, we can't do PowerPC support."
    54     allow_ppc="no"
    55 fi
    56 
    57 #
    58 # Figure out which phase to build:
    59 # all,
    60 # configure, configure-ppc, configure-x86, configure-x64
    61 # make, make-ppc, make-x86, make-x64, merge
    62 # install
    63 # clean
    64 if test x"$1" = x; then
    65     phase=all
    66 else
    67     phase="$1"
    68 fi
    69 case $phase in
    70     all)
    71         configure_ppc="$allow_ppc"
    72         configure_x86="yes"
    73         configure_x64="yes"
    74         make_ppc="$allow_ppc"
    75         make_x86="yes"
    76         make_x64="yes"
    77         merge="yes"
    78         ;;
    79     configure)
    80         configure_ppc="$allow_ppc"
    81         configure_x86="yes"
    82         configure_x64="yes"
    83         ;;
    84     configure-ppc)
    85         configure_ppc="$allow_ppc"
    86         ;;
    87     configure-x86)
    88         configure_x86="yes"
    89         ;;
    90     configure-x64)
    91         configure_x64="yes"
    92         ;;
    93     make)
    94         make_ppc="$allow_ppc"
    95         make_x86="yes"
    96         make_x64="yes"
    97         merge="yes"
    98         ;;
    99     make-ppc)
   100         make_ppc="$allow_ppc"
   101         ;;
   102     make-x86)
   103         make_x86="yes"
   104         ;;
   105     make-x64)
   106         make_x64="yes"
   107         ;;
   108     merge)
   109         merge="yes"
   110         ;;
   111     install)
   112         install_bin="yes"
   113         install_hdrs="yes"
   114         install_lib="yes"
   115         install_data="yes"
   116         install_man="yes"
   117         ;;
   118     install-bin)
   119         install_bin="yes"
   120         ;;
   121     install-hdrs)
   122         install_hdrs="yes"
   123         ;;
   124     install-lib)
   125         install_lib="yes"
   126         ;;
   127     install-data)
   128         install_data="yes"
   129         ;;
   130     install-man)
   131         install_man="yes"
   132         ;;
   133     clean)
   134         clean_ppc="yes"
   135         clean_x86="yes"
   136         clean_x64="yes"
   137         ;;
   138     clean-ppc)
   139         clean_ppc="yes"
   140         ;;
   141     clean-x86)
   142         clean_x86="yes"
   143         ;;
   144     clean-x64)
   145         clean_x64="yes"
   146         ;;
   147     *)
   148         echo "Usage: $0 [all|configure[-ppc|-x86|-x64]|make[-ppc|-x86|-x64]|merge|install|clean[-ppc|-x86|-x64]]"
   149         exit 1
   150         ;;
   151 esac
   152 case `uname -p` in
   153     *86)
   154         native_path=x86
   155         ;;
   156     *powerpc)
   157         native_path=ppc
   158         ;;
   159     x86_64)
   160         native_path=x64
   161         ;;
   162     *)
   163         echo "Couldn't figure out native architecture path"
   164         exit 1
   165         ;;
   166 esac
   167 
   168 #
   169 # Create the build directories
   170 #
   171 for dir in build build/ppc build/x86 build/x64; do
   172     if test -d $dir; then
   173         :
   174     else
   175         mkdir $dir || exit 1
   176     fi
   177 done
   178 
   179 
   180 #
   181 # Build the PowerPC 32-bit binary
   182 #
   183 if test x$configure_ppc = xyes; then
   184     (cd build/ppc && \
   185      sh ../../configure $BASE_CONFIG_FLAGS $CONFIG_PPC CC="$CC_PPC" CXX="$CXX_PPC" CFLAGS="$CFLAGS $BUILD_FLAGS_PPC $CFLAGS_PPC" LDFLAGS="$BUILD_FLAGS_PPC $LFLAGS_PPC") || exit 2
   186 fi
   187 if test x$make_ppc = xyes; then
   188     (cd build/ppc && make -j$NJOB) || exit 3
   189 fi
   190 #
   191 # Build the Intel 32-bit binary
   192 #
   193 if test x$configure_x86 = xyes; then
   194     (cd build/x86 && \
   195      sh ../../configure $BASE_CONFIG_FLAGS $CONFIG_X86 CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $BUILD_FLAGS_X86 $CFLAGS_X86" LDFLAGS="$BUILD_FLAGS_X86 $LFLAGS_X86") || exit 2
   196 fi
   197 if test x$make_x86 = xyes; then
   198     (cd build/x86 && make -j$NJOB) || exit 3
   199 fi
   200 
   201 #
   202 # Build the Intel 64-bit binary
   203 #
   204 if test x$configure_x64 = xyes; then
   205     (cd build/x64 && \
   206      sh ../../configure $BASE_CONFIG_FLAGS $CONFIG_X64 CC="$CC_X64" CXX="$CXX_X64" CFLAGS="$CFLAGS $BUILD_FLAGS_X64 $CFLAGS_X64" LDFLAGS="$BUILD_FLAGS_X64 $LFLAGS_X64") || exit 2
   207 fi
   208 if test x$make_x64 = xyes; then
   209     (cd build/x64 && make -j$NJOB) || exit 3
   210 fi
   211 
   212 #
   213 # Combine into fat binary
   214 #
   215 if test x$merge = xyes; then
   216     output=.libs
   217     sh $auxdir/mkinstalldirs build/$output
   218     cd build
   219     target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
   220     (lipo -create -o $output/$target `find . -mindepth 4 -maxdepth 4 -type f -name "*.dylib"` &&
   221      ln -sf $target $output/libSDL.dylib &&
   222      lipo -create -o $output/libSDL.a */build/.libs/libSDL.a &&
   223      cp $native_path/build/.libs/libSDL.la $output &&
   224      cp $native_path/build/.libs/libSDL.lai $output &&
   225      cp $native_path/build/libSDL.la . &&
   226      lipo -create -o $output/libSDLmain.a */build/.libs/libSDLmain.a &&
   227      cp $native_path/build/.libs/libSDLmain.la $output &&
   228      cp $native_path/build/.libs/libSDLmain.lai $output &&
   229      cp $native_path/build/libSDLmain.la . &&
   230      echo "Build complete!" &&
   231      echo "Files can be found in the build directory.") || exit 4
   232     cd ..
   233 fi
   234 
   235 #
   236 # Install
   237 #
   238 do_install()
   239 {
   240     echo $*
   241     $* || exit 5
   242 }
   243 if test x$prefix = x; then
   244     prefix=/usr/local
   245 fi
   246 if test x$exec_prefix = x; then
   247     exec_prefix=$prefix
   248 fi
   249 if test x$bindir = x; then
   250     bindir=$exec_prefix/bin
   251 fi
   252 if test x$libdir = x; then
   253     libdir=$exec_prefix/lib
   254 fi
   255 if test x$includedir = x; then
   256     includedir=$prefix/include
   257 fi
   258 if test x$datadir = x; then
   259     datadir=$prefix/share
   260 fi
   261 if test x$mandir = x; then
   262     mandir=$prefix/man
   263 fi
   264 if test x$install_bin = xyes; then
   265     do_install sh $auxdir/mkinstalldirs $bindir
   266     do_install /usr/bin/install -c -m 755 build/$native_path/sdl-config $bindir/sdl-config
   267 fi
   268 if test x$install_hdrs = xyes; then
   269     do_install sh $auxdir/mkinstalldirs $includedir/SDL
   270     for src in $srcdir/include/*.h; do \
   271         file=`echo $src | sed -e 's|^.*/||'`; \
   272         do_install /usr/bin/install -c -m 644 $src $includedir/SDL/$file; \
   273     done
   274     do_install /usr/bin/install -c -m 644 $srcdir/include/SDL_config_macosx.h $includedir/SDL/SDL_config.h
   275 fi
   276 if test x$install_lib = xyes; then
   277     do_install sh $auxdir/mkinstalldirs $libdir
   278     do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDL.la $libdir/libSDL.la
   279     do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDLmain.la $libdir/libSDLmain.la
   280 fi
   281 if test x$install_data = xyes; then
   282     do_install sh $auxdir/mkinstalldirs $datadir/aclocal
   283     do_install /usr/bin/install -c -m 644 $srcdir/sdl.m4 $datadir/aclocal/sdl.m4
   284     do_install sh $auxdir/mkinstalldirs $libdir/pkgconfig
   285     do_install /usr/bin/install -m 644 build/$native_path/sdl.pc $libdir/pkgconfig/sdl.pc
   286 fi
   287 if test x$install_man = xyes; then
   288     do_install sh $auxdir/mkinstalldirs $mandir/man3
   289     for src in $srcdir/docs/man3/*.3; do \
   290         file=`echo $src | sed -e 's|^.*/||'`; \
   291         do_install /usr/bin/install -c -m 644 $src $mandir/man3/$file; \
   292     done
   293 fi
   294 
   295 #
   296 # Clean up
   297 #
   298 do_clean()
   299 {
   300     echo $*
   301     $* || exit 6
   302 }
   303 if test x$clean_ppc = xyes; then
   304     do_clean rm -r build/ppc
   305 fi
   306 if test x$clean_x86 = xyes; then
   307     do_clean rm -r build/x86
   308 fi
   309 if test x$clean_x64 = xyes; then
   310     do_clean rm -r build/x64
   311 fi