2006-04-14 05:43:04 +00:00
#!/bin/sh
#
# Build a fat binary on Mac OS X, thanks Ryan!
2006-04-27 11:18:03 +00:00
# Number of CPUs (for make -j)
NCPU = ` sysctl -n hw.ncpu`
2009-12-05 19:46:24 +00:00
if test x$NJOB = x; then
NJOB = $NCPU
fi
2006-04-27 11:18:03 +00:00
# Generic, cross-platform CFLAGS you always want go here.
CFLAGS = "-O3 -g -pipe"
2009-09-05 10:39:18 +00:00
# We dynamically load X11, so using the system X11 headers is fine.
2011-09-19 01:49:29 -04:00
BASE_CONFIG_FLAGS = " --build=`uname -p`-apple-darwin \
2009-09-05 10:39:18 +00:00
--x-includes= /usr/X11R6/include --x-libraries= /usr/X11R6/lib"
2011-09-19 01:49:29 -04:00
# PowerPC 32-bit compiler flags
CONFIG_PPC = "--host=powerpc-apple-darwin"
CC_PPC = "gcc-4.0"
CXX_PPC = "g++-4.0"
BUILD_FLAGS_PPC = "-arch ppc -mmacosx-version-min=10.4"
2010-01-10 08:15:25 +00:00
2009-09-05 10:39:18 +00:00
# Intel 32-bit compiler flags
2011-09-19 01:49:29 -04:00
CONFIG_X86 = "--host=i386-apple-darwin"
CC_X86 = "gcc"
CXX_X86 = "g++"
BUILD_FLAGS_X86 = "-arch i386 -mmacosx-version-min=10.4"
2009-09-05 10:39:18 +00:00
# Intel 64-bit compiler flags
2011-09-19 01:49:29 -04:00
CONFIG_X64 = "--host=x86_64-apple-darwin"
CC_X64 = "gcc"
CXX_X64 = "g++"
BUILD_FLAGS_X64 = "-arch x86_64 -mmacosx-version-min=10.6"
2009-09-05 10:39:18 +00:00
2006-04-14 05:43:04 +00:00
#
# Find the configure script
#
2006-04-22 19:17:14 +00:00
srcdir = ` dirname $0 ` /..
2011-10-19 20:23:24 -04:00
srcdir = ` cd $srcdir && pwd `
2006-04-22 19:17:14 +00:00
auxdir = $srcdir /build-scripts
cd $srcdir
2006-04-14 05:43:04 +00:00
2011-09-19 01:49:29 -04:00
allow_ppc = "yes"
which gcc-4.0 >/dev/null 2>/dev/null
if [ " x $? " = "x1" ] ; then
#echo "WARNING: Can't find gcc-4.0, which means you don't have Xcode 3."
#echo "WARNING: Therefore, we can't do PowerPC support."
allow_ppc = "no"
fi
2006-04-14 05:43:04 +00:00
#
# Figure out which phase to build:
# all,
2011-09-19 01:49:29 -04:00
# configure, configure-ppc, configure-x86, configure-x64
# make, make-ppc, make-x86, make-x64, merge
2006-04-14 05:43:04 +00:00
# install
2006-04-27 11:18:03 +00:00
# clean
2006-04-14 05:43:04 +00:00
if test x" $1 " = x; then
phase = all
else
phase = " $1 "
fi
case $phase in
all)
2011-09-19 01:49:29 -04:00
configure_ppc = " $allow_ppc "
2006-04-14 05:43:04 +00:00
configure_x86 = "yes"
2009-09-05 10:39:18 +00:00
configure_x64 = "yes"
2011-09-19 01:49:29 -04:00
make_ppc = " $allow_ppc "
2006-04-14 05:43:04 +00:00
make_x86 = "yes"
2009-09-05 10:39:18 +00:00
make_x64 = "yes"
2006-04-14 05:43:04 +00:00
merge = "yes"
; ;
configure)
2011-09-19 01:49:29 -04:00
configure_ppc = " $allow_ppc "
2006-04-14 05:43:04 +00:00
configure_x86 = "yes"
2009-09-05 10:39:18 +00:00
configure_x64 = "yes"
2006-04-14 05:43:04 +00:00
; ;
2011-09-19 01:49:29 -04:00
configure-ppc)
configure_ppc = " $allow_ppc "
; ;
2006-04-14 05:43:04 +00:00
configure-x86)
configure_x86 = "yes"
; ;
2009-09-05 10:39:18 +00:00
configure-x64)
configure_x64 = "yes"
; ;
2006-04-14 05:43:04 +00:00
make)
2011-09-19 01:49:29 -04:00
make_ppc = " $allow_ppc "
2006-04-14 05:43:04 +00:00
make_x86 = "yes"
2009-09-05 10:39:18 +00:00
make_x64 = "yes"
2006-04-14 05:43:04 +00:00
merge = "yes"
; ;
2011-09-19 01:49:29 -04:00
make-ppc)
make_ppc = " $allow_ppc "
; ;
2006-04-14 05:43:04 +00:00
make-x86)
make_x86 = "yes"
; ;
2009-09-05 10:39:18 +00:00
make-x64)
make_x64 = "yes"
; ;
2006-04-14 05:43:04 +00:00
merge)
merge = "yes"
; ;
install)
2006-04-22 19:17:14 +00:00
install_bin = "yes"
install_hdrs = "yes"
install_lib = "yes"
install_data = "yes"
; ;
install-bin)
install_bin = "yes"
; ;
install-hdrs)
install_hdrs = "yes"
; ;
install-lib)
install_lib = "yes"
; ;
install-data)
install_data = "yes"
; ;
2006-04-27 11:18:03 +00:00
clean)
2011-09-19 01:49:29 -04:00
clean_ppc = "yes"
2006-04-27 11:18:03 +00:00
clean_x86 = "yes"
2009-09-05 10:39:18 +00:00
clean_x64 = "yes"
2006-04-27 11:18:03 +00:00
; ;
2011-09-19 01:49:29 -04:00
clean-ppc)
clean_ppc = "yes"
; ;
2006-04-27 11:18:03 +00:00
clean-x86)
clean_x86 = "yes"
; ;
2009-09-05 10:39:18 +00:00
clean-x64)
clean_x64 = "yes"
; ;
2006-04-22 19:17:14 +00:00
*)
2011-09-19 01:49:29 -04:00
echo " Usage: $0 [all|configure[-ppc|-x86|-x64]|make[-ppc|-x86|-x64]|merge|install|clean[-ppc|-x86|-x64]] "
2006-04-22 19:17:14 +00:00
exit 1
; ;
esac
case ` uname -p` in
*86)
native_path = x86
; ;
2011-09-19 01:49:29 -04:00
*powerpc)
native_path = ppc
; ;
2009-09-05 14:22:12 +00:00
x86_64)
native_path = x64
; ;
2006-04-22 19:17:14 +00:00
*)
echo "Couldn't figure out native architecture path"
exit 1
2006-04-14 05:43:04 +00:00
; ;
esac
#
# Create the build directories
#
2011-09-19 01:49:29 -04:00
for dir in build build/ppc build/x86 build/x64; do
2006-04-14 05:43:04 +00:00
if test -d $dir ; then
:
else
mkdir $dir || exit 1
fi
done
2011-09-19 01:49:29 -04:00
#
# Build the PowerPC 32-bit binary
#
if test x$configure_ppc = xyes; then
( cd build/ppc && \
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
fi
if test x$make_ppc = xyes; then
( cd build/ppc && make -j$NJOB ) || exit 3
fi
2009-09-05 10:39:18 +00:00
#
# Build the Intel 32-bit binary
2006-04-14 05:43:04 +00:00
#
if test x$configure_x86 = xyes; then
( cd build/x86 && \
2011-09-19 01:49:29 -04:00
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
2006-04-14 05:43:04 +00:00
fi
if test x$make_x86 = xyes; then
2006-04-28 05:38:06 +00:00
( cd build/x86 && make -j$NJOB ) || exit 3
2006-04-14 05:43:04 +00:00
fi
2009-09-05 10:39:18 +00:00
#
2011-09-19 01:49:29 -04:00
# Build the Intel 64-bit binary
2009-09-05 10:39:18 +00:00
#
if test x$configure_x64 = xyes; then
( cd build/x64 && \
2011-09-19 01:49:29 -04:00
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
2009-09-05 10:39:18 +00:00
fi
if test x$make_x64 = xyes; then
( cd build/x64 && make -j$NJOB ) || exit 3
fi
2006-04-14 05:43:04 +00:00
#
# Combine into fat binary
#
if test x$merge = xyes; then
2006-04-22 19:17:14 +00:00
output = .libs
sh $auxdir /mkinstalldirs build/$output
cd build
2009-09-05 09:51:39 +00:00
target = ` find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||' `
( lipo -create -o $output /$target ` find . -mindepth 4 -maxdepth 4 -type f -name "*.dylib" ` &&
2012-02-04 10:40:04 -05:00
ln -sf $target $output /libSDL2.dylib &&
lipo -create -o $output /libSDL2.a */build/.libs/libSDL2.a &&
cp $native_path /build/.libs/libSDL2.la $output &&
cp $native_path /build/.libs/libSDL2.lai $output &&
cp $native_path /build/libSDL2.la . &&
lipo -create -o libSDL2main.a */build/libSDL2main.a &&
2012-12-22 17:24:02 -08:00
lipo -create -o libSDL2_test.a */build/libSDL2_test.a &&
2006-04-14 05:43:04 +00:00
echo "Build complete!" &&
echo "Files can be found in the build directory." ) || exit 4
2006-04-22 19:17:14 +00:00
cd ..
2006-04-14 05:43:04 +00:00
fi
#
# Install
#
2006-04-22 19:17:14 +00:00
do_install( )
{
echo $*
$* || exit 5
}
if test x$prefix = x; then
prefix = /usr/local
fi
if test x$exec_prefix = x; then
exec_prefix = $prefix
fi
if test x$bindir = x; then
bindir = $exec_prefix /bin
fi
if test x$libdir = x; then
libdir = $exec_prefix /lib
fi
if test x$includedir = x; then
includedir = $prefix /include
fi
if test x$datadir = x; then
datadir = $prefix /share
fi
if test x$mandir = x; then
mandir = $prefix /man
fi
if test x$install_bin = xyes; then
do_install sh $auxdir /mkinstalldirs $bindir
2012-02-04 10:40:04 -05:00
do_install /usr/bin/install -c -m 755 build/$native_path /sdl2-config $bindir /sdl2-config
2006-04-22 19:17:14 +00:00
fi
if test x$install_hdrs = xyes; then
2012-02-04 10:40:04 -05:00
do_install sh $auxdir /mkinstalldirs $includedir /SDL2
2006-04-22 19:17:14 +00:00
for src in $srcdir /include/*.h; do \
file = ` echo $src | sed -e 's|^.*/||' ` ; \
2012-02-04 10:40:04 -05:00
do_install /usr/bin/install -c -m 644 $src $includedir /SDL2/$file ; \
2006-04-22 19:17:14 +00:00
done
2012-02-04 10:40:04 -05:00
do_install /usr/bin/install -c -m 644 $srcdir /include/SDL_config_macosx.h $includedir /SDL2/SDL_config.h
2006-04-22 19:17:14 +00:00
fi
if test x$install_lib = xyes; then
do_install sh $auxdir /mkinstalldirs $libdir
2012-02-04 10:40:04 -05:00
do_install sh build/$native_path /libtool --mode= install /usr/bin/install -c build/libSDL2.la $libdir /libSDL2.la
do_install /usr/bin/install -c -m 644 build/libSDL2main.a $libdir /libSDL2main.a
do_install ranlib $libdir /libSDL2main.a
2012-12-22 17:24:02 -08:00
do_install /usr/bin/install -c -m 644 build/libSDL2_test.a $libdir /libSDL2_test.a
do_install ranlib $libdir /libSDL2_test.a
2006-04-22 19:17:14 +00:00
fi
if test x$install_data = xyes; then
do_install sh $auxdir /mkinstalldirs $datadir /aclocal
2012-02-04 10:40:04 -05:00
do_install /usr/bin/install -c -m 644 $srcdir /sdl2.m4 $datadir /aclocal/sdl2.m4
2006-04-22 19:17:14 +00:00
fi
2006-04-27 11:18:03 +00:00
#
# Clean up
#
do_clean( )
{
echo $*
$* || exit 6
}
2011-09-19 01:49:29 -04:00
if test x$clean_ppc = xyes; then
do_clean rm -r build/ppc
fi
2006-04-27 11:18:03 +00:00
if test x$clean_x86 = xyes; then
do_clean rm -r build/x86
fi
2011-08-14 17:21:21 -04:00
if test x$clean_x64 = xyes; then
do_clean rm -r build/x64
2006-04-27 11:18:03 +00:00
fi