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