build-scripts/fatbuild.sh
author Ryan C. Gordon <icculus@icculus.org>
Thu, 13 Sep 2012 15:24:04 -0400
changeset 6423 339c0ccf6250
parent 6276 b696a93d2848
child 6457 1b32affca783
permissions -rwxr-xr-x
Make the X11 SetBordered event tapdancing more robust, restore focus, etc.
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@6016
    45
srcdir=`cd $srcdir && pwd`
slouken@1648
    46
auxdir=$srcdir/build-scripts
slouken@1648
    47
cd $srcdir
slouken@1636
    48
icculus@5961
    49
allow_ppc="yes"
icculus@5961
    50
which gcc-4.0 >/dev/null 2>/dev/null
icculus@5961
    51
if [ "x$?" = "x1" ]; then
icculus@5961
    52
    #echo "WARNING: Can't find gcc-4.0, which means you don't have Xcode 3."
icculus@5961
    53
    #echo "WARNING: Therefore, we can't do PowerPC support."
icculus@5961
    54
    allow_ppc="no"
icculus@5961
    55
fi
icculus@5961
    56
slouken@1636
    57
#
slouken@1636
    58
# Figure out which phase to build:
slouken@1636
    59
# all,
icculus@5961
    60
# configure, configure-ppc, configure-x86, configure-x64
icculus@5961
    61
# make, make-ppc, make-x86, make-x64, merge
slouken@1636
    62
# install
icculus@1741
    63
# clean
slouken@1636
    64
if test x"$1" = x; then
slouken@1636
    65
    phase=all
slouken@1636
    66
else
slouken@1636
    67
    phase="$1"
slouken@1636
    68
fi
slouken@1636
    69
case $phase in
slouken@1636
    70
    all)
icculus@5961
    71
        configure_ppc="$allow_ppc"
slouken@1636
    72
        configure_x86="yes"
slouken@3248
    73
        configure_x64="yes"
icculus@5961
    74
        make_ppc="$allow_ppc"
slouken@1636
    75
        make_x86="yes"
slouken@3248
    76
        make_x64="yes"
slouken@1636
    77
        merge="yes"
slouken@1636
    78
        ;;
slouken@1636
    79
    configure)
icculus@5961
    80
        configure_ppc="$allow_ppc"
slouken@1636
    81
        configure_x86="yes"
slouken@3248
    82
        configure_x64="yes"
slouken@1636
    83
        ;;
icculus@5961
    84
    configure-ppc)
icculus@5961
    85
        configure_ppc="$allow_ppc"
icculus@5961
    86
        ;;
slouken@1636
    87
    configure-x86)
slouken@1636
    88
        configure_x86="yes"
slouken@1636
    89
        ;;
slouken@3248
    90
    configure-x64)
slouken@3248
    91
        configure_x64="yes"
slouken@3248
    92
        ;;
slouken@1636
    93
    make)
icculus@5961
    94
        make_ppc="$allow_ppc"
slouken@1636
    95
        make_x86="yes"
slouken@3248
    96
        make_x64="yes"
slouken@1636
    97
        merge="yes"
slouken@1636
    98
        ;;
icculus@5961
    99
    make-ppc)
icculus@5961
   100
        make_ppc="$allow_ppc"
icculus@5961
   101
        ;;
slouken@1636
   102
    make-x86)
slouken@1636
   103
        make_x86="yes"
slouken@1636
   104
        ;;
slouken@3248
   105
    make-x64)
slouken@3248
   106
        make_x64="yes"
slouken@3248
   107
        ;;
slouken@1636
   108
    merge)
slouken@1636
   109
        merge="yes"
slouken@1636
   110
        ;;
slouken@1636
   111
    install)
slouken@1648
   112
        install_bin="yes"
slouken@1648
   113
        install_hdrs="yes"
slouken@1648
   114
        install_lib="yes"
slouken@1648
   115
        install_data="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
        ;;
icculus@1741
   129
    clean)
icculus@5961
   130
        clean_ppc="yes"
icculus@1741
   131
        clean_x86="yes"
slouken@3248
   132
        clean_x64="yes"
icculus@1741
   133
        ;;
icculus@5961
   134
    clean-ppc)
icculus@5961
   135
        clean_ppc="yes"
icculus@5961
   136
        ;;
