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