build-scripts/fatbuild.sh
author Ryan C. Gordon <icculus@icculus.org>
Thu, 27 Apr 2006 11:18:03 +0000
changeset 1741 d67622addf51
parent 1739 3a3e847aadb9
child 1742 af4352da64d8
permissions -rwxr-xr-x
fatbuild fixes:

- A change to define CXX in fatbuild, which comforts the configure script a little, even if we don't use C++ anywhere.
- Some code to see how many CPU cores exist and parallelize make across them.
- CFLAGS that apply to both archs are specified seperately (-O3, -pipe, etc)
- -fvisibility=hidden for the gcc4 builds
- a "clean", "clean-ppc" and "clean-x86" command
- Fix to SDL_config_macosx.h for the HAVE_ALLOCA_H thing.

Now builds on an Intel Mac.
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=1
icculus@1741
     7
NCPU=`sysctl -n hw.ncpu`
icculus@1741
     8
icculus@1741
     9
# !!! FIXME: other CFLAGS?
icculus@1741
    10
# Generic, cross-platform CFLAGS you always want go here.
icculus@1741
    11
CFLAGS="-O3 -g -pipe"
icculus@1741
    12
slouken@1636
    13
# PowerPC compiler flags (10.2 runtime compatibility)
slouken@1739
    14
CC_PPC="gcc-3.3 -arch ppc"
icculus@1741
    15
CXX_PPC="g++-3.3 -arch ppc"
slouken@1739
    16
CFLAGS_PPC=""
slouken@1648
    17
CPPFLAGS_PPC="-DMAC_OS_X_VERSION_MIN_REQUIRED=1020 \
slouken@1648
    18
-nostdinc \
slouken@1636
    19
-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
slouken@1636
    20
-I/Developer/SDKs/MacOSX10.2.8.sdk/usr/include/gcc/darwin/3.3 \
slouken@1636
    21
-isystem /Developer/SDKs/MacOSX10.2.8.sdk/usr/include"
slouken@1636
    22
slouken@1636
    23
# PowerPC linker flags 
slouken@1648
    24
LFLAGS_PPC="-arch ppc \
slouken@1636
    25
-L/Developer/SDKs/MacOSX10.2.8.sdk/usr/lib/gcc/darwin/3.3 \
slouken@1636
    26
-F/Developer/SDKs/MacOSX10.2.8.sdk/System/Library/Frameworks \
slouken@1636
    27
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.2.8.sdk"
slouken@1636
    28
slouken@1636
    29
# Intel compiler flags (10.4 runtime compatibility)
slouken@1739
    30
CC_X86="gcc-4.0 -arch i386"
icculus@1741
    31
CXX_X86="g++-4.0 -arch i386"
slouken@1739
    32
CFLAGS_X86="-mmacosx-version-min=10.4"
slouken@1648
    33
CPPFLAGS_X86="-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
icculus@1741
    34
-nostdinc -fvisibility=hidden \
slouken@1648
    35
-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks \
slouken@1648
    36
-I/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.1/include \
slouken@1648
    37
-isystem /Developer/SDKs/MacOSX10.4u.sdk/usr/include"
slouken@1636
    38
slouken@1636
    39
# Intel linker flags
slouken@1639
    40
LFLAGS_X86="-arch i386 -mmacosx-version-min=10.4 \
slouken@1636
    41
-L/Developer/SDKs/MacOSX10.4u.sdk/usr/lib/gcc/i686-apple-darwin8/4.0.0 \
slouken@1636
    42
-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk"
slouken@1636
    43
slouken@1636
    44
#
slouken@1636
    45
# Find the configure script
slouken@1636
    46
#
slouken@1648
    47
srcdir=`dirname $0`/..
slouken@1648
    48
auxdir=$srcdir/build-scripts
slouken@1648
    49
cd $srcdir
slouken@1636
    50
slouken@1636
    51
#
slouken@1636
    52
# Figure out which phase to build:
slouken@1636
    53
# all,
slouken@1636
    54
