build-scripts/fatbuild.sh
author Ryan C. Gordon <icculus@icculus.org>
Mon, 19 Sep 2011 01:49:29 -0400
changeset 5961 3bd7ed5f3895
parent 5611 d20007078cd1
child 6016 196ab3642a3f
permissions -rwxr-xr-x
Updated fatbuild.sh to match 1.2 version.
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
slouken@4924
    11
# SDK path
slouken@4924
    12
if test x$SDK_PATH = x; then
slouken@4924
    13
    SDK_PATH=/Developer/SDKs
slouken@4924
    14
fi
slouken@4924
    15
icculus@1741
    16
# Generic, cross-platform CFLAGS you always want go here.
icculus@1741
    17
CFLAGS="-O3 -g -pipe"
icculus@1741
    18
slouken@1799
    19
# We dynamically load X11, so using the system X11 headers is fine.
icculus@5961
    20
BASE_CONFIG_FLAGS="--build=`uname -p`-apple-darwin \
slouken@1799
    21
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
slouken@1799
    22
icculus@5961
    23
# PowerPC 32-bit compiler flags
icculus@5961
    24
CONFIG_PPC="--host=powerpc-apple-darwin"
icculus@5961
    25
CC_PPC="gcc-4.0"
icculus@5961
    26
CXX_PPC="g++-4.0"
icculus@5961
    27
BUILD_FLAGS_PPC="-arch ppc -mmacosx-version-min=10.4"
icculus@3629
    28
slouken@3248
    29
# Intel 32-bit compiler flags
icculus@5961
    30
CONFIG_X86="--host=i386-apple-darwin"
icculus@5961
    31
CC_X86="gcc"
icculus@5961
    32
CXX_X86="g++"
icculus@5961
    33
BUILD_FLAGS_X86="-arch i386 -mmacosx-version-min=10.4"
slouken@3248
    34
slouken@3248
    35
# Intel 64-bit compiler flags
icculus@5961
    36
CONFIG_X64="--host=x86_64-apple-darwin"
icculus@5961
    37
CC_X64="gcc"
icculus@5961
    38
CXX_X64="g++"
icculus@5961
    39
BUILD_FLAGS_X64="-arch x86_64 -mmacosx-version-min=10.6"
slouken@3248
    40
slouken@1636
    41
#
slouken@1636
    42
# Find the configure script
slouken@1636
    43
#
slouken@1648
    44
srcdir=`dirname $0`/..
slouken@1648
    45
auxdir=$srcdir/build-scripts
slouken@1648
    46
cd $srcdir
slouken@1636
    47
icculus@5961
    48
allow_ppc="yes"
icculus@5961
    49
which gcc-4.0 >/dev/null 2>/dev/null
icculus@5961
    50
if [ "x$?" = "x1" ]; then
icculus@5961
    51
    #echo "WARNING: Can't find gcc-4.0, which means you don't have Xcode 3."
icculus@5961
    52
    #echo "WARNING: Therefore, we can't do PowerPC support."
icculus@5961
    53
    allow_ppc="no"
icculus@5961
    54
fi
icculus@5961
    55
slouken@1636
    56
#
slouken@1636
    57
# Figure out which phase to build:
slouken@1636
    58
# all,
icculus@5961
    59
# configure, configure-ppc, configure-x86, configure-x64
icculus@5961
    60
# make, make-ppc, make-x86, make-x64, merge
slouken@1636
    61
# install
icculus@1741
    62
# clean
slouken@1636
    63
if test x"$1" = x; then
slouken@1636
    64
    phase=all
slouken@1636
    65
else
slouken@1636
    66
    phase="$1"
slouken@1636
    67
fi
slouken@1636
    68
case $phase in
slouken@1636
    69
    all)
icculus@5961
    70
        configure_ppc="$allow_ppc"
slouken@1636
    71
        configure_x86="yes"
slouken@3248
    72
        configure_x64="yes"
icculus@5961
    73
        make_ppc="$allow_ppc"
slouken@1636
    74
        make_x86="yes"
slouken@3248
    75
        make_x64="yes"
slouken@1636
    76
        merge="yes"
slouken@1636
    77
        ;;
slouken@1636
    78
    configure)
icculus@5961
    79
        configure_ppc="$allow_ppc"
