build-scripts/fatbuild.sh
author Ryan C. Gordon <icculus@icculus.org>
Fri, 16 Sep 2011 00:46:59 -0400
branchSDL-1.2
changeset 5944 f5c4ce6a2f67
parent 5610 e55f9d0e117a
child 5960 eb025734b5a1
permissions -rwxr-xr-x
Make build-scripts/fatbuild.sh sane for x86-64.

No one targets 10.5 or uses gcc 4.0 with x86-64 Mac OS X.
slouken@1636
     1
#!/bin/sh
slouken@1636
     2
#
slouken@1636
     3
# Build a fat binary on Mac OS X, thanks Ryan!
slouken@1636
     4
icculus@1741
     5
# Number of CPUs (for make -j)
icculus@1741
     6
NCPU=`sysctl -n hw.ncpu`
slouken@5608
     7
if test x$NJOB = x; then
slouken@5608
     8
    NJOB=$NCPU
slouken@5608
     9
fi
slouken@5608
    10
slouken@5608
    11
# SDK path
slouken@5608
    12
if test x$SDK_PATH = x; then
slouken@5608
    13
    SDK_PATH=/Developer/SDKs
slouken@5608
    14
fi
icculus@1741
    15
icculus@1741
    16
# Generic, cross-platform CFLAGS you always want go here.
icculus@1741
    17
CFLAGS="-O3 -g -pipe"
icculus@1741
    18
slouken@5608
    19
# Intel 32-bit configure flags (10.4 runtime compatibility)
slouken@1799
    20
# We dynamically load X11, so using the system X11 headers is fine.
slouken@1799
    21
CONFIG_X86="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
slouken@1799
    22
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
slouken@1799
    23
slouken@5608
    24
# They changed this from "darwin9" to "darwin10" in Xcode 3.2 (Snow Leopard).
slouken@5608
    25
GCCUSRPATH_X86=`ls -d $SDK_PATH/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin*/4.0.1`
slouken@5608
    26
if [ ! -d "$GCCUSRPATH_X86" ]; then
slouken@5608
    27
    echo "Couldn't find any GCC usr path for 32-bit x86"
slouken@5608
    28
    exit 1
icculus@4397
    29
fi
icculus@5944
    30
GCCUSRPATH_X64=`ls -d $SDK_PATH/MacOSX10.6.sdk/usr/lib/gcc/i686-apple-darwin*/4.2.1`
slouken@5608
    31
if [ ! -d "$GCCUSRPATH_X64" ]; then
slouken@5608
    32
    echo "Couldn't find any GCC usr path for 64-bit x86"
icculus@4397
    33
    exit 1
icculus@4397
    34
fi
icculus@4397
    35
slouken@5608
    36
# Intel 32-bit compiler flags
slouken@1739
    37
CC_X86="gcc-4.0 -arch i386"
slouken@1743
    38
CXX_X86="g++-4.0 -arch i386"
slouken@1739
    39
CFLAGS_X86="-mmacosx-version-min=10.4"
slouken@1648
    40
CPPFLAGS_X86="-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
slouken@1742
    41
-nostdinc \
icculus@4397
    42
-F$SDK_PATH/MacOSX10.4u.sdk/System/Library/Frameworks \
slouken@5608
    43
-I$GCCUSRPATH_X86/include \
icculus@4397
    44
-isystem $SDK_PATH/MacOSX10.4u.sdk/usr/include"
slouken@1636
    45
slouken@5608
    46
# Intel 32-bit linker flags
slouken@5608
    47
LFLAGS_X86="-arch i386 -Wl,-headerpad_max_install_names -mmacosx-version-min=10.4 \
slouken@5608
    48
-F$SDK_PATH/MacOSX10.4u.sdk/System/Library/Frameworks \
slouken@5608
    49
-L$GCCUSRPATH_X86 \
icculus@4397
    50
-Wl,-syslibroot,$SDK_PATH/MacOSX10.4u.sdk"
slouken@1636
    51
icculus@5944
    52
# Intel 64-bit configure flags (10.6 runtime compatibility)
slouken@5608
    53
# We dynamically load X11, so using the system X11 headers is fine.
slouken@5608
    54
CONFIG_X64="--build=`uname -p`-apple-darwin --host=i386-apple-darwin \
slouken@5608
    55
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
slouken@5608
    56
slouken@5608
    57
# Intel 64-bit compiler flags
icculus@5944
    58
