2013-11-12 00:04:21 +04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
export LC_ALL="C"
|
|
|
|
export LIBRARY_PATH=""
|
|
|
|
|
2013-11-12 21:14:54 +04:00
|
|
|
export CC=clang
|
|
|
|
export CXX=clang++
|
|
|
|
|
2013-11-14 23:28:27 +04:00
|
|
|
which osxcross-conf &>/dev/null || {
|
2013-11-12 00:04:21 +04:00
|
|
|
echo "you need to complete ./build.sh first, before you can start building gcc"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2013-11-14 23:28:27 +04:00
|
|
|
eval `osxcross-conf`
|
|
|
|
|
2013-11-12 00:04:21 +04:00
|
|
|
# How many concurrent jobs should be used for compiling?
|
2013-11-12 21:18:17 +04:00
|
|
|
JOBS=`grep -c ^processor /proc/cpuinfo`
|
2013-11-12 00:04:21 +04:00
|
|
|
|
|
|
|
# GCC version to build
|
|
|
|
GCC_VERSION=4.8.2
|
|
|
|
|
|
|
|
# GCC mirror
|
|
|
|
GCC_MIRROR="ftp://ftp.gwdg.de/pub/misc/gcc/releases"
|
|
|
|
|
|
|
|
function require
|
|
|
|
{
|
|
|
|
which $1 &>/dev/null
|
|
|
|
while [ $? -ne 0 ]
|
|
|
|
do
|
|
|
|
echo ""
|
|
|
|
read -p "Install $1 then press enter"
|
|
|
|
which $1 &>/dev/null
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2013-11-14 23:28:27 +04:00
|
|
|
set +e
|
2013-11-12 00:04:21 +04:00
|
|
|
require wget
|
2013-11-14 23:28:27 +04:00
|
|
|
set -e
|
2013-11-12 00:04:21 +04:00
|
|
|
|
|
|
|
BASE_DIR=`pwd`
|
|
|
|
|
|
|
|
pushd $OSXCROSS_BUILD_DIR
|
|
|
|
|
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
|
|
|
|
|
|
|
pushd $OSXCROSS_TARBALL_DIR
|
|
|
|
wget -c "$GCC_MIRROR/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.bz2"
|
|
|
|
popd
|
|
|
|
|
|
|
|
rm -rf gcc* 2>/dev/null
|
|
|
|
|
|
|
|
echo "extracting gcc ..."
|
|
|
|
tar xf "$OSXCROSS_TARBALL_DIR/gcc-$GCC_VERSION.tar.bz2"
|
|
|
|
|
|
|
|
pushd gcc*$GCC_VERSION*
|
|
|
|
|
2013-11-16 21:36:44 +04:00
|
|
|
rm -f $OSXCROSS_TARGET_DIR/bin/*-gcc*
|
|
|
|
rm -f $OSXCROSS_TARGET_DIR/bin/*-g++*
|
|
|
|
|
2013-11-12 00:04:21 +04:00
|
|
|
patch -p0 < $OSXCROSS_PATCH_DIR/gcc-dsymutil.patch
|
|
|
|
|
|
|
|
mkdir -p build
|
|
|
|
pushd build
|
|
|
|
|
|
|
|
../configure \
|
|
|
|
--target=x86_64-apple-$OSXCROSS_TARGET \
|
|
|
|
--with-ld=$OSXCROSS_TARGET_DIR/bin/x86_64-apple-$OSXCROSS_TARGET-ld \
|
|
|
|
--with-as=$OSXCROSS_TARGET_DIR/bin/x86_64-apple-$OSXCROSS_TARGET-as \
|
|
|
|
--with-sysroot=$OSXCROSS_SDK \
|
|
|
|
--disable-nls \
|
|
|
|
--enable-languages=c,c++,objc,obj-c++ \
|
|
|
|
--without-headers \
|
|
|
|
--enable-multilib \
|
|
|
|
--enable-lto \
|
|
|
|
--prefix=$OSXCROSS_TARGET_DIR
|
|
|
|
|
|
|
|
make -j$JOBS
|
|
|
|
make install -j$JOBS
|
|
|
|
|
|
|
|
popd #build
|
|
|
|
popd #gcc
|
|
|
|
|
2013-11-16 21:36:44 +04:00
|
|
|
touch "have_gcc_${GCC_VERSION}_${OSXCROSS_TARGET}"
|
2013-11-12 00:04:21 +04:00
|
|
|
|
|
|
|
fi #have gcc
|
|
|
|
|
|
|
|
popd #build dir
|
|
|
|
|
|
|
|
cp ogcc/ogcc $OSXCROSS_TARGET_DIR/bin
|
|
|
|
|
|
|
|
pushd $OSXCROSS_TARGET_DIR/bin
|
|
|
|
|
|
|
|
if [ ! -f $OSXCROSS_TARGET_DIR/bin/i386-apple-$OSXCROSS_TARGET-base-gcc ]; then
|
|
|
|
mv x86_64-apple-$OSXCROSS_TARGET-gcc x86_64-apple-$OSXCROSS_TARGET-base-gcc
|
|
|
|
mv x86_64-apple-$OSXCROSS_TARGET-g++ x86_64-apple-$OSXCROSS_TARGET-base-g++
|
|
|
|
|
|
|
|
ln -sf x86_64-apple-$OSXCROSS_TARGET-base-gcc i386-apple-$OSXCROSS_TARGET-base-gcc
|
|
|
|
ln -sf x86_64-apple-$OSXCROSS_TARGET-base-g++ i386-apple-$OSXCROSS_TARGET-base-g++
|
|
|
|
fi
|
|
|
|
|
|
|
|
ln -sf ogcc o32-gcc
|
|
|
|
ln -sf ogcc o32-g++
|
|
|
|
ln -sf ogcc o64-gcc
|
|
|
|
ln -sf ogcc o64-g++
|
|
|
|
|
|
|
|
ln -sf ogcc i386-apple-$OSXCROSS_TARGET-gcc
|
|
|
|
ln -sf ogcc i386-apple-$OSXCROSS_TARGET-g++
|
|
|
|
ln -sf ogcc x86_64-apple-$OSXCROSS_TARGET-gcc
|
|
|
|
ln -sf ogcc x86_64-apple-$OSXCROSS_TARGET-g++
|
|
|
|
|
|
|
|
popd #target dir / bin
|
|
|
|
|
|
|
|
function test_compiler
|
|
|
|
{
|
|
|
|
echo -ne "testing $1 ... "
|
|
|
|
$1 $2 -O2 -Wall -o test && rm test
|
|
|
|
echo "works"
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ""
|