slouken@1636
    80
        configure_x86="yes"
slouken@3248
    81
        configure_x64="yes"
slouken@1636
    82
        ;;
icculus@5961
    83
    configure-ppc)
icculus@5961
    84
        configure_ppc="$allow_ppc"
icculus@5961
    85
        ;;
slouken@1636
    86
    configure-x86)
slouken@1636
    87
        configure_x86="yes"
slouken@1636
    88
        ;;
slouken@3248
    89
    configure-x64)
slouken@3248
    90
        configure_x64="yes"
slouken@3248
    91
        ;;
slouken@1636
    92
    make)
icculus@5961
    93
        make_ppc="$allow_ppc"
slouken@1636
    94
        make_x86="yes"
slouken@3248
    95
        make_x64="yes"
slouken@1636
    96
        merge="yes"
slouken@1636
    97
        ;;
icculus@5961
    98
    make-ppc)
icculus@5961
    99
        make_ppc="$allow_ppc"
icculus@5961
   100
        ;;
slouken@1636
   101
    make-x86)
slouken@1636
   102
        make_x86="yes"
slouken@1636
   103
        ;;
slouken@3248
   104
    make-x64)
slouken@3248
   105
        make_x64="yes"
slouken@3248
   106
        ;;
slouken@1636
   107
    merge)
slouken@1636
   108
        merge="yes"
slouken@1636
   109
        ;;
slouken@1636
   110
    install)
slouken@1648
   111
        install_bin="yes"
slouken@1648
   112
        install_hdrs="yes"
slouken@1648
   113
        install_lib="yes"
slouken@1648
   114
        install_data="yes"
slouken@1648
   115
        install_man="yes"
slouken@1648
   116
        ;;
slouken@1648
   117
    install-bin)
slouken@1648
   118
        install_bin="yes"
slouken@1648
   119
        ;;
slouken@1648
   120
    install-hdrs)
slouken@1648
   121
        install_hdrs="yes"
slouken@1648
   122
        ;;
slouken@1648
   123
    install-lib)
slouken@1648
   124
        install_lib="yes"
slouken@1648
   125
        ;;
slouken@1648
   126
    install-data)
slouken@1648
   127
        install_data="yes"
slouken@1648
   128
        ;;
slouken@1648
   129
    install-man)
slouken@1648
   130
        install_man="yes"
slouken@1648
   131
        ;;
icculus@1741
   132
    clean)
icculus@5961
   133
        clean_ppc="yes"
icculus@1741
   134
        clean_x86="yes"
slouken@3248
   135
        clean_x64="yes"
icculus@1741
   136
        ;;
icculus@5961
   137
    clean-ppc)
icculus@5961
   138
        clean_ppc="yes"
icculus@5961
   139
        ;;
icculus@1741
   140
    clean-x86)
icculus@1741
   141
        clean_x86="yes"
icculus@1741
   142
        ;;
slouken@3248
   143
    clean-x64)
slouken@3248
   144
        clean_x64="yes"
slouken@3248
   145
        ;;
slouken@1648
   146
    *)
icculus@5961
   147
        echo "Usage: $0 [all|configure[-ppc|-x86|-x64]|make[-ppc|-x86|-x64]|merge|install|clean[-ppc|-x86|-x64]]"
slouken@1648
   148
        exit 1
slouken@1648
   149
        ;;
slouken@1648
   150
esac
slouken@1648
   151
case `uname -p` in
slouken@1648
   152
    *86)
slouken@1648
   153
        native_path=x86
slouken@1648
   154
        ;;
icculus@5961
   155
    *powerpc)
icculus@5961
   156
        native_path=ppc
icculus@5961
   157
        ;;
slouken@3249
   158
    x86_64)
slouken@3249
   159
        native_path=x64
slouken@3249
   160
        ;;
slouken@1648
   161
    *)
slouken@1648
   162
        echo "Couldn't figure out native architecture path"
slouken@1648
   163
        exit 1
slouken@1636
   164
        ;;
slouken@1636
   165
esac
slouken@1636
   166
slouken@1636
   167
#
slouken@1636
   168
# Create the build directories
slouken@1636
   169
#
icculus@5961
   170
for dir in build build/ppc build/x86 build/x64; do
slouken@1636
   171
    if test -d $dir; then
