build-scripts/fatbuild.sh
author Michael Sartain <mikesart@valvesoftware.com>
Thu, 11 Oct 2012 09:41:43 -0700
changeset 6570 45855398762c
parent 6457 1b32affca783
child 6767 0d46fb7f06d4
permissions -rwxr-xr-x
Add GLX_X_VISUAL_TYPE_EXT so created window will use DirectColor if available (instead of TrueColor).
Our new X11 window was being created with the TrueColor attribute, and trying to set the gamma
on that would fail. This change checks for the visual_info extension, and uses that to ask for
DirectColor if available.
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
icculus@1741
    11
# Generic, cross-platform CFLAGS you always want go here.
icculus@1741
    12
CFLAGS="-O3 -g -pipe"
icculus@1741
    13
slouken@1799
    14
# We dynamically load X11, so using the system X11 headers is fine.
icculus@5961
    15
BASE_CONFIG_FLAGS="--build=`uname -p`-apple-darwin \
slouken@1799
    16
--x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib"
slouken@1799
    17
icculus@5961
    18
# PowerPC 32-bit compiler flags
icculus@5961
    19
CONFIG_PPC="--host=powerpc-apple-darwin"
icculus@5961
    20
CC_PPC="gcc-4.0"
icculus@5961
    21
CXX_PPC="g++-4.0"
icculus@5961
    22
BUILD_FLAGS_PPC="-arch ppc -mmacosx-version-min=10.4"
icculus@3629
    23
slouken@3248
    24
# Intel 32-bit compiler flags
icculus@5961
    25
CONFIG_X86="--host=i386-apple-darwin"
icculus@5961
    26
CC_X86="gcc"
icculus@5961
    27
CXX_X86="g++"
icculus@5961
    28
BUILD_FLAGS_X86="-arch i386 -mmacosx-version-min=10.4"
slouken@3248
    29
slouken@3248
    30
# Intel 64-bit compiler flags
icculus@5961
    31
CONFIG_X64="--host=x86_64-apple-darwin"
icculus@5961
    32
CC_X64="gcc"
icculus@5961
    33
CXX_X64="g++"
icculus@5961
    34
BUILD_FLAGS_X64="-arch x86_64 -mmacosx-version-min=10.6"
slouken@3248
    35
slouken@1636
    36
#
slouken@1636
    37
# Find the configure script
slouken@1636
    38
#
slouken@1648
    39
srcdir=`dirname $0`/..
slouken@6016
    40
srcdir=`cd $srcdir && pwd`
slouken@1648
    41
auxdir=$srcdir/build-scripts
slouken@1648
    42
cd $srcdir
slouken@1636
    43
icculus@5961
    44
allow_ppc="yes"
icculus@5961
    45
which gcc-4.0 >/dev/null 2>/dev/null
icculus@5961
    46
if [ "x$?" = "x1" ]; then
icculus@5961
    47
    #echo "WARNING: Can't find gcc-4.0, which means you don't have Xcode 3."
icculus@5961
    48
    #echo "WARNING: Therefore, we can't do PowerPC support."
icculus@5961
    49
    allow_ppc="no"
icculus@5961
    50
fi
icculus@5961
    51
slouken@1636
    52
#
slouken@1636
    53
# Figure out which phase to build:
slouken@1636
    54
# all,
icculus@5961
    55
# configure, configure-ppc, configure-x86, configure-x64
icculus@5961
    56
# make, make-ppc, make-x86, make-x64, merge
slouken@1636
    57
# install
icculus@1741
    58
# clean
slouken@1636
    59
if test x"$1" = x; then
slouken@1636
    60
    phase=all
slouken@1636
    61
else
slouken@1636
    62
    phase="$1"
slouken@1636
    63
fi
slouken@1636
    64
case $phase in
slouken@1636
    65
    all)
icculus@5961
    66
        configure_ppc="$allow_ppc"
slouken@1636
    67
        configure_x86="yes"
