gcc-fat.sh
author Ozkan Sezer <sezeroz@gmail.com>
Sat, 13 Oct 2018 15:02:56 +0300
changeset 596 4b70bfe18fb7
parent 382 0940479cefdb
permissions -rwxr-xr-x
fix build against libpng-1.5.x versions.
slouken@131
     1
#!/bin/sh
slouken@131
     2
#
slouken@131
     3
# Build Universal binaries on Mac OS X, thanks Ryan!
slouken@131
     4
#
slouken@274
     5
# Usage: ./configure CC="sh gcc-fat.sh" && make && rm -rf x86 x64
slouken@198
     6
slouken@382
     7
DEVELOPER="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer"
slouken@382
     8
slouken@382
     9
# Intel 32-bit compiler flags (10.6 runtime compatibility)
slouken@382
    10
GCC_COMPILE_X86="gcc -arch i386 -mmacosx-version-min=10.6 \
slouken@131
    11
-DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
slouken@382
    12
-I/usr/local/include"
slouken@131
    13
slouken@382
    14
GCC_LINK_X86="-mmacosx-version-min=10.6"
slouken@131
    15
slouken@382
    16
# Intel 64-bit compiler flags (10.6 runtime compatibility)
slouken@382
    17
GCC_COMPILE_X64="gcc -arch x86_64 -mmacosx-version-min=10.6 \
slouken@198
    18
-DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
slouken@382
    19
-I/usr/local/include"
slouken@198
    20
slouken@382
    21
GCC_LINK_X64="-mmacosx-version-min=10.6"
slouken@198
    22
slouken@131
    23
# Output both PowerPC and Intel object files
slouken@131
    24
args="$*"
slouken@131
    25
compile=yes
slouken@131
    26
link=yes
slouken@131
    27
while test x$1 != x; do
slouken@131
    28
    case $1 in
slouken@131
    29
        --version) exec gcc $1;;
slouken@131
    30
        -v) exec gcc $1;;
slouken@131
    31
        -V) exec gcc $1;;
slouken@131
    32
        -print-prog-name=*) exec gcc $1;;
slouken@131
    33
        -print-search-dirs) exec gcc $1;;
slouken@274
    34
        -E) GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
slouken@198
    35
            GCC_COMPILE_X64="$GCC_COMPILE_X64 -E"
slouken@131
    36
            compile=no; link=no;;
slouken@131
    37
        -c) link=no;;
slouken@131
    38
        -o) output=$2;;
slouken@134
    39
        *.c|*.cc|*.cpp|*.S) source=$1;;
slouken@131
    40
    esac
slouken@131
    41
    shift
slouken@131
    42
done
slouken@131
    43
if test x$link = xyes; then
slouken@131
    44
    GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
slouken@198
    45
    GCC_COMPILE_X64="$GCC_COMPILE_X64 $GCC_LINK_X64"
slouken@131
    46
fi
slouken@131
    47
if test x"$output" = x; then
slouken@131
    48
    if test x$link = xyes; then
slouken@131
    49
        output=a.out
slouken@131
    50
    elif test x$compile = xyes; then
slouken@134
    51
        output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
slouken@131
    52
    fi
slouken@131
    53
fi
slouken@131
    54
slouken@198
    55
# Compile X86 32-bit
slouken@131
    56
if test x"$output" != x; then
slouken@131
    57
    dir=x86/`dirname $output`
slouken@131
    58
    if test -d $dir; then
slouken@131
    59
        :
slouken@131
    60
    else
slouken@131
    61
        mkdir -p $dir
slouken@131
    62
    fi
slouken@131
    63
fi
slouken@131
    64
set -- $args
slouken@131
    65
while test x$1 != x; do
slouken@132
    66
    if test -f "x86/$1" && test "$1" != "$output"; then
slouken@131
    67
        x86_args="$x86_args x86/$1"
slouken@131
    68
    else
slouken@131
    69
        x86_args="$x86_args $1"
slouken@131
    70
    fi
slouken@131
    71
    shift
slouken@131
    72
done
slouken@131
    73
$GCC_COMPILE_X86 $x86_args || exit $?
slouken@131
    74
if test x"$output" != x; then
slouken@131
    75
    cp $output x86/$output
slouken@131
    76
fi
slouken@131
    77
slouken@198
    78
# Compile X86 32-bit
slouken@131
    79
if test x"$output" != x; then
slouken@198
    80
    dir=x64/`dirname $output`
slouken@198
    81
    if test -d $dir; then
slouken@198
    82
        :
slouken@198
    83
    else
slouken@198
    84
        mkdir -p $dir
slouken@198
    85
    fi
slouken@131
    86
fi
slouken@198
    87
set -- $args
slouken@198
    88
while test x$1 != x; do
slouken@198
    89
    if test -f "x64/$1" && test "$1" != "$output"; then
slouken@198
    90
        x64_args="$x64_args x64/$1"
slouken@198
    91
    else
slouken@198
    92
        x64_args="$x64_args $1"
slouken@198
    93
    fi
slouken@198
    94
    shift
slouken@198
    95
done
slouken@198
    96
$GCC_COMPILE_X64 $x64_args || exit $?
slouken@198
    97
if test x"$output" != x; then
slouken@198
    98
    cp $output x64/$output
slouken@198
    99
fi
slouken@198
   100
slouken@198
   101
if test x"$output" != x; then
slouken@274
   102
    lipo -create -o $output x86/$output x64/$output
slouken@198
   103
fi