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