build-scripts/fatbuild.sh
author Ozkan Sezer <sezeroz@gmail.com>
Sat, 24 Mar 2018 23:38:50 +0300
branchSDL-1.2
changeset 11977 6cf3a08b42dc
parent 6279 8e98c714bb2a
permissions -rwxr-xr-x
backport bug #3332 (win32 deadkeys) patch:

https://bugzilla.libsdl.org/show_bug.cgi?id=3332
Eric Wasylishen <ewasylishen@gmail.com>
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@5608
     7
if test x$NJOB = x; then
slouken@5608
     8
    NJOB=$NCPU
slouken@5608
     9
fi
slouken@5608
    10
slouken@5608
    11
# SDK path
slouken@5608
    12
if test x$SDK_PATH = x; then
slouken@5608
    13
    SDK_PATH=/Developer/SDKs
slouken@5608
    14
fi
icculus@1741
    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@5960
    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@5960
    23
# PowerPC 32-bit compiler flags
icculus@5960
    24
CONFIG_PPC="--host=powerpc-apple-darwin"
icculus@5960
    25
CC_PPC="gcc-4.0"
icculus@5960
    26
CXX_PPC="g++-4.0"
icculus@5960
    27
BUILD_FLAGS_PPC="-arch ppc -mmacosx-version-min=10.4"
icculus@4397
    28
slouken@5608
    29
# Intel 32-bit compiler flags
icculus@5960
    30
CONFIG_X86="--host=i386-apple-darwin"
icculus@5960
    31
CC_X86="gcc"
icculus@5960
    32
CXX_X86="g++"
icculus@5960
    33
BUILD_FLAGS_X86="-arch i386 -mmacosx-version-min=10.4"
slouken@5608
    34
slouken@5608
    35
# Intel 64-bit compiler flags
icculus@5960
    36
CONFIG_X64="--host=x86_64-apple-darwin"
icculus@5960
    37
CC_X64="gcc"
icculus@5960
    38
CXX_X64="g++"
icculus@5960
    39
BUILD_FLAGS_X64="-arch x86_64 -mmacosx-version-min=10.6"
slouken@5608
    40
slouken@1636
    41
#
slouken@1636
    42
# Find the configure script
slouken@1636
    43
#
slouken@1648
    44
srcdir=`dirname $0`/..
slouken@6279
    45
srcdir=`cd $srcdir && pwd`
slouken@1648
    46
auxdir=$srcdir/build-scripts
slouken@1648
    47
cd $srcdir
slouken@1636
    48
icculus@5960
    49
allow_ppc="yes"
icculus@5960
    50
which gcc-4.0 >/dev/null 2>/dev/null
icculus@5960
    51
if [ "x$?" = "x1" ]; then
icculus@5960
    52
    #echo "WARNING: Can't find gcc-4.0, which means you don't have Xcode 3."
icculus@5960
    53
    #echo "WARNING: Therefore, we can't do PowerPC support."
icculus@5960
    54
    allow_ppc="no"
icculus@5960
    55
fi
icculus@5960
    56
slouken@1636
    57
#
slouken@1636
    58
# Figure out which phase to build:
slouken@1636
    59
# all,
icculus@5960
    60
# configure, configure-ppc, configure-x86, configure-x64
icculus@5960
    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@5960
    71
        configure_ppc="$allow_ppc"
slouken@1636
    72
        configure_x86="yes"
slouken@5608
    73
        configure_x64="yes"
icculus@5960
    74
        make_ppc="$allow_ppc"
slouken@1636
    75
        make_x86="yes"
slouken@5608
    76
        make_x64="yes"
slouken@1636
    77
        merge="yes"
slouken@1636
    78
        ;;
slouken@1636
    79
    configure)
icculus@5960
    80
        configure_ppc="$allow_ppc"
slouken@1636
    81
        configure_x86="yes"
slouken@5608
    82
        configure_x64="yes"