icculus@1741
   137
    clean-x86)
icculus@1741
   138
        clean_x86="yes"
icculus@1741
   139
        ;;
slouken@3248
   140
    clean-x64)
slouken@3248
   141
        clean_x64="yes"
slouken@3248
   142
        ;;
slouken@1648
   143
    *)
icculus@5961
   144
        echo "Usage: $0 [all|configure[-ppc|-x86|-x64]|make[-ppc|-x86|-x64]|merge|install|clean[-ppc|-x86|-x64]]"
slouken@1648
   145
        exit 1
slouken@1648
   146
        ;;
slouken@1648
   147
esac
slouken@1648
   148
case `uname -p` in
slouken@1648
   149
    *86)
slouken@1648
   150
        native_path=x86
slouken@1648
   151
        ;;
icculus@5961
   152
    *powerpc)
icculus@5961
   153
        native_path=ppc
icculus@5961
   154
        ;;
slouken@3249
   155
    x86_64)
slouken@3249
   156
        native_path=x64
slouken@3249
   157
        ;;
slouken@1648
   158
    *)
slouken@1648
   159
        echo "Couldn't figure out native architecture path"
slouken@1648
   160
        exit 1
slouken@1636
   161
        ;;
slouken@1636
   162
esac
slouken@1636
   163
slouken@1636
   164
#
slouken@1636
   165
# Create the build directories
slouken@1636
   166
#
icculus@5961
   167
for dir in build build/ppc build/x86 build/x64; do
slouken@1636
   168
    if test -d $dir; then
slouken@1636
   169
        :
slouken@1636
   170
    else
slouken@1636
   171
        mkdir $dir || exit 1
slouken@1636
   172
    fi
slouken@1636
   173
done
slouken@1636
   174
icculus@5961
   175
icculus@5961
   176
#
icculus@5961
   177
# Build the PowerPC 32-bit binary
icculus@5961
   178
#
icculus@5961
   179
