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