# configure, configure-ppc, configure-x86,
slouken@1636
    55
# make, make-ppc, make-x86, merge
slouken@1636
    56
# install
icculus@1741
    57
# clean
slouken@1636
    58
if test x"$1" = x; then
slouken@1636
    59
    phase=all
slouken@1636
    60
else
slouken@1636
    61
    phase="$1"
slouken@1636
    62
fi
slouken@1636
    63
case $phase in
slouken@1636
    64
    all)
slouken@1636
    65
        configure_ppc="yes"
slouken@1636
    66
        configure_x86="yes"
slouken@1636
    67
        make_ppc="yes"
slouken@1636
    68
        make_x86="yes"
slouken@1636
    69
        merge="yes"
slouken@1636
    70
        ;;
slouken@1636
    71
    configure)
slouken@1636
    72
        configure_ppc="yes"
slouken@1636
    73
        configure_x86="yes"
slouken@1636
    74
        ;;
slouken@1636
    75
    configure-ppc)
slouken@1636
    76
        configure_ppc="yes"
slouken@1636
    77
        ;;
slouken@1636
    78
    configure-x86)
slouken@1636
    79
        configure_x86="yes"
slouken@1636
    80
        ;;
slouken@1636
    81
    make)
slouken@1636
    82
        make_ppc="yes"
slouken@1636
    83
        make_x86="yes"
slouken@1636
    84
        merge="yes"
slouken@1636
    85
        ;;
slouken@1636
    86
    make-ppc)
slouken@1636
    87
        make_ppc="yes"
slouken@1636
    88
        ;;
slouken@1636
    89
    make-x86)
slouken@1636
    90
        make_x86="yes"
slouken@1636
    91
        ;;
slouken@1636
    92
    merge)
slouken@1636
    93
        merge="yes"
slouken@1636
    94
        ;;
slouken@1636
    95
    install)
slouken@1648
    96
        install_bin="yes"
slouken@1648
    97
        install_hdrs="yes"
slouken@1648
    98
        install_lib="yes"
slouken@1648
    99
        install_data="yes"
slouken@1648
   100
        install_man="yes"
slouken@1648
   101
        ;;
slouken@1648
   102
    install-bin)
slouken@1648
   103
        install_bin="yes"
slouken@1648
   104
        ;;
slouken@1648
   105
    install-hdrs)
slouken@1648
   106
        install_hdrs="yes"
slouken@1648
   107
        ;;
slouken@1648
   108
    install-lib)
slouken@1648
   109
        install_lib="yes"
slouken@1648
   110
        ;;
slouken@1648
   111
    install-data)
slouken@1648
   112
        install_data="yes"
slouken@1648
   113
        ;;
slouken@1648
   114
    install-man)
slouken@1648
   115
        install_man="yes"
slouken@1648
   116
        ;;
icculus@1741
   117
    clean)
icculus@1741
   118
        clean_ppc="yes"
icculus@1741
   119
        clean_x86="yes"
icculus@1741
   120
        ;;
icculus@1741
   121
    clean-ppc)
icculus@1741
   122
        clean_ppc="yes"
icculus@1741
   123
        ;;
icculus@1741
   124
    clean-x86)
icculus@1741
   125
        clean_x86="yes"
icculus@1741
   126
        ;;
slouken@1648
   127
    *)
icculus@1741
   128
        echo "Usage: $0 [all|configure[-ppc|-x86]|make[-ppc|-x86]|merge|install|clean]"
slouken@1648
   129
        exit 1
slouken@1648
   130
        ;;
slouken@1648
   131
esac
slouken@1648
   132
case `uname -p` in
slouken@1648
   133
    powerpc)
slouken@1648
   134
        native_path=ppc
slouken@1648
   135
        ;;
slouken@1648
   136
    *86)
slouken@1648
   137
        native_path=x86
slouken@1648
   138
        ;;
slouken@1648
   139
    *)
slouken@1648
   140
        echo "Couldn't figure out native architecture path"