slouken@1636
   172
        :
slouken@1636
   173
    else
slouken@1636
   174
        mkdir $dir || exit 1
slouken@1636
   175
    fi
slouken@1636
   176
done
slouken@1636
   177
icculus@5961
   178
icculus@5961
   179
#
icculus@5961
   180
# Build the PowerPC 32-bit binary
icculus@5961
   181
#
icculus@5961
   182
if test x$configure_ppc = xyes; then
icculus@5961
   183
    (cd build/ppc && \
icculus@5961
   184
     sh ../../configure $BASE_CONFIG_FLAGS $CONFIG_PPC CC="$CC_PPC" CXX="$CXX_PPC" CFLAGS="$CFLAGS $BUILD_FLAGS_PPC $CFLAGS_PPC" LDFLAGS="$BUILD_FLAGS_PPC $LFLAGS_PPC") || exit 2
icculus@5961
   185
fi
icculus@5961
   186
if test x$make_ppc = xyes; then
icculus@5961
   187
    (cd build/ppc && make -j$NJOB) || exit 3
icculus@5961
   188
fi
slouken@1636
   189
#
slouken@3248
   190
# Build the Intel 32-bit binary
slouken@1636
   191
#
slouken@1636
   192
if test x$configure_x86 = xyes; then
slouken@1636
   193
    (cd build/x86 && \
icculus@5961
   194
     sh ../../configure $BASE_CONFIG_FLAGS $CONFIG_X86 CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $BUILD_FLAGS_X86 $CFLAGS_X86" LDFLAGS="$BUILD_FLAGS_X86 $LFLAGS_X86") || exit 2
slouken@1636
   195
fi
slouken@1636
   196
if test x$make_x86 = xyes; then
slouken@1742
   197
    (cd build/x86 && make -j$NJOB) || exit 3
slouken@1636
   198
fi
slouken@1636
   199
slouken@1636
   200
#
icculus@5961
   201
# Build the Intel 64-bit binary
slouken@3248
   202
#
slouken@3248
   203
if test x$configure_x64 = xyes; then
slouken@3248
   204
    (cd build/x64 && \
icculus@5961
   205
     sh ../../configure $BASE_CONFIG_FLAGS $CONFIG_X64 CC="$CC_X64" CXX="$CXX_X64" CFLAGS="$CFLAGS $BUILD_FLAGS_X64 $CFLAGS_X64" LDFLAGS="$BUILD_FLAGS_X64 $LFLAGS_X64") || exit 2
slouken@3248
   206
fi
slouken@3248
   207
if test x$make_x64 = xyes; then
slouken@3248
   208
    (cd build/x64 && make -j$NJOB) || exit 3
slouken@3248
   209
fi
slouken@3248
   210
slouken@3248
   211
#
slouken@1636
   212
# Combine into fat binary
slouken@1636
   213
#
slouken@1636
   214
if test x$merge = xyes; then
slouken@1648
   215
    output=.libs
slouken@1648
   216
    sh $auxdir/mkinstalldirs build/$output
slouken@1648
   217
    cd build
slouken@3245
   218
    target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
slouken@3245
   219
    (lipo -create -o $output/$target `find . -mindepth 4 -maxdepth 4 -type f -name "*.dylib"` &&
slouken@1648
   220
     ln -sf $target $output/libSDL.dylib &&
slouken@1648
   221
     lipo -create -o $output/libSDL.a */build/.libs/libSDL.a &&
slouken@1648
   222
     cp $native_path/build/.libs/libSDL.la $output &&
slouken@1648
   223
     cp $native_path/build/.libs/libSDL.lai $output &&
slouken@1648
   224
     cp $native_path/build/libSDL.la . &&
slouken@1648
   225
     lipo -create -o libSDLmain.a */build/libSDLmain.a &&
slouken@1636
   226
     echo "Build complete!" &&
slouken@1636
   227
     echo "Files can be found in the build directory.") || exit 4
slouken@1648
   228
    cd ..
slouken@1636
   229
fi
slouken@1636
   230
slouken@1636
   231
#
slouken@1636
   232
# Install
slouken@1636
   233
#
slouken@1648
   234
do_install()
slouken@1648
   235
{
slouken@1648
   236
    echo $*
slouken@1648
   237
    $* || exit 5
slouken@1648
   238
}
slouken@1648
   239
if test x$prefix = x; then
slouken@1648
   240
    prefix=/usr/local
slouken@1648
   241
fi
slouken@1648
   242
if test x$exec_prefix = x; then
slouken@1648
   243
    exec_prefix=$prefix
slouken@1648
   244
fi
slouken@1648
   245
if test x$bindir = x; then
slouken@1648
   246
    bindir=$exec_prefix/bin
slouken@1648
   247
fi
slouken@1648
   248
if test x$libdir = x; then
slouken@1648
   249
    libdir=$exec_prefix/lib
slouken@1648
   250
fi
slouken@1648
   251
if test x$includedir = x; then
slouken@1648
   252
    includedir=$prefix/include
slouken@1648
   253
fi
slouken@1648
   254
if test x$datadir = x; then
slouken@1648
   255
    datadir=$prefix/share
slouken@1648
   256
fi
slouken@1648
   257
if test x$mandir = x; then
slouken@1648
   258
    mandir=$prefix/man
slouken@1636
   259
fi
slouken@1648
   260
if test x$install_bin = xyes; then
slouken@1648
   261
    do_install sh $auxdir/mkinstalldirs $bindir
slouken@1648
   262
    do_install /usr/bin/install -c -m 755 build/$native_path/sdl-config $bindir/sdl-config
slouken@1648
   263
fi
slouken@1648
   264
if test x$install_hdrs = xyes; then
slouken@1648
   265
    do_install sh $auxdir/mkinstalldirs $includedir/SDL
slouken@1648
   266
    for src in $srcdir/include/*.h; do \
slouken@1648
   267
        file=`echo $src | sed -e 's|^.*/||'`; \
slouken@1648
   268
        do_install /usr/bin/install -c -m 644 $src $includedir/SDL/$file; \
slouken@1648
   269
    done
slouken@1648
   270
    do_install /usr/bin/install -c -m 644 $srcdir/include/SDL_config_macosx.h $includedir/SDL/SDL_config.h
slouken@1648
   271
fi
slouken@1648
   272
if test x$install_lib = xyes; then
slouken@1648
   273
    do_install sh $auxdir/mkinstalldirs $libdir
slouken@1648
   274
    do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDL.la $libdir/libSDL.la
slouken@1648
   275
    do_install /usr/bin/install -c -m 644 build/libSDLmain.a $libdir/libSDLmain.a
slouken@1648
   276
    do_install ranlib $libdir/libSDLmain.a
slouken@1648
   277
fi
slouken@1648
   278
if test x$install_data = xyes; then
slouken@1648
   279
    do_install sh $auxdir/mkinstalldirs $datadir/aclocal
slouken@1648
   280
    do_install /usr/bin/install -c -m 644 $srcdir/sdl.m4 $datadir/aclocal/sdl.m4
slouken@1648
   281
fi
slouken@1648
   282
if test x$install_man = xyes; then
slouken@1648
   283
    do_install sh $auxdir/mkinstalldirs $mandir/man3
slouken@1648
   284
    for src in $srcdir/docs/man3/*.3; do \
slouken@1648
   285
        file=`echo $src | sed -e 's|^.*/||'`; \
slouken@1648
   286
        do_install /usr/bin/install -c -m 644 $src $mandir/man3/$file; \
slouken@1648
   287
    done
slouken@1648
   288
fi
icculus@1741
   289
icculus@1741
   290
#
icculus@1741
   291
# Clean up
icculus@1741
   292
#
icculus@1741
   293
do_clean()
icculus@1741
   294
{
icculus@1741
   295
    echo $*
icculus@1741
   296
    $* || exit 6
icculus@1741
   297
}
icculus@5961
   298
if test x$clean_ppc = xyes; then
icculus@5961
   299
    do_clean rm -r build/ppc
icculus@5961
   300
fi
icculus@1741
   301
if test x$clean_x86 = xyes; then
icculus@1741
   302
    do_clean rm -r build/x86
icculus@1741
   303
fi
slouken@5611
   304
if test x$clean_x64 = xyes; then
slouken@5611
   305
    do_clean rm -r build/x64
icculus@1741
   306
fi