CC_X64="gcc-4.2 -arch x86_64"
icculus@5944
    59
CXX_X64="g++-4.2 -arch x86_64"
icculus@5944
    60
CFLAGS_X64="-mmacosx-version-min=10.6"
icculus@5944
    61
CPPFLAGS_X64="-DMAC_OS_X_VERSION_MIN_REQUIRED=1060 \
slouken@5608
    62
-nostdinc \
icculus@5944
    63
-F$SDK_PATH/MacOSX10.6.sdk/System/Library/Frameworks \
slouken@5608
    64
-I$GCCUSRPATH_X64/include \
icculus@5944
    65
-isystem $SDK_PATH/MacOSX10.6.sdk/usr/include"
slouken@5608
    66
slouken@5608
    67
# Intel 64-bit linker flags
icculus@5944
    68
LFLAGS_X64="-arch x86_64 -Wl,-headerpad_max_install_names -mmacosx-version-min=10.6 \
icculus@5944
    69
-F$SDK_PATH/MacOSX10.6.sdk/System/Library/Frameworks \
slouken@5608
    70
-L$GCCUSRPATH_X64/x86_64 \
icculus@5944
    71
-Wl,-syslibroot,$SDK_PATH/MacOSX10.6.sdk"
slouken@5608
    72
slouken@1636
    73
#
slouken@1636
    74
# Find the configure script
slouken@1636
    75
#
slouken@1648
    76
srcdir=`dirname $0`/..
slouken@1648
    77
auxdir=$srcdir/build-scripts
slouken@1648
    78
cd $srcdir
slouken@1636
    79
slouken@1636
    80
#
slouken@1636
    81
# Figure out which phase to build:
slouken@1636
    82
# all,
slouken@5610
    83
# configure, configure-x86, configure-x64
slouken@5610
    84
# make, make-x86, make-x64, merge
slouken@1636
    85
# install
icculus@1741
    86
# clean
slouken@1636
    87
if test x"$1" = x; then
slouken@1636
    88
    phase=all
slouken@1636
    89
else
slouken@1636
    90
    phase="$1"
slouken@1636
    91
fi
slouken@1636
    92
case $phase in
slouken@1636
    93
    all)
slouken@1636
    94
        configure_x86="yes"
slouken@5608
    95
        configure_x64="yes"
slouken@1636
    96
        make_x86="yes"
slouken@5608
    97
        make_x64="yes"
slouken@1636
    98
        merge="yes"
slouken@1636
    99
        ;;
slouken@1636
   100
    configure)
slouken@1636
   101
        configure_x86="yes"
slouken@5608
   102
        configure_x64="yes"
slouken@1636
   103
        ;;
slouken@1636
   104
    configure-x86)
slouken@1636
   105
        configure_x86="yes"
slouken@1636
   106
        ;;
slouken@5608
   107
    configure-x64)
slouken@5608
   108
        configure_x64="yes"
slouken@5608
   109
        ;;
slouken@1636
   110
    make)
slouken@1636
   111
        make_x86="yes"
slouken@5608
   112
        make_x64="yes"
slouken@1636
   113
        merge="yes"
slouken@1636
   114
        ;;
slouken@1636
   115
    make-x86)
slouken@1636
   116
        make_x86="yes"
slouken@1636
   117
        ;;
slouken@5608
   118
    make-x64)
slouken@5608
   119
        make_x64="yes"
slouken@5608
   120
        ;;
slouken@1636
   121
    merge)
slouken@1636
   122
        merge="yes"
slouken@1636
   123
        ;;
slouken@1636
   124
    install)
slouken@1648
   125
        install_bin="yes"
slouken@1648
   126
        install_hdrs="yes"
slouken@1648
   127
        install_lib="yes"
slouken@1648
   128
        install_data="yes"
slouken@1648
   129
        install_man="yes"
slouken@1648
   130
        ;;
slouken@1648
   131
    install-bin)
slouken@1648
   132
        install_bin="yes"
slouken@1648
   133
        ;;
slouken@1648
   134
    install-hdrs)
slouken@1648
   135
        install_hdrs="yes"
slouken@1648
   136
        ;;
slouken@1648
   137
    install-lib)
slouken@1648
   138
        install_lib="yes"
slouken@1648
   139
        ;;
slouken@1648
   140
    install-data)
slouken@1648
   141
        install_data="yes"
slouken@1648
   142
        ;;
slouken@1648
   143
    install-man)
slouken@1648
   144
        install_man="yes"
