build-scripts/fatbuild.sh
author Sam Lantinga <slouken@libsdl.org>
Sun, 14 Aug 2011 17:17:17 -0400
branchSDL-1.2
changeset 5608 2bee7f46cb2b
parent 4397 fb1fc6c9289e
child 5610 e55f9d0e117a
permissions -rwxr-xr-x
Fat build doesn't support PPC anymore.
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
slouken@5608
    30
GCCUSRPATH_X64=`ls -d $SDK_PATH/MacOSX10.5.sdk/usr/lib/gcc/i686-apple-darwin*/4.0.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
slouken@5608
    52
# Intel 64-bit configure flags (10.5 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
slouken@5608
    58
CC_X64="gcc-4.0 -arch x86_64"
slouken@5608
    59
CXX_X64="g++-4.0 -arch x86_64"
slouken@5608
    60
CFLAGS_X64="-mmacosx-version-min=10.5"
slouken@5608
    61
CPPFLAGS_X64="-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
slouken@5608
    62
-nostdinc \
slouken@5608
    63
-F$SDK_PATH/MacOSX10.5.sdk/System/Library/Frameworks \
slouken@5608
    64
-I$GCCUSRPATH_X64/include \
slouken@5608
    65
-isystem $SDK_PATH/MacOSX10.5.sdk/usr/include"
slouken@5608
    66
slouken@5608
    67
# Intel 64-bit linker flags
slouken@5608
    68
LFLAGS_X64="-arch x86_64 -Wl,-headerpad_max_install_names -mmacosx-version-min=10.5 \
slouken@5608
    69
-F$SDK_PATH/MacOSX10.5.sdk/System/Library/Frameworks \
slouken@5608
    70
-L$GCCUSRPATH_X64/x86_64 \
slouken@5608
    71
-Wl,-syslibroot,$SDK_PATH/MacOSX10.5.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@5608
    83
# configure, configure-ppc, configure-ppc64, configure-x86, configure-x64
slouken@5608
    84
# make, make-ppc, make-ppc64, 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_ppc="yes"
slouken@5608
    95
        configure_ppc64="yes"
slouken@1636
    96
        configure_x86="yes"
slouken@5608
    97
        configure_x64="yes"
slouken@1636
    98
        make_ppc="yes"
slouken@5608
    99
        make_ppc64="yes"
slouken@1636
   100
        make_x86="yes"
slouken@5608
   101
        make_x64="yes"
slouken@1636
   102
        merge="yes"
slouken@1636
   103
        ;;
slouken@1636
   104
    configure)
slouken@1636
   105
        configure_ppc="yes"
slouken@5608
   106
        configure_ppc64="yes"
slouken@1636
   107
        configure_x86="yes"
slouken@5608
   108
        configure_x64="yes"
slouken@1636
   109
        ;;
slouken@1636
   110
    configure-ppc)
slouken@1636
   111
        configure_ppc="yes"
slouken@1636
   112
        ;;
slouken@5608
   113
    configure-ppc64)
slouken@5608
   114
        configure_ppc64="yes"
slouken@5608
   115
        ;;
slouken@1636
   116
    configure-x86)
slouken@1636
   117
        configure_x86="yes"
slouken@1636
   118
        ;;
slouken@5608
   119
    configure-x64)
slouken@5608
   120
        configure_x64="yes"
slouken@5608
   121
        ;;
slouken@1636
   122
    make)
slouken@1636
   123
        make_ppc="yes"
slouken@5608
   124
        make_ppc64="yes"
slouken@1636
   125
        make_x86="yes"
slouken@5608
   126
        make_x64="yes"
slouken@1636
   127
        merge="yes"
slouken@1636
   128
        ;;
slouken@1636
   129
    make-ppc)
slouken@1636
   130
        make_ppc="yes"
slouken@1636
   131
        ;;
slouken@5608
   132
    make-ppc64)
slouken@5608
   133
        make_ppc64="yes"
slouken@5608
   134
        ;;
slouken@1636
   135
    make-x86)
slouken@1636
   136
        make_x86="yes"
slouken@1636
   137
        ;;
slouken@5608
   138
    make-x64)
slouken@5608
   139
        make_x64="yes"
slouken@5608
   140
        ;;
slouken@1636
   141
    merge)
slouken@1636
   142
        merge="yes"
slouken@1636
   143
        ;;
slouken@1636
   144
    install)
slouken@1648
   145
        install_bin="yes"
slouken@1648
   146
        install_hdrs="yes"
slouken@1648
   147
        install_lib="yes"
slouken@1648
   148
        install_data="yes"
slouken@1648
   149
        install_man="yes"
slouken@1648
   150
        ;;
slouken@1648
   151
    install-bin)
slouken@1648
   152
        install_bin="yes"
slouken@1648
   153
        ;;
slouken@1648
   154
    install-hdrs)
slouken@1648
   155
        install_hdrs="yes"
slouken@1648
   156
        ;;
slouken@1648
   157
    install-lib)
slouken@1648
   158
        install_lib="yes"
slouken@1648
   159
        ;;
slouken@1648
   160
    install-data)
slouken@1648
   161
        install_data="yes"
slouken@1648
   162
        ;;
slouken@1648
   163
    install-man)
slouken@1648
   164
        install_man="yes"
slouken@1648
   165
        ;;
icculus@1741
   166
    clean)
icculus@1741
   167
        clean_ppc="yes"
slouken@5608
   168
        clean_ppc64="yes"
icculus@1741
   169
        clean_x86="yes"
slouken@5608
   170
        clean_x64="yes"
icculus@1741
   171
        ;;
icculus@1741
   172
    clean-ppc)
icculus@1741
   173
        clean_ppc="yes"
icculus@1741
   174
        ;;
slouken@5608
   175
    clean-ppc64)
slouken@5608
   176
        clean_ppc64="yes"
slouken@5608
   177
        ;;
icculus@1741
   178
    clean-x86)
icculus@1741
   179
        clean_x86="yes"
icculus@1741
   180
        ;;
slouken@5608
   181
    clean-x64)
slouken@5608
   182
        clean_x64="yes"
slouken@5608
   183
        ;;
slouken@1648
   184
    *)
slouken@5608
   185
        echo "Usage: $0 [all|configure[-ppc|-ppc64|-x86|-x64]|make[-ppc|-ppc64|-x86|-x64]|merge|install|clean[-ppc|-ppc64|-x86|-x64]]"
slouken@1648
   186
        exit 1
slouken@1648
   187
        ;;
slouken@1648
   188
esac
slouken@1648
   189
case `uname -p` in
slouken@1648
   190
    powerpc)
slouken@1648
   191
        native_path=ppc
slouken@1648
   192
        ;;
slouken@5608
   193
    powerpc64)
slouken@5608
   194
        native_path=ppc64
slouken@5608
   195
        ;;
slouken@1648
   196
    *86)
slouken@1648
   197
        native_path=x86
slouken@1648
   198
        ;;
slouken@5608
   199
    x86_64)
slouken@5608
   200
        native_path=x64
slouken@5608
   201
        ;;
slouken@1648
   202
    *)
slouken@1648
   203
        echo "Couldn't figure out native architecture path"
slouken@1648
   204
        exit 1
slouken@1636
   205
        ;;
slouken@1636
   206
esac
slouken@1636
   207
slouken@1636
   208
#
slouken@1636
   209
# Create the build directories
slouken@1636
   210
#
slouken@5608
   211
for dir in build build/ppc build/ppc64 build/x86 build/x64; do
slouken@1636
   212
    if test -d $dir; then
slouken@1636
   213
        :
slouken@1636
   214
    else
slouken@1636
   215
        mkdir $dir || exit 1
slouken@1636
   216
    fi
slouken@1636
   217
done
slouken@1636
   218
slouken@1636
   219
#
slouken@5608
   220
# Build the Intel 32-bit binary
slouken@1636
   221
#
slouken@1636
   222
if test x$configure_x86 = xyes; then
slouken@1636
   223
    (cd build/x86 && \
slouken@1799
   224
     sh ../../configure $CONFIG_X86 CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $CFLAGS_X86" CPPFLAGS="$CPPFLAGS_X86" LDFLAGS="$LFLAGS_X86") || exit 2
slouken@1636
   225
fi
slouken@1636
   226
if test x$make_x86 = xyes; then
slouken@1742
   227
    (cd build/x86 && make -j$NJOB) || exit 3
slouken@1636
   228
fi
slouken@1636
   229
slouken@1636
   230
#
slouken@5608
   231
# Build the Intel 32-bit binary
slouken@5608
   232
#
slouken@5608
   233
if test x$configure_x64 = xyes; then
slouken@5608
   234
    (cd build/x64 && \
slouken@5608
   235
     sh ../../configure $CONFIG_X64 CC="$CC_X64" CXX="$CXX_X64" CFLAGS="$CFLAGS $CFLAGS_X64" CPPFLAGS="$CPPFLAGS_X64" LDFLAGS="$LFLAGS_X64") || exit 2
slouken@5608
   236
fi
slouken@5608
   237
if test x$make_x64 = xyes; then
slouken@5608
   238
    (cd build/x64 && make -j$NJOB) || exit 3
slouken@5608
   239
fi
slouken@5608
   240
slouken@5608
   241
#
slouken@1636
   242
# Combine into fat binary
slouken@1636
   243
#
slouken@1636
   244
if test x$merge = xyes; then
slouken@1648
   245
    output=.libs
slouken@1648
   246
    sh $auxdir/mkinstalldirs build/$output
slouken@1648
   247
    cd build
slouken@5608
   248
    target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
slouken@5608
   249
    (lipo -create -o $output/$target `find . -mindepth 4 -maxdepth 4 -type f -name "*.dylib"` &&
slouken@1648
   250
     ln -sf $target $output/libSDL.dylib &&
slouken@1648
   251
     lipo -create -o $output/libSDL.a */build/.libs/libSDL.a &&
slouken@1648
   252
     cp $native_path/build/.libs/libSDL.la $output &&
slouken@1648
   253
     cp $native_path/build/.libs/libSDL.lai $output &&
slouken@1648
   254
     cp $native_path/build/libSDL.la . &&
slouken@1648
   255
     lipo -create -o libSDLmain.a */build/libSDLmain.a &&
slouken@1636
   256
     echo "Build complete!" &&
slouken@1636
   257
     echo "Files can be found in the build directory.") || exit 4
slouken@1648
   258
    cd ..
slouken@1636
   259
fi
slouken@1636
   260
slouken@1636
   261
#
slouken@1636
   262
# Install
slouken@1636
   263
#
slouken@1648
   264
do_install()
slouken@1648
   265
{
slouken@1648
   266
    echo $*
slouken@1648
   267
    $* || exit 5
slouken@1648
   268
}
slouken@1648
   269
if test x$prefix = x; then
slouken@1648
   270
    prefix=/usr/local
slouken@1648
   271
fi
slouken@1648
   272
if test x$exec_prefix = x; then
slouken@1648
   273
    exec_prefix=$prefix
slouken@1648
   274
fi
slouken@1648
   275
if test x$bindir = x; then
slouken@1648
   276
    bindir=$exec_prefix/bin
slouken@1648
   277
fi
slouken@1648
   278
if test x$libdir = x; then
slouken@1648
   279
    libdir=$exec_prefix/lib
slouken@1648
   280
fi
slouken@1648
   281
if test x$includedir = x; then
slouken@1648
   282
    includedir=$prefix/include
slouken@1648
   283
fi
slouken@1648
   284
if test x$datadir = x; then
slouken@1648
   285
    datadir=$prefix/share
slouken@1648
   286
fi
slouken@1648
   287
if test x$mandir = x; then
slouken@1648
   288
    mandir=$prefix/man
slouken@1636
   289
fi
slouken@1648
   290
if test x$install_bin = xyes; then
slouken@1648
   291
    do_install sh $auxdir/mkinstalldirs $bindir
slouken@1648
   292
    do_install /usr/bin/install -c -m 755 build/$native_path/sdl-config $bindir/sdl-config
slouken@1648
   293
fi
slouken@1648
   294
if test x$install_hdrs = xyes; then
slouken@1648
   295
    do_install sh $auxdir/mkinstalldirs $includedir/SDL
slouken@1648
   296
    for src in $srcdir/include/*.h; do \
slouken@1648
   297
        file=`echo $src | sed -e 's|^.*/||'`; \
slouken@1648
   298
        do_install /usr/bin/install -c -m 644 $src $includedir/SDL/$file; \
slouken@1648
   299
    done
slouken@1648
   300
    do_install /usr/bin/install -c -m 644 $srcdir/include/SDL_config_macosx.h $includedir/SDL/SDL_config.h
slouken@1648
   301
fi
slouken@1648
   302
if test x$install_lib = xyes; then
slouken@1648
   303
    do_install sh $auxdir/mkinstalldirs $libdir
slouken@1648
   304
    do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDL.la $libdir/libSDL.la
slouken@1648
   305
    do_install /usr/bin/install -c -m 644 build/libSDLmain.a $libdir/libSDLmain.a
slouken@1648
   306
    do_install ranlib $libdir/libSDLmain.a
slouken@1648
   307
fi
slouken@1648
   308
if test x$install_data = xyes; then
slouken@1648
   309
    do_install sh $auxdir/mkinstalldirs $datadir/aclocal
slouken@1648
   310
    do_install /usr/bin/install -c -m 644 $srcdir/sdl.m4 $datadir/aclocal/sdl.m4
slouken@1648
   311
fi
slouken@1648
   312
if test x$install_man = xyes; then
slouken@1648
   313
    do_install sh $auxdir/mkinstalldirs $mandir/man3
slouken@1648
   314
    for src in $srcdir/docs/man3/*.3; do \
slouken@1648
   315
        file=`echo $src | sed -e 's|^.*/||'`; \
slouken@1648
   316
        do_install /usr/bin/install -c -m 644 $src $mandir/man3/$file; \
slouken@1648
   317
    done
slouken@1648
   318
fi
icculus@1741
   319
icculus@1741
   320
#
icculus@1741
   321
# Clean up
icculus@1741
   322
#
icculus@1741
   323
do_clean()
icculus@1741
   324
{
icculus@1741
   325
    echo $*
icculus@1741
   326
    $* || exit 6
icculus@1741
   327
}
icculus@1741
   328
if test x$clean_x86 = xyes; then
icculus@1741
   329
    do_clean rm -r build/x86
icculus@1741
   330
fi
icculus@1741
   331
if test x$clean_ppc = xyes; then
icculus@1741
   332
    do_clean rm -r build/ppc
icculus@1741
   333
fi
icculus@1741
   334