build-scripts/fatbuild.sh
author Sam Lantinga <slouken@libsdl.org>
Sat, 26 Sep 2009 23:17:08 +0000
branchSDL-1.2
changeset 4246 8b8314cc34a6
parent 4148 3e7f2edce658
child 4371 6f74b80cca1d
permissions -rwxr-xr-x
Fixed bug #810

Lauri Kenttä 2009-09-26 06:42:23 PDT

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