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