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