slouken@1648
   141
        exit 1
slouken@1636
   142
        ;;
slouken@1636
   143
esac
slouken@1636
   144
slouken@1636
   145
#
slouken@1636
   146
# Create the build directories
slouken@1636
   147
#
slouken@1636
   148
for dir in build build/ppc build/x86; do
slouken@1636
   149
    if test -d $dir; then
slouken@1636
   150
        :
slouken@1636
   151
    else
slouken@1636
   152
        mkdir $dir || exit 1
slouken@1636
   153
    fi
slouken@1636
   154
done
slouken@1636
   155
slouken@1636
   156
#
slouken@1636
   157
# Build the PowerPC binary
slouken@1636
   158
#
slouken@1636
   159
if test x$configure_ppc = xyes; then
slouken@1636
   160
    (cd build/ppc && \
icculus@1741
   161
     sh ../../configure --build=`uname -p`-apple-darwin --host=powerpc-apple-darwin CC="$CC_PPC" CXX="$CXX_PPC" CFLAGS="$CFLAGS $CFLAGS_PPC" CPPFLAGS="$CPPFLAGS_PPC" LDFLAGS="$LFLAGS_PPC") || exit 2
slouken@1636
   162
fi
slouken@1636
   163
if test x$make_ppc = xyes; then
icculus@1741
   164
    (cd build/ppc && make -j$NCPU) || exit 3
slouken@1636
   165
fi
slouken@1636
   166
slouken@1636
   167
#
slouken@1636
   168
# Build the Intel binary
slouken@1636
   169
#
slouken@1636
   170
if test x$configure_x86 = xyes; then
slouken@1636
   171
    (cd build/x86 && \
icculus@1741
   172
     sh ../../configure --build=`uname -p`-apple-darwin --host=i686-apple-darwin CC="$CC_X86" CXX="$CXX_X86" CFLAGS="$CFLAGS $CFLAGS_X86" CPPFLAGS="$CPPFLAGS_X86" LDFLAGS="$LFLAGS_X86") || exit 2
slouken@1636
   173
fi
slouken@1636
   174
if test x$make_x86 = xyes; then
icculus@1741
   175
    (cd build/x86 && make -j$NCPU) || exit 3
slouken@1636
   176
fi
slouken@1636
   177
slouken@1636
   178
#
slouken@1636
   179
# Combine into fat binary
slouken@1636
   180
#
slouken@1636
   181
if test x$merge = xyes; then
slouken@1648
   182
    output=.libs
slouken@1648
   183
    sh $auxdir/mkinstalldirs build/$output
slouken@1648
   184
    cd build