if test x$configure_ppc = xyes; then
icculus@5961
   180
    (cd build/ppc && \
icculus@5961
   181
     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
   182
fi
icculus@5961
   183
if test x$make_ppc = xyes; then
icculus@5961
   184
    (cd build/ppc && make -j$NJOB) || exit 3
icculus@5961
   185
fi
slouken@1636
   186
#
slouken@3248
   187
# Build the Intel 32-bit binary
slouken@1636
   188
#
slouken@1636
   189
if test x$configure_x86 = xyes; then
slouken@1636
   190
    (cd build/x86 && \
icculus@5961
   191
     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
   192
fi
slouken@1636
   193
if test x$make_x86 = xyes; then
slouken@1742
   194
    (cd build/x86 && make -j$NJOB) || exit 3
slouken@1636
   195
fi
slouken@1636
   196
slouken@1636
   197
#
icculus@5961
   198
# Build the Intel 64-bit binary
slouken@3248
   199
#
slouken@3248
   200
if test x$configure_x64 = xyes; then
slouken@3248
   201
    (cd build/x64 && \
icculus@5961
   202
     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
   203
fi
slouken@3248
   204
if test x$make_x64 = xyes; then
slouken@3248
   205
    (cd build/x64 && make -j$NJOB) || exit 3
slouken@3248
   206
fi
slouken@3248
   207
slouken@3248
   208
#
slouken@1636
   209
# Combine into fat binary
slouken@1636
   210
#
slouken@1636
   211
if test x$merge = xyes; then
slouken@1648
   212
    output=.libs
slouken@1648
   213
    sh $auxdir/mkinstalldirs build/$output
slouken@1648
   214
    cd build
slouken@3245
   215
    target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
slouken@3245
   216
    (lipo -create -o $output/$target `find . -mindepth 4 -maxdepth 4 -type f -name "*.dylib"` &&
slouken@6276
   217
     ln -sf $target $output/libSDL2.dylib &&
slouken@6276
   218
     lipo -create -o $output/libSDL2.a */build/.libs/libSDL2.a &&
slouken@6276
   219
     cp $native_path/build/.libs/libSDL2.la $output &&
slouken@6276
   220
     cp $native_path/build/.libs/libSDL2.lai $output &&
slouken@6276
   221
     cp $native_path/build/libSDL2.la . &&
slouken@6276
   222
     lipo -create -o libSDL2main.a */build/libSDL2main.a &&
slouken@1636
   223
     echo "Build complete!" &&
slouken@1636
   224
     echo "Files can be found in the build directory.") || exit 4
slouken@1648
   225
    cd ..
slouken@1636
   226
fi
slouken@1636
   227
slouken@1636
   228
#
slouken@1636
   229
# Install
slouken@1636
   230
#
slouken@1648
   231
do_install()
slouken@1648
   232
{
slouken@1648
   233
    echo $*
slouken@1648
   234
    $* || exit 5
slouken@1648
   235
}
slouken@1648
   236
if test x$prefix = x; then
slouken@1648
   237
    prefix=/usr/local
slouken@1648
   238
fi
slouken@1648
   239
if test x$exec_prefix = x; then
slouken@1648
   240
    exec_prefix=$prefix
slouken@1648
   241
fi
slouken@1648
   242
if test x$bindir = x; then
slouken@1648
   243
    bindir=$exec_prefix/bin
slouken@1648
   244
fi
slouken@1648
   245
if test x$libdir = x; then
slouken@1648
   246
    libdir=$exec_prefix/lib
slouken@1648
   247
fi
slouken@1648
   248
if test x$includedir = x; then
slouken@1648
   249
    includedir=$prefix/include
slouken@1648
   250
fi
slouken@1648
   251
if test x$datadir = x; then
slouken@1648
   252
    datadir=$prefix/share
slouken@1648
   253
fi
slouken@1648
   254
if test x$mandir = x; then
slouken@1648
   255
    mandir=$prefix/man
slouken@1636
   256
fi
slouken@1648
   257
if test x$install_bin = xyes; then
slouken@1648
   258
    do_install sh $auxdir/mkinstalldirs $bindir
slouken@6276
   259
    do_install /usr/bin/install -c -m 755 build/$native_path/sdl2-config $bindir/sdl2-config
slouken@1648
   260
fi
slouken@1648
   261
if test x$install_hdrs = xyes; then
slouken@6276
   262
    do_install sh $auxdir/mkinstalldirs $includedir/SDL2
slouken@1648
   263
    for src in $srcdir/include/*.h; do \
slouken@1648
   264
        file=`echo $src | sed -e 's|^.*/||'`; \
slouken@6276
   265
        do_install /usr/bin/install -c -m 644 $src $includedir/SDL2/$file; \
slouken@1648
   266
    done
slouken@6276
   267
    do_install /usr/bin/install -c -m 644 $srcdir/include/SDL_config_macosx.h $includedir/SDL2/SDL_config.h
slouken@1648
   268
fi
slouken@1648
   269
if test x$install_lib = xyes; then
slouken@1648
   270
    do_install sh $auxdir/mkinstalldirs $libdir
slouken@6276
   271
    do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDL2.la $libdir/libSDL2.la
slouken@6276
   272
    do_install /usr/bin/install -c -m 644 build/libSDL2main.a $libdir/libSDL2main.a
slouken@6276
   273
    do_install ranlib $libdir/libSDL2main.a
slouken@1648
   274
fi
slouken@1648
   275
if test x$install_data = xyes; then
slouken@1648
   276
    do_install sh $auxdir/mkinstalldirs $datadir/aclocal
slouken@6276
   277
    do_install /usr/bin/install -c -m 644 $srcdir/sdl2.m4 $datadir/aclocal/sdl2.m4
slouken@1648
   278
fi
icculus@1741
   279
icculus@1741
   280
#
icculus@1741
   281
# Clean up
icculus@1741
   282
#
icculus@1741
   283
do_clean()
icculus@1741
   284
{
icculus@1741
   285
    echo $*
icculus@1741
   286
    $* || exit 6
icculus@1741
   287
}
icculus@5961
   288
if test x$clean_ppc = xyes; then
icculus@5961
   289
    do_clean rm -r build/ppc
icculus@5961
   290
fi
icculus@1741
   291
if test x$clean_x86 = xyes; then
icculus@1741
   292
    do_clean rm -r build/x86
icculus@1741
   293
fi
slouken@5611
   294
if test x$clean_x64 = xyes; then
slouken@5611
   295
    do_clean rm -r build/x64
icculus@1741
   296
fi