slouken@1636
    83
        ;;
icculus@5960
    84
    configure-ppc)
icculus@5960
    85
        configure_ppc="$allow_ppc"
icculus@5960
    86
        ;;
slouken@1636
    87
    configure-x86)
slouken@1636
    88
        configure_x86="yes"
slouken@1636
    89
        ;;
slouken@5608
    90
    configure-x64)
slouken@5608
    91
        configure_x64="yes"
slouken@5608
    92
        ;;
slouken@1636
    93
    make)
icculus@5960
    94
        make_ppc="$allow_ppc"
slouken@1636
    95
        make_x86="yes"
slouken@5608
    96
        make_x64="yes"
slouken@1636
    97
        merge="yes"
slouken@1636
    98
        ;;
icculus@5960
    99
    make-ppc)
icculus@5960
   100
        make_ppc="$allow_ppc"
icculus@5960
   101
        ;;
slouken@1636
   102
    make-x86)
slouken@1636
   103
        make_x86="yes"
slouken@1636
   104
        ;;
slouken@5608
   105
    make-x64)
slouken@5608
   106
        make_x64="yes"
slouken@5608
   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
        install_man="yes"
slouken@1648
   117
        ;;
slouken@1648
   118
    install-bin)
slouken@1648
   119
        install_bin="yes"
slouken@1648
   120
        ;;
slouken@1648
   121
    install-hdrs)
slouken@1648
   122
        install_hdrs="yes"
slouken@1648
   123
        ;;
slouken@1648
   124
    install-lib)
slouken@1648
   125
        install_lib="yes"
slouken@1648
   126
        ;;
slouken@1648
   127
    install-data)
slouken@1648
   128
        install_data="yes"
slouken@1648
   129
        ;;
slouken@1648
   130
    install-man)
slouken@1648
   131
        install_man="yes"
slouken@1648
   132
        ;;
icculus@1741
   133
    clean)
icculus@5960
   134
        clean_ppc="yes"
icculus@1741
   135
        clean_x86="yes"
slouken@5608
   136
        clean_x64="yes"
icculus@1741
   137
        ;;
icculus@5960
   138
    clean-ppc)
icculus@5960
   139
        clean_ppc="yes"
icculus@5960
   140
        ;;
icculus@1741
   141
    clean-x86)
icculus@1741
   142
        clean_x86="yes"
icculus@1741
   143
        ;;
slouken@5608
   144
    clean-x64)
slouken@5608
   145
        clean_x64="yes"
slouken@5608
   146
        ;;
slouken@1648
   147
    *)
icculus@5960
   148
        echo "Usage: $0 [all|configure[-ppc|-x86|-x64]|make[-ppc|-x86|-x64]|merge|install|clean[-ppc|-x86|-x64]]"
slouken@1648
   149
        exit 1
slouken@1648
   150
        ;;
slouken@1648
   151
esac
slouken@1648
   152
case `uname -p` in
slouken@1648
   153
    *86)
slouken@1648
   154
        native_path=x86
slouken@1648
   155
        ;;
icculus@5960
   156
    *powerpc)
icculus@5960
   157
        native_path=ppc
icculus@5960
   158
        ;;
slouken@5608
   159
    x86_64)
slouken@5608
   160
        native_path=x64
slouken@5608
   161
        ;;
slouken@1648
   162
    *)
slouken@1648
   163
        echo "Couldn't figure out native architecture path"
slouken@1648
   164
        exit 1
slouken@1636
   165
        ;;
slouken@1636
   166
esac
slouken@1636
   167
slouken@1636
   168
#
slouken@1636
   169
# Create the build directories
slouken@1636
   170
#
icculus@5960
   171
for dir in build build/ppc build/x86 build/x64; do
slouken@1636
   172
    if test -d $dir; then
slouken@1636
   173
        :
slouken@1636
   174
    else
slouken@1636
   175
        mkdir $dir || exit 1
slouken@1636
   176
    fi
slouken@1636
   177
done
slouken@1636
   178
icculus@5960
   179
icculus@5960
   180
#
icculus@5960
   181
# Build the PowerPC 32-bit binary
icculus@5960
   182
#
icculus@5960
   183
if test x$configure_ppc = xyes; then
icculus@5960
   184
    (cd build/ppc && \
icculus@5960
   185
     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@5960
   186
fi
icculus@5960
   187
if test x$make_ppc = xyes; then
icculus@5960
   188
    (cd build/ppc && make -j$NJOB) || exit 3
icculus@5960
   189
fi
slouken@1636
   190
#
slouken@5608
   191
# Build the Intel 32-bit binary
slouken@1636
   192
#
slouken@1636
   193
if test x$configure_x86 = xyes; then
slouken@1636
   194
    (cd build/x86 && \
icculus@5960
   195
     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
   196
fi
slouken@1636
   197
if test x$make_x86 = xyes; then
slouken@1742
   198
    (cd build/x86 && make -j$NJOB) || exit 3
slouken@1636
   199
fi
slouken@1636
   200
slouken@1636
   201
#
icculus@5960
   202
# Build the Intel 64-bit binary
slouken@5608
   203
#
slouken@5608
   204
if test x$configure_x64 = xyes; then
slouken@5608
   205
    (cd build/x64 && \
icculus@5960
   206
     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@5608
   207
fi
slouken@5608
   208
if test x$make_x64 = xyes; then
slouken@5608
   209
    (cd build/x64 && make -j$NJOB) || exit 3
slouken@5608
   210
fi
slouken@5608
   211
slouken@5608
   212
#
slouken@1636
   213
# Combine into fat binary
slouken@1636
   214
#
slouken@1636
   215
if test x$merge = xyes; then
slouken@1648
   216
    output=.libs
slouken@1648
   217
    sh $auxdir/mkinstalldirs build/$output
slouken@1648
   218
    cd build
slouken@5608
   219
    target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
slouken@5608
   220
    (lipo -create -o $output/$target `find . -mindepth 4 -maxdepth 4 -type f -name "*.dylib"` &&
slouken@1648
   221
     ln -sf $target $output/libSDL.dylib &&
slouken@1648
   222
     lipo -create -o $output/libSDL.a */build/.libs/libSDL.a &&
slouken@1648
   223
     cp $native_path/build/.libs/libSDL.la $output &&
slouken@1648
   224
     cp $native_path/build/.libs/libSDL.lai $output &&
slouken@1648
   225
     cp $native_path/build/libSDL.la . &&
slouken@6141
   226
     lipo -create -o $output/libSDLmain.a */build/.libs/libSDLmain.a &&
slouken@6141
   227
     cp $native_path/build/.libs/libSDLmain.la $output &&
slouken@6141
   228
     cp $native_path/build/.libs/libSDLmain.lai $output &&
slouken@6141
   229
     cp $native_path/build/libSDLmain.la . &&
slouken@1636
   230
     echo "Build complete!" &&
slouken@1636
   231
     echo "Files can be found in the build directory.") || exit 4
slouken@1648
   232
    cd ..
slouken@1636
   233
fi
slouken@1636
   234
slouken@1636
   235
#
slouken@1636
   236
# Install
slouken@1636
   237
#
slouken@1648
   238
do_install()
slouken@1648
   239
{
slouken@1648
   240
    echo $*
slouken@1648
   241
    $* || exit 5
slouken@1648
   242
}
slouken@1648
   243
if test x$prefix = x; then
slouken@1648
   244
    prefix=/usr/local
slouken@1636
   245
fi
slouken@1648
   246
if test x$exec_prefix = x; then
slouken@1648
   247
    exec_prefix=$prefix
slouken@1648
   248
fi
slouken@1648
   249
if test x$bindir = x; then
slouken@1648
   250
    bindir=$exec_prefix/bin
slouken@1648
   251
fi
slouken@1648
   252
if test x$libdir = x; then
slouken@1648
   253
    libdir=$exec_prefix/lib
slouken@1648
   254
fi
slouken@1648
   255
if test x$includedir = x; then
slouken@1648
   256
    includedir=$prefix/include
slouken@1648
   257
fi
slouken@1648
   258
if test x$datadir = x; then
slouken@1648
   259
    datadir=$prefix/share
slouken@1648
   260
fi
slouken@1648
   261
if test x$mandir = x; then
slouken@1648
   262
    mandir=$prefix/man
slouken@1648
   263
fi
slouken@1648
   264
if test x$install_bin = xyes; then
slouken@1648
   265
    do_install sh $auxdir/mkinstalldirs $bindir
slouken@1648
   266
    do_install /usr/bin/install -c -m 755 build/$native_path/sdl-config $bindir/sdl-config
slouken@1648
   267
fi
slouken@1648
   268
if test x$install_hdrs = xyes; then
slouken@1648
   269
    do_install sh $auxdir/mkinstalldirs $includedir/SDL
slouken@1648
   270
    for src in $srcdir/include/*.h; do \
slouken@1648
   271
        file=`echo $src | sed -e 's|^.*/||'`; \
slouken@1648
   272
        do_install /usr/bin/install -c -m 644 $src $includedir/SDL/$file; \
slouken@1648
   273
    done
slouken@1648
   274
    do_install /usr/bin/install -c -m 644 $srcdir/include/SDL_config_macosx.h $includedir/SDL/SDL_config.h
slouken@1648
   275
fi
slouken@1648
   276
if test x$install_lib = xyes; then
slouken@1648
   277
    do_install sh $auxdir/mkinstalldirs $libdir
slouken@1648
   278
    do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDL.la $libdir/libSDL.la
slouken@6141
   279
    do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDLmain.la $libdir/libSDLmain.la
slouken@1648
   280
fi
slouken@1648
   281
if test x$install_data = xyes; then
slouken@1648
   282
    do_install sh $auxdir/mkinstalldirs $datadir/aclocal
slouken@1648
   283
    do_install /usr/bin/install -c -m 644 $srcdir/sdl.m4 $datadir/aclocal/sdl.m4
slouken@6142
   284
    do_install sh $auxdir/mkinstalldirs $libdir/pkgconfig
slouken@6142
   285
    do_install /usr/bin/install -m 644 build/$native_path/sdl.pc $libdir/pkgconfig/sdl.pc
slouken@1648
   286
fi
slouken@1648
   287
if test x$install_man = xyes; then
slouken@1648
   288
    do_install sh $auxdir/mkinstalldirs $mandir/man3
slouken@1648
   289
    for src in $srcdir/docs/man3/*.3; do \
slouken@1648
   290
        file=`echo $src | sed -e 's|^.*/||'`; \
slouken@1648
   291
        do_install /usr/bin/install -c -m 644 $src $mandir/man3/$file; \
slouken@1648
   292
    done
slouken@1648
   293
fi
icculus@1741
   294
icculus@1741
   295
#
icculus@1741
   296
# Clean up
icculus@1741
   297
#
icculus@1741
   298
do_clean()
icculus@1741
   299
{
icculus@1741
   300
    echo $*
icculus@1741
   301
    $* || exit 6
icculus@1741
   302
}
icculus@5960
   303
if test x$clean_ppc = xyes; then
icculus@5960
   304
    do_clean rm -r build/ppc
icculus@5960
   305
fi
icculus@1741
   306
if test x$clean_x86 = xyes; then
icculus@1741
   307
    do_clean rm -r build/x86
icculus@1741
   308
fi
slouken@5610
   309
if test x$clean_x64 = xyes; then
slouken@5610
   310
    do_clean rm -r build/x64
icculus@1741
   311
fi