slouken@1648
   145
        ;;
icculus@1741
   146
    clean)
icculus@1741
   147
        clean_x86="yes"
slouken@5608
   148
        clean_x64="yes"
icculus@1741
   149
        ;;
icculus@1741
   150
    clean-x86)
icculus@1741
   151
        clean_x86="yes"
icculus@1741
   152
        ;;
slouken@5608
   153
    clean-x64)
slouken@5608
   154
        clean_x64="yes"
slouken@5608
   155
        ;;
slouken@1648
   156
    *)
slouken@5610
   157
        echo "Usage: $0 [all|configure[-x86|-x64]|make[-x86|-x64]|merge|install|clean[-x86|-x64]]"
slouken@1648
   158
        exit 1
slouken@1648
   159
        ;;
slouken@1648
   160
esac
slouken@1648
   161
case `uname -p` in
slouken@1648
   162
    *86)
slouken@1648
   163
        native_path=x86
slouken@1648
   164
        ;;
slouken@5608
   165
    x86_64)
slouken@5608
   166
        native_path=x64
slouken@5608
   167
        ;;
slouken@1648
   168
    *)
slouken@1648
   169
        echo "Couldn't figure out native architecture path"
slouken@1648
   170
        exit 1
slouken@1636
   171
        ;;
slouken@1636
   172
esac
slouken@1636
   173
slouken@1636
   174
#
slouken@1636
   175
# Create the build directories
slouken@1636
   176
#
slouken@5610
   177
for dir in build build/x86 build/x64; do
slouken@1636
   178
    if test -d $dir; then
slouken@1636
   179
        :
slouken@1636
   180
    else
slouken@1636
   181
        mkdir $dir || exit 1
slouken@1636
   182
    fi
slouken@1636
   183
done
slouken@1636
   184
slouken@1636
   185
#
slouken@5608
   186
# Build the Intel 32-bit binary
slouken@1636
   187
#
slouken@1636
   188