slouken@1648
   185
    target=`find . -mindepth 3 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
slouken@1648
   186
    (lipo -create -o $output/$target `find . -mindepth 3 -type f -name "*.dylib"` &&
slouken@1648
   187
     ln -sf $target $output/libSDL-1.2.0.dylib &&
slouken@1648
   188
     ln -sf $target $output/libSDL.dylib &&
slouken@1648
   189
     lipo -create -o $output/libSDL.a */build/.libs/libSDL.a &&
slouken@1648
   190
     cp $native_path/build/.libs/libSDL.la $output &&
slouken@1648
   191
     cp $native_path/build/.libs/libSDL.lai $output &&
slouken@1648
   192
     cp $native_path/build/libSDL.la . &&
slouken@1648
   193
     lipo -create -o libSDLmain.a */build/libSDLmain.a &&
slouken@1636
   194
     echo "Build complete!" &&
slouken@1636
   195
     echo "Files can be found in the build directory.") || exit 4
slouken@1648
   196
    cd ..
slouken@1636
   197
fi
slouken@1636
   198
slouken@1636
   199
#
slouken@1636
   200
# Install
slouken@1636
   201
#
slouken@1648
   202
do_install()
slouken@1648
   203
{
slouken@1648
   204
    echo $*
slouken@1648
   205
    $* || exit 5
slouken@1648
   206
}
slouken@1648
   207
if test x$prefix = x; then
slouken@1648
   208
    prefix=/usr/local
slouken@1636
   209
fi
slouken@1648
   210
if test x$exec_prefix = x; then
slouken@1648
   211
    exec_prefix=$prefix
slouken@1648
   212
fi
slouken@1648
   213
if test x$bindir = x; then
slouken@1648
   214
    bindir=$exec_prefix/bin
slouken@1648
   215
fi
slouken@1648
   216
if test x$libdir = x; then
slouken@1648
   217
    libdir=$exec_prefix/lib
slouken@1648
   218
fi
slouken@1648
   219
if test x$includedir = x; then
slouken@1648
   220
    includedir=$prefix/include
slouken@1648
   221
fi
slouken@1648
   222
if test x$datadir = x; then
slouken@1648
   223
    datadir=$prefix/share
slouken@1648
   224
fi
slouken@1648
   225
if test x$mandir = x; then
slouken@1648
   226
    mandir=$prefix/man
slouken@1648
   227
fi
slouken@1648
   228
if test x$install_bin = xyes; then
slouken@1648
   229
    do_install sh $auxdir/mkinstalldirs $bindir
slouken@1648
   230
    do_install /usr/bin/install -c -m 755 build/$native_path/sdl-config $bindir/sdl-config
slouken@1648
   231
fi
slouken@1648
   232
if test x$install_hdrs = xyes; then
slouken@1648
   233
    do_install sh $auxdir/mkinstalldirs $includedir/SDL
slouken@1648
   234
    for src in $srcdir/include/*.h; do \
slouken@1648
   235
        file=`echo $src | sed -e 's|^.*/||'`; \
slouken@1648
   236
        do_install /usr/bin/install -c -m 644 $src $includedir/SDL/$file; \
slouken@1648
   237
    done
slouken@1648
   238
    do_install /usr/bin/install -c -m 644 $srcdir/include/SDL_config_macosx.h $includedir/SDL/SDL_config.h
slouken@1648
   239
fi
slouken@1648
   240
if test x$install_lib = xyes; then
slouken@1648
   241
    do_install sh $auxdir/mkinstalldirs $libdir
slouken@1648
   242
    do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDL.la $libdir/libSDL.la
slouken@1648
   243
    do_install /usr/bin/install -c -m 644 build/libSDLmain.a $libdir/libSDLmain.a
slouken@1648
   244
    do_install ranlib $libdir/libSDLmain.a
slouken@1648
   245
fi
slouken@1648
   246
if test x$install_data = xyes; then
slouken@1648
   247
    do_install sh $auxdir/mkinstalldirs $datadir/aclocal
slouken@1648
   248
    do_install /usr/bin/install -c -m 644 $srcdir/sdl.m4 $datadir/aclocal/sdl.m4
slouken@1648
   249
fi
slouken@1648
   250
if test x$install_man = xyes; then
slouken@1648
   251
    do_install sh $auxdir/mkinstalldirs $mandir/man3
slouken@1648
   252
    for src in $srcdir/docs/man3/*.3; do \
slouken@1648
   253
        file=`echo $src | sed -e 's|^.*/||'`; \
slouken@1648
   254
        do_install /usr/bin/install -c -m 644 $src $mandir/man3/$file; \
slouken@1648
   255
    done
slouken@1648
   256
fi
icculus@1741
   257
icculus@1741
   258
#
icculus@1741
   259
# Clean up
icculus@1741
   260
#
icculus@1741
   261
do_clean()
icculus@1741
   262
{
icculus@1741
   263
    echo $*
icculus@1741
   264
    $* || exit 6
icculus@1741
   265
}
icculus@1741
   266
if test x$clean_x86 = xyes; then
icculus@1741
   267
    do_clean rm -r build/x86
icculus@1741
   268
fi
icculus@1741
   269
if test x$clean_ppc = xyes; then
icculus@1741
   270
    do_clean rm -r build/ppc
icculus@1741
   271
fi
icculus@1741
   272