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