2013-11-12 00:04:21 +04:00
|
|
|
#!/usr/bin/env bash
|
2017-01-18 12:47:13 +03:00
|
|
|
#
|
|
|
|
# Build and install gcc/gcc++ as a cross-compiler with target OSX,
|
|
|
|
# using `clang`.
|
|
|
|
#
|
|
|
|
# You may want to run this script if you want to build software using
|
|
|
|
# gcc. Please refer to the README.md for details.
|
|
|
|
#
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2013-12-15 22:06:50 +04:00
|
|
|
pushd "${0%/*}" &>/dev/null
|
|
|
|
|
2014-03-25 02:11:25 +04:00
|
|
|
unset LIBRARY_PATH
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2013-12-17 00:53:21 +04:00
|
|
|
DESC=gcc
|
2014-07-18 00:43:29 +04:00
|
|
|
USESYSTEMCOMPILER=1
|
2013-12-17 00:53:21 +04:00
|
|
|
source tools/tools.sh
|
2013-11-12 21:14:54 +04:00
|
|
|
|
2015-07-20 22:13:36 +03:00
|
|
|
eval $(tools/osxcross_conf.sh)
|
2013-12-15 22:06:50 +04:00
|
|
|
|
2013-11-12 00:04:21 +04:00
|
|
|
# GCC version to build
|
2013-12-15 22:06:50 +04:00
|
|
|
# (<4.7 will not work properly with libc++)
|
2014-10-01 21:53:41 +04:00
|
|
|
if [ -z "$GCC_VERSION" ]; then
|
2018-12-07 15:12:36 +03:00
|
|
|
GCC_VERSION=8.2.0
|
2014-10-01 21:53:41 +04:00
|
|
|
#GCC_VERSION=5-20140928 # snapshot
|
|
|
|
fi
|
2013-11-12 00:04:21 +04:00
|
|
|
|
|
|
|
# GCC mirror
|
2014-04-22 23:17:15 +04:00
|
|
|
GCC_MIRROR="ftp://ftp.fu-berlin.de/unix/languages/gcc"
|
2013-11-12 00:04:21 +04:00
|
|
|
|
|
|
|
require wget
|
|
|
|
|
2013-12-17 00:53:21 +04:00
|
|
|
pushd $OSXCROSS_BUILD_DIR &>/dev/null
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2013-12-17 00:53:21 +04:00
|
|
|
function remove_locks()
|
|
|
|
{
|
2014-04-06 17:58:15 +04:00
|
|
|
rm -rf $OSXCROSS_BUILD_DIR/have_gcc*
|
2013-12-17 00:53:21 +04:00
|
|
|
}
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2013-12-17 00:53:21 +04:00
|
|
|
source $BASE_DIR/tools/trap_exit.sh
|
2013-12-15 22:06:50 +04:00
|
|
|
|
2013-11-16 21:36:44 +04:00
|
|
|
if [ ! -f "have_gcc_${GCC_VERSION}_${OSXCROSS_TARGET}" ]; then
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2013-12-17 00:53:21 +04:00
|
|
|
pushd $OSXCROSS_TARBALL_DIR &>/dev/null
|
2014-04-22 21:34:08 +04:00
|
|
|
if [[ $GCC_VERSION != *-* ]]; then
|
2017-08-14 00:42:37 +03:00
|
|
|
wget -c "$GCC_MIRROR/releases/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.gz"
|
2014-04-22 21:34:08 +04:00
|
|
|
else
|
2017-08-14 00:42:37 +03:00
|
|
|
wget -c "$GCC_MIRROR/snapshots/$GCC_VERSION/gcc-$GCC_VERSION.tar.gz"
|
2014-04-22 21:34:08 +04:00
|
|
|
fi
|
2013-12-17 00:53:21 +04:00
|
|
|
popd &>/dev/null
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2013-12-15 22:06:50 +04:00
|
|
|
echo "cleaning up ..."
|
2013-11-12 00:04:21 +04:00
|
|
|
rm -rf gcc* 2>/dev/null
|
|
|
|
|
2017-08-14 00:42:37 +03:00
|
|
|
extract "$OSXCROSS_TARBALL_DIR/gcc-$GCC_VERSION.tar.gz" 1
|
2014-03-25 02:11:25 +04:00
|
|
|
echo ""
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2013-12-17 00:53:21 +04:00
|
|
|
pushd gcc*$GCC_VERSION* &>/dev/null
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2013-11-16 21:36:44 +04:00
|
|
|
rm -f $OSXCROSS_TARGET_DIR/bin/*-gcc*
|
|
|
|
rm -f $OSXCROSS_TARGET_DIR/bin/*-g++*
|
|
|
|
|
2015-10-04 19:58:46 +03:00
|
|
|
if [ $(osxcross-cmp $GCC_VERSION '>' 5.0.0) == 1 ] &&
|
|
|
|
[ $(osxcross-cmp $GCC_VERSION '<' 5.3.0) == 1 ]; then
|
|
|
|
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66035
|
|
|
|
patch -p1 < $PATCH_DIR/gcc-pr66035.patch
|
|
|
|
fi
|
|
|
|
|
2017-08-14 00:42:37 +03:00
|
|
|
if [ $(osxcross-cmp $GCC_VERSION '>=' 6.1.0) == 1 ] &&
|
|
|
|
[ $(osxcross-cmp $GCC_VERSION '<=' 6.3.0) == 1 ]; then
|
|
|
|
# https://gcc.gnu.org/ml/gcc-patches/2016-09/msg00129.html
|
|
|
|
patch -p1 < $PATCH_DIR/gcc-6-buildfix.patch
|
|
|
|
fi
|
|
|
|
|
2017-01-28 12:24:46 +03:00
|
|
|
if [ $(osxcross-cmp $GCC_VERSION '==' 6.3.0) == 1 ]; then
|
2017-08-14 00:42:37 +03:00
|
|
|
# https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/config/darwin-driver.c?r1=244010&r2=244009&pathrev=244010
|
|
|
|
patch -p1 < $PATCH_DIR/darwin-driver.c.patch
|
2017-01-28 12:24:46 +03:00
|
|
|
fi
|
|
|
|
|
2013-11-12 00:04:21 +04:00
|
|
|
mkdir -p build
|
2013-12-17 00:53:21 +04:00
|
|
|
pushd build &>/dev/null
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2014-04-14 23:59:03 +04:00
|
|
|
if [[ $PLATFORM == *BSD ]]; then
|
2014-04-06 17:58:15 +04:00
|
|
|
export CPATH="/usr/local/include:/usr/pkg/include:$CPATH"
|
|
|
|
export LDFLAGS="-L/usr/local/lib -L/usr/pkg/lib $LDFLAGS"
|
|
|
|
export LD_LIBRARY_PATH="/usr/local/lib:/usr/pkg/lib:$LD_LIBRARY_PATH"
|
2014-04-14 23:59:03 +04:00
|
|
|
elif [ "$PLATFORM" == "Darwin" ]; then
|
|
|
|
export CPATH="/opt/local/include:$CPATH"
|
|
|
|
export LDFLAGS="-L/opt/local/lib $LDFLAGS"
|
|
|
|
export LD_LIBRARY_PATH="/opt/local/lib:$LD_LIBRARY_PATH"
|
|
|
|
fi
|
|
|
|
|
|
|
|
EXTRACONFFLAGS=""
|
|
|
|
|
|
|
|
if [ "$PLATFORM" != "Darwin" ]; then
|
|
|
|
EXTRACONFFLAGS+="--with-ld=$OSXCROSS_TARGET_DIR/bin/x86_64-apple-$OSXCROSS_TARGET-ld "
|
|
|
|
EXTRACONFFLAGS+="--with-as=$OSXCROSS_TARGET_DIR/bin/x86_64-apple-$OSXCROSS_TARGET-as "
|
2013-12-15 22:06:50 +04:00
|
|
|
fi
|
|
|
|
|
2014-10-01 21:53:41 +04:00
|
|
|
LANGS="c,c++,objc,obj-c++"
|
|
|
|
|
|
|
|
if [ -n "$ENABLE_FORTRAN" ]; then
|
|
|
|
LANGS+=",fortran"
|
|
|
|
fi
|
|
|
|
|
2013-11-12 00:04:21 +04:00
|
|
|
../configure \
|
2014-04-06 17:58:15 +04:00
|
|
|
--target=x86_64-apple-$OSXCROSS_TARGET \
|
|
|
|
--with-sysroot=$OSXCROSS_SDK \
|
|
|
|
--disable-nls \
|
2014-10-01 21:53:41 +04:00
|
|
|
--enable-languages=$LANGS \
|
2014-04-06 17:58:15 +04:00
|
|
|
--without-headers \
|
|
|
|
--enable-multilib \
|
2014-07-18 00:02:41 +04:00
|
|
|
--with-multilib-list=m32,m64 \
|
2014-04-06 17:58:15 +04:00
|
|
|
--enable-lto \
|
|
|
|
--enable-checking=release \
|
2014-07-18 00:02:41 +04:00
|
|
|
--disable-libstdcxx-pch \
|
2014-04-14 23:59:03 +04:00
|
|
|
--prefix=$OSXCROSS_TARGET_DIR \
|
2014-07-18 00:02:41 +04:00
|
|
|
--with-system-zlib \
|
2014-04-14 23:59:03 +04:00
|
|
|
$EXTRACONFFLAGS
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2013-12-15 22:06:50 +04:00
|
|
|
$MAKE -j$JOBS
|
2014-04-23 00:40:05 +04:00
|
|
|
$MAKE install
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2014-04-22 23:17:15 +04:00
|
|
|
GCC_VERSION=`echo $GCC_VERSION | tr '-' ' ' | awk '{print $1}'`
|
2014-04-23 21:31:49 +04:00
|
|
|
|
|
|
|
pushd $OSXCROSS_TARGET_DIR/x86_64-apple-$OSXCROSS_TARGET/include &>/dev/null
|
|
|
|
pushd c++/${GCC_VERSION}* &>/dev/null
|
|
|
|
|
|
|
|
cat $OSXCROSS_TARGET_DIR/../patches/libstdcxx.patch | \
|
2015-07-19 23:28:10 +03:00
|
|
|
$SED "s/darwin13/$OSXCROSS_TARGET/g" | \
|
2014-04-23 21:31:49 +04:00
|
|
|
patch -p0 -l &>/dev/null || true
|
|
|
|
|
|
|
|
popd &>/dev/null
|
|
|
|
popd &>/dev/null
|
2014-04-22 23:17:15 +04:00
|
|
|
|
2013-12-17 00:53:21 +04:00
|
|
|
popd &>/dev/null # build
|
|
|
|
popd &>/dev/null # gcc
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2013-11-16 21:36:44 +04:00
|
|
|
touch "have_gcc_${GCC_VERSION}_${OSXCROSS_TARGET}"
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2013-12-17 00:53:21 +04:00
|
|
|
fi # have gcc
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2013-12-17 00:53:21 +04:00
|
|
|
popd &>/dev/null # build dir
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2014-07-18 00:43:29 +04:00
|
|
|
unset USESYSTEMCOMPILER
|
|
|
|
source tools/tools.sh
|
|
|
|
|
2014-04-07 00:27:59 +04:00
|
|
|
pushd $OSXCROSS_TARGET_DIR/bin &>/dev/null
|
2013-12-15 22:06:50 +04:00
|
|
|
|
2016-10-29 20:26:05 +03:00
|
|
|
if [ ! -f i386-apple-$OSXCROSS_TARGET-base-gcc$EXESUFFIX ]; then
|
|
|
|
mv x86_64-apple-$OSXCROSS_TARGET-gcc$EXESUFFIX \
|
|
|
|
x86_64-apple-$OSXCROSS_TARGET-base-gcc$EXESUFFIX
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2016-10-29 20:26:05 +03:00
|
|
|
mv x86_64-apple-$OSXCROSS_TARGET-g++$EXESUFFIX \
|
|
|
|
x86_64-apple-$OSXCROSS_TARGET-base-g++$EXESUFFIX
|
|
|
|
|
|
|
|
create_symlink x86_64-apple-$OSXCROSS_TARGET-base-gcc$EXESUFFIX \
|
|
|
|
i386-apple-$OSXCROSS_TARGET-base-gcc$EXESUFFIX
|
|
|
|
|
|
|
|
create_symlink x86_64-apple-$OSXCROSS_TARGET-base-g++$EXESUFFIX \
|
|
|
|
i386-apple-$OSXCROSS_TARGET-base-g++$EXESUFFIX
|
2013-11-12 00:04:21 +04:00
|
|
|
fi
|
|
|
|
|
2014-04-07 00:27:59 +04:00
|
|
|
echo "compiling wrapper ..."
|
2013-12-15 22:06:50 +04:00
|
|
|
|
2014-04-17 22:51:16 +04:00
|
|
|
export OSXCROSS_VERSION
|
|
|
|
export OSXCROSS_LIBLTO_PATH
|
2014-04-22 21:34:08 +04:00
|
|
|
export OSXCROSS_TARGET
|
|
|
|
export OSXCROSS_OSX_VERSION_MIN=$OSXCROSS_OSX_VERSION_MIN
|
|
|
|
export OSXCROSS_LINKER_VERSION=$OSXCROSS_LINKER_VERSION
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2014-04-07 00:27:59 +04:00
|
|
|
TARGETCOMPILER=gcc \
|
|
|
|
$BASE_DIR/wrapper/build.sh 1>/dev/null
|
2013-11-12 00:04:21 +04:00
|
|
|
|
2013-12-17 00:53:21 +04:00
|
|
|
popd &>/dev/null # wrapper dir
|
2013-11-12 00:04:21 +04:00
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
test_compiler o32-gcc $BASE_DIR/oclang/test.c
|
|
|
|
test_compiler o64-gcc $BASE_DIR/oclang/test.c
|
|
|
|
|
|
|
|
test_compiler o32-g++ $BASE_DIR/oclang/test.cpp
|
|
|
|
test_compiler o64-g++ $BASE_DIR/oclang/test.cpp
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
echo "Done! Now you can use o32-gcc/o32-g++ and o64-gcc/o64-g++ as compiler"
|
|
|
|
echo ""
|
|
|
|
echo "Example usage:"
|
|
|
|
echo ""
|
|
|
|
echo "Example 1: CC=o32-gcc ./configure --host=i386-apple-$OSXCROSS_TARGET"
|
|
|
|
echo "Example 2: CC=i386-apple-$OSXCROSS_TARGET-gcc ./configure --host=i386-apple-$OSXCROSS_TARGET"
|
|
|
|
echo "Example 3: o64-gcc -Wall test.c -o test"
|
|
|
|
echo "Example 4: x86_64-apple-$OSXCROSS_TARGET-strip -x test"
|
|
|
|
echo ""
|