slouken@3248
    68
        configure_x64="yes"
icculus@5961
    69
        make_ppc="$allow_ppc"
slouken@1636
    70
        make_x86="yes"
slouken@3248
    71
        make_x64="yes"
slouken@1636
    72
        merge="yes"
slouken@1636
    73
        ;;
slouken@1636
    74
    configure)
icculus@5961
    75
        configure_ppc="$allow_ppc"
slouken@1636
    76
        configure_x86="yes"
slouken@3248
    77
        configure_x64="yes"
slouken@1636
    78
        ;;
icculus@5961
    79
    configure-ppc)
icculus@5961
    80
        configure_ppc="$allow_ppc"
icculus@5961
    81
        ;;
slouken@1636
    82
    configure-x86)
slouken@1636
    83
        configure_x86="yes"
slouken@1636
    84
        ;;
slouken@3248
    85
    configure-x64)
slouken@3248
    86
        configure_x64="yes"
slouken@3248
    87
        ;;
slouken@1636
    88
    make)
icculus@5961
    89
        make_ppc="$allow_ppc"
slouken@1636
    90
        make_x86="yes"
slouken@3248
    91
        make_x64="yes"
slouken@1636
    92
        merge="yes"
slouken@1636
    93
        ;;
icculus@5961
    94
    make-ppc)
icculus@5961
    95
        make_ppc="$allow_ppc"
icculus@5961
    96
        ;;
slouken@1636
    97
    make-x86)
slouken@1636
    98
        make_x86="yes"
slouken@1636
    99
        ;;
slouken@3248
   100
    make-x64)
slouken@3248
   101
        make_x64="yes"
slouken@3248
   102
        ;;
slouken@1636
   103
    merge)
slouken@1636
   104
        merge="yes"
slouken@1636
   105
        ;;
slouken@1636
   106
    install)
slouken@1648
   107
        install_bin="yes"
slouken@1648
   108
        install_hdrs="yes"
slouken@1648
   109
        install_lib="yes"
slouken@1648
   110
        install_data="yes"
slouken@1648
   111
        ;;
slouken@1648
   112
    install-bin)
slouken@1648
   113
        install_bin="yes"
slouken@1648
   114
        ;;
slouken@1648
   115
    install-hdrs)
slouken@1648
   116
        install_hdrs="yes"
slouken@1648
   117
        ;;
slouken@1648
   118
    install-lib)
slouken@1648
   119
        install_lib="yes"
slouken@1648
   120
        ;;
slouken@1648
   121
    install-data)
slouken@1648
   122
        install_data="yes"
slouken@1648
   123
        ;;
icculus@1741
   124
    clean)
icculus@5961
   125
        clean_ppc="yes"
icculus@1741
   126
        clean_x86="yes"
slouken@3248
   127
        clean_x64="yes"
icculus@1741
   128
        ;;
icculus@5961
   129
    clean-ppc)
icculus@5961
   130
        clean_ppc="yes"
icculus@5961
   131
        ;;
icculus@1741
   132
    clean-x86)
icculus@1741
   133
        clean_x86="yes"
icculus@1741
   134
        ;;
slouken@3248
   135
    clean-x64)
slouken@3248
   136
        clean_x64="yes"
slouken@3248
   137
        ;;
slouken@1648
   138
    *)
icculus@5961
   139
        echo "Usage: $0 [all|configure[-ppc|-x86|-x64]|make[-ppc|-x86|-x64]|merge|install|clean[-ppc|-x86|-x64]]"
slouken@1648
   140
        exit 1
slouken@1648
   141
        ;;
slouken@1648
   142
esac
slouken@1648
   143
case `uname -p` in
slouken@1648
   144
    *86)
slouken@1648
   145
        native_path=x86
slouken@1648
   146
        ;;
icculus@5961
   147
    *powerpc)
icculus@5961
   148
        native_path=ppc
icculus@5961
   149
        ;;
slouken@3249
   150
    x86_64)
slouken@3249
   151
        native_path=x64
slouken@3249
   152
        ;;
slouken@1648
   153
    *)
slouken@1648
   154
        echo "Couldn't figure out native architecture path"
slouken@1648
   155
        exit 1
slouken@1636
   156
        ;;
slouken@1636
   157
esac
slouken@1636
   158
slouken@1636
   159
#
slouken@1636
   160
# Create the build directories
slouken@1636
   161
#
icculus@5961
   162
for dir in build build/ppc build/x86 build/x64; do
slouken@1636
   163
    if test -d $dir; then
slouken@1636
   164
        :
slouken@1636
   165
    else
slouken@1636
   166
        mkdir $dir || exit 1
slouken@1636
   167
    fi
slouken@1636
   168
done
slouken@1636
   169
icculus@5961
   170
icculus@5961
   171
#
icculus@5961
   172
# Build the PowerPC 32-bit binary
icculus@5961
   173
#
icculus@5961
   174
if test x$configure_ppc = xyes; then
icculus@5961
   175
    (cd build/ppc && \
icculus@5961
   176
     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
   177
fi
icculus@5961
   178
if test x$make_ppc = xyes; then
icculus@5961
   179
    (cd build/ppc && make -j$NJOB) || exit 3
icculus@5961
   180
fi
slouken@1636
   181
#
slouken@3248
   182
# Build the Intel 32-bit binary
slouken@1636
   183
#
slouken@1636
   184
if test x$configure_x86 = xyes; then
slouken@1636
   185
    (cd build/x86 && \
icculus@5961
   186
     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
   187
fi
slouken@1636
   188
if test x$make_x86 = xyes; then
slouken@1742
   189
    (cd build/x86 && make -j$NJOB) || exit 3
slouken@1636
   190
fi
slouken@1636
   191
slouken@1636
   192
#
icculus@5961
   193
# Build the Intel 64-bit binary
slouken@3248
   194
#
slouken@3248
   195
if test x$configure_x64 = xyes; then
slouken@3248
   196
    (cd build/x64 && \
icculus@5961
   197
     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
   198
fi
slouken@3248
   199
if test x$make_x64 = xyes; then
slouken@3248
   200
    (cd build/x64 && make -j$NJOB) || exit 3
slouken@3248
   201
fi
slouken@3248
   202
slouken@3248
   203
#
slouken@1636
   204
# Combine into fat binary
slouken@1636
   205
#
slouken@1636
   206
if test x$merge = xyes; then
slouken@1648
   207
    output=.libs
slouken@1648
   208
    sh $auxdir/mkinstalldirs build/$output
slouken@1648
   209
    cd build
slouken@3245
   210
    target=`find . -mindepth 4 -maxdepth 4 -type f -name '*.dylib' | head -1 | sed 's|.*/||'`
slouken@3245
   211
    (lipo -create -o $output/$target `find . -mindepth 4 -maxdepth 4 -type f -name "*.dylib"` &&
slouken@6276
   212
     ln -sf $target $output/libSDL2.dylib &&
slouken@6276
   213
     lipo -create -o $output/libSDL2.a */build/.libs/libSDL2.a &&
slouken@6276
   214
     cp $native_path/build/.libs/libSDL2.la $output &&
slouken@6276
   215
     cp $native_path/build/.libs/libSDL2.lai $output &&
slouken@6276
   216
     cp $native_path/build/libSDL2.la . &&
slouken@6276
   217
     lipo -create -o libSDL2main.a */build/libSDL2main.a &&
slouken@1636
   218
     echo "Build complete!" &&
slouken@1636
   219
     echo "Files can be found in the build directory.") || exit 4
slouken@1648
   220
    cd ..
slouken@1636
   221
fi
slouken@1636
   222
slouken@1636
   223
#
slouken@1636
   224
# Install
slouken@1636
   225
#
slouken@1648
   226
do_install()
slouken@1648
   227
{
slouken@1648
   228
    echo $*
slouken@1648
   229
    $* || exit 5
slouken@1648
   230
}
slouken@1648
   231
if test x$prefix = x; then
slouken@1648
   232
    prefix=/usr/local
slouken@1648
   233
fi
slouken@1648
   234
if test x$exec_prefix = x; then
slouken@1648
   235
    exec_prefix=$prefix
slouken@1648
   236
fi
slouken@1648
   237
if test x$bindir = x; then
slouken@1648
   238
    bindir=$exec_prefix/bin
slouken@1648
   239
fi
slouken@1648
   240
if test x$libdir = x; then
slouken@1648
   241
    libdir=$exec_prefix/lib
slouken@1648
   242
fi
slouken@1648
   243
if test x$includedir = x; then
slouken@1648
   244
    includedir=$prefix/include
slouken@1648
   245
fi
slouken@1648
   246
if test x$datadir = x; then
slouken@1648
   247
    datadir=$prefix/share
slouken@1648
   248
fi
slouken@1648
   249
if test x$mandir = x; then
slouken@1648
   250
    mandir=$prefix/man
slouken@1636
   251
fi
slouken@1648
   252
if test x$install_bin = xyes; then
slouken@1648
   253
    do_install sh $auxdir/mkinstalldirs $bindir
slouken@6276
   254
    do_install /usr/bin/install -c -m 755 build/$native_path/sdl2-config $bindir/sdl2-config
slouken@1648
   255
fi
slouken@1648
   256
if test x$install_hdrs = xyes; then
slouken@6276
   257
    do_install sh $auxdir/mkinstalldirs $includedir/SDL2
slouken@1648
   258
    for src in $srcdir/include/*.h; do \
slouken@1648
   259
        file=`echo $src | sed -e 's|^.*/||'`; \
slouken@6276
   260
        do_install /usr/bin/install -c -m 644 $src $includedir/SDL2/$file; \
slouken@1648
   261
    done
slouken@6276
   262
    do_install /usr/bin/install -c -m 644 $srcdir/include/SDL_config_macosx.h $includedir/SDL2/SDL_config.h
slouken@1648
   263
fi
slouken@1648
   264
if test x$install_lib = xyes; then
slouken@1648
   265
    do_install sh $auxdir/mkinstalldirs $libdir
slouken@6276
   266
    do_install sh build/$native_path/libtool --mode=install /usr/bin/install -c  build/libSDL2.la $libdir/libSDL2.la
slouken@6276
   267
    do_install /usr/bin/install -c -m 644 build/libSDL2main.a $libdir/libSDL2main.a
slouken@6276
   268
    do_install ranlib $libdir/libSDL2main.a
slouken@1648
   269
fi
slouken@1648
   270
if test x$install_data = xyes; then
slouken@1648
   271
    do_install sh $auxdir/mkinstalldirs $datadir/aclocal
slouken@6276
   272
    do_install /usr/bin/install -c -m 644 $srcdir/sdl2.m4 $datadir/aclocal/sdl2.m4
slouken@1648
   273
fi
icculus@1741
   274
icculus@1741
   275
#
icculus@1741
   276
# Clean up
icculus@1741
   277
#
icculus@1741
   278
do_clean()
icculus@1741
   279
{
icculus@1741
   280
    echo $*
icculus@1741
   281
    $* || exit 6
icculus@1741
   282
}
icculus@5961
   283
if test x$clean_ppc = xyes; then
icculus@5961
   284
    do_clean rm -r build/ppc
icculus@5961
   285
fi
icculus@1741
   286
if test x$clean_x86 = xyes; then
icculus@1741
   287
    do_clean rm -r build/x86
icculus@1741
   288
fi
slouken@5611
   289
if test x$clean_x64 = xyes; then
slouken@5611
   290
    do_clean rm -r build/x64
icculus@1741
   291
fi