if test x$configure_x86 = xyes; then
slouken@1636
   189
    (cd build/x86 && \
slouken@1799
   190
     sh ../../configure $CONFIG_X86 CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $CFLAGS_X86" CPPFLAGS="$CPPFLAGS_X86" LDFLAGS="$LFLAGS_X86") || exit 2
slouken@1636
   191
fi
slouken@1636
   192
if test x$make_x86 = xyes; then
slouken@1742
   193
    (cd build/x86 && make -j$NJOB) || exit 3
slouken@1636
   194
fi
slouken@1636
   195
slouken@1636
   196
#
slouken@5608
   197
# Build the Intel 32-bit binary
slouken@5608
   198
#
slouken@5608
   199
if test x$configure_x64 = xyes; then
slouken@5608
   200
    (cd build/x64 && \
slouken@5608
   201
     sh ../../configure $CONFIG_X64 CC="$CC_X64" CXX="$CXX_X64" CFLAGS="$CFLAGS $CFLAGS_X64" CPPFLAGS="$CPPFLAGS_X64" LDFLAGS="$LFLAGS_X64") || exit 2
slouken@5608
   202
fi
slouken@5608
   203
if test x$make_x64 = xyes; then
slouken@5608
   204
    (cd build/x64 && make -j$NJOB) || exit 3
slouken@5608
   205
fi
slouken@5608
   206
slouken@5608
   207
#
slouken@1636
   208
# Combine into fat binary
slouken@1636
   209
#
slouken@1636
   210
if test x$merge = xyes; then
slouken@1648
   211
    output=.libs
slouken@1648
   212
    sh $auxdir/mkinstalldirs build/$output
slouken@1648
   213
    cd build
slouken@5608
   214
    target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
slouken@5608
   215
    (lipo -create -o $output/$target `find . -mindepth 4 -maxdepth 4 -type f -name "*.dylib"` &&
slouken@1648
   216
     ln -sf $target $output/libSDL.dylib &&
slouken@1648
   217
     lipo -create -o $output/libSDL.a */build/.libs/libSDL.a &&
slouken@1648
   218
     cp $native_path/build/.libs/libSDL.la $output &&
slouken@1648
   219
     cp $native_path/build/.libs/libSDL.lai $output &&
slouken@1648
   220
     cp $native_path/build/libSDL.la . &&
slouken@1648
   221
     lipo -create -o libSDLmain.a */build/libSDLmain.a &&
slouken@1636
   222
     echo "Build complete!" &&
slouken@1636
   223
     echo "Files can be found in the build directory.") || exit 4
slouken@1648
   224
    cd ..
slouken@1636
   225
fi
slouken@1636
   226
slouken@1636
   227
#
slouken@1636
   228
# Install
slouken@1636
   229
#
slouken@1648
   230
do_install()
slouken@1648
   231
{
slouken@1648
   232
    echo $*
slouken@1648
   233
    $* || exit 5
slouken@1648
   234
}
slouken@1648
   235
if test x$prefix = x; then
slouken@1648
   236
    prefix=/usr/local
slouken@1648
   237
fi
slouken@1648
   238
if test x$exec_prefix = x; then
slouken@1648
   239
    exec_prefix=$prefix
slouken@1648
   240
fi
slouken@1648
   241
if test x$bindir = x; then
slouken@1648
   242
    bindir=$exec_prefix/bin
slouken@1648
   243
fi
slouken@1648
   244
if test x$libdir = x; then
slouken@1648
   245
    libdir=$exec_prefix/lib
slouken@1648
   246
fi
slouken@1648
   247
if test x$includedir = x; then
slouken@1648
   248
    includedir=$prefix/include
slouken@1648
   249
fi
slouken@1648
   250
if test x$datadir = x; then
slouken@1648
   251
    datadir=$prefix/share
slouken@1648
   252
fi
slouken@1648
   253
if test x$mandir = x; then
slouken@1648
   254
    mandir=$prefix/man
slouken@1636
   255
fi
slouken@1648
   256
if test x$install_bin = xyes; then
slouken@1648
   257
    do_install sh $auxdir/mkinstalldirs $bindir
slouken@1648
   258
    do_install /usr/bin/install -c -m 755 build/$native_path/sdl-config $bindir/sdl-config
slouken@1648
   259
fi
slouken@1648
   260
if test x$install_hdrs = xyes; then
slouken@1648
   261
    do_install sh $auxdir/mkinstalldirs $includedir/SDL
slouken@1648
   262
    for src in $srcdir/include/*.h; do \
slouken@1648
   263
        file=`echo $src | sed -e 's|^.*/||'`; \
slouken@1648
   264
        do_install /usr/bin/install -c -m 644 $src $includedir/SDL/$file; \
slouken@1648
   265
    done
slouken@1648
   266
    do_install /usr/bin/install -c -m 644 $srcdir/include/SDL_config_macosx.h $includedir/SDL/SDL_config.h
slouken@1648
   267
fi
slouken@1648
   268
if test x$install_lib = xyes; then
slouken@1648
   269
    do_install sh $auxdir/mkinstalldirs $libdir
slouken@1648
   270
    do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDL.la $libdir/libSDL.la
slouken@1648
   271
    do_install /usr/bin/install -c -m 644 build/libSDLmain.a $libdir/libSDLmain.a
slouken@1648
   272
    do_install ranlib $libdir/libSDLmain.a
slouken@1648
   273
fi
slouken@1648
   274
if test x$install_data = xyes; then
slouken@1648
   275
    do_install sh $auxdir/mkinstalldirs $datadir/aclocal
slouken@1648
   276
    do_install /usr/bin/install -c -m 644 $srcdir/sdl.m4 $datadir/aclocal/sdl.m4
slouken@1648
   277
fi
slouken@1648
   278
if test x$install_man = xyes; then
slouken@1648
   279
    do_install sh $auxdir/mkinstalldirs $mandir/man3
slouken@1648
   280
    for src in $srcdir/docs/man3/*.3; do \
slouken@1648
   281
        file=`echo $src | sed -e 's|^.*/||'`; \
slouken@1648
   282
        do_install /usr/bin/install -c -m 644 $src $mandir/man3/$file; \
slouken@1648
   283
    done
slouken@1648
   284
fi
icculus@1741
   285
icculus@1741
   286
#
icculus@1741
   287
# Clean up
icculus@1741
   288
#
icculus@1741
   289
do_clean()
icculus@1741
   290
{
icculus@1741
   291
    echo $*
icculus@1741
   292
    $* || exit 6
icculus@1741
   293
}
icculus@1741
   294
if test x$clean_x86 = xyes; then
icculus@1741
   295
    do_clean rm -r build/x86
icculus@1741
   296
fi
slouken@5610
   297
if test x$clean_x64 = xyes; then
slouken@5610
   298
    do_clean rm -r build/x64
icculus@1741
   299
fi