support building a gcc as well

rename the project to osxcross
bump version to 0.4
This commit is contained in:
Thomas Pöchtrager 2013-11-11 21:04:21 +01:00
parent 3e81644303
commit 55ae02b117
10 changed files with 281 additions and 28 deletions

View File

@ -1,3 +1,6 @@
0.4:
- added: gcc support
0.3:
- added: SDK download links to README
- added: support 10.9 (Mavericks) SDK

6
README
View File

@ -1,9 +1,11 @@
- Oclang: OS X cross toolchain for linux -
- OSXCross: OS X cross toolchain for linux -
Oclang is a tool which helps you to cross compile source code easily with clang on linux for OS X.
OSXCross is a tool which helps you to cross compile source code easily with clang on linux for OS X.
After the installation you will have "o32-clang", "o32-clang++", "o64-clang" and "o64-clang++" available as compiler.
You can optionally build an update-to-date gcc as well, please see README.gcc.
Make sure you have the following installed on your linux-system:
Clang 3.2+, llvm-devel, automake, autogen, libtool,

17
README.gcc Normal file
View File

@ -0,0 +1,17 @@
- OSXCross: OS X cross toolchain for linux -
After finishing ./build.sh you can optionally build gcc as well.
Don't forget to run "source ~/.profile" after adding the target to your .bashrc or .profile,
or simply start a new shell session.
Then make sure you have got the build dependencies for gcc installed on your system,
see: http://gcc.gnu.org/install/prerequisites.html
On debian like systems you can run 'apt-get build-dep gcc' to install them.
After this edit GCC_VERSION and so on build_gcc.sh, so it fits your requirements, then finally
run ./build_gcc.sh to start building gcc.
If everything went well, then you'll have "x86_64-apple-darwinXX-gcc, i386-apple-darwinXX-g++" and so on
available as compiler.

View File

@ -13,14 +13,14 @@ SDK_VERSION=10.8
# Minimum targeted OS X version
# Must be <= SDK_VERSION
# You can comment this variable out,
# if you want to use clangs default value
# if you want to use the compilers default value
OSX_VERSION_MIN=10.5
# ld version
LINKER_VERSION=134.9
# Don't change this
OCLANG_VERSION=0.3
OSXCROSS_VERSION=0.4
function require
{
@ -60,7 +60,7 @@ case $SDK_VERSION in
esac
echo ""
echo "Building oclang, Version: $OCLANG_VERSION"
echo "Building OSXCross toolchain, Version: $OSXCROSS_VERSION"
echo ""
echo "OS X SDK Version: $SDK_VERSION, Target: $TARGET"
echo "Minimum targeted OS X Version: $OSX_VERSION_MIN"
@ -121,6 +121,7 @@ tar xzfv $TARBALL_DIR/xar*.tar.gz || exit 1
pushd cctools*
patch -p0 < $PATCH_DIR/ld64-1.patch || exit 1
patch -p0 < $PATCH_DIR/ld64-2.patch || exit 1
patch -p0 < $PATCH_DIR/ld64-3.patch || exit 1
patch -p0 < $PATCH_DIR/llvm-3.4.patch || exit 1
./autogen.sh
./configure --prefix=$TARGET_DIR --target=x86_64-apple-$TARGET || exit 1
@ -214,18 +215,24 @@ ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/i386-apple-$TARGET-clang++
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/x86_64-apple-$TARGET-clang
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/x86_64-apple-$TARGET-clang++
rm $TARGET_DIR/bin/oclang-conf 2>/dev/null
OSXCROSS_CONF="$TARGET_DIR/bin/osxcross-conf"
echo "#!/usr/bin/env bash" > $TARGET_DIR/bin/oclang-conf
echo "echo \"export OCLANG_VERSION=$OCLANG_VERSION\"" >> $TARGET_DIR/bin/oclang-conf
echo "echo \"export OCLANG_OSX_VERSION_MIN=$OSX_VERSION_MIN\"" >> $TARGET_DIR/bin/oclang-conf
echo "echo \"export OCLANG_TARGET=$TARGET\"" >> $TARGET_DIR/bin/oclang-conf
echo "echo \"export OCLANG_SDK_VERSION=$SDK_VERSION\"" >> $TARGET_DIR/bin/oclang-conf
echo "echo \"export OCLANG_SDK=$SDK_DIR/MacOSX$SDK_VERSION.sdk\"" >> $TARGET_DIR/bin/oclang-conf
echo "echo \"export OCLANG_CCTOOLS_PATH=$TARGET_DIR/bin\"" >> $TARGET_DIR/bin/oclang-conf
echo "echo \"export OCLANG_TARGET_OPTION=$CLANG_TARGET_OPTION\"" >> $TARGET_DIR/bin/oclang-conf
echo "echo \"export OCLANG_LINKER_VERSION=$LINKER_VERSION\"" >> $TARGET_DIR/bin/oclang-conf
chmod +x $TARGET_DIR/bin/oclang-conf
rm $OSXCROSS_CONF 2>/dev/null
echo "#!/usr/bin/env bash" > $OSXCROSS_CONF
echo "echo \"export OSXCROSS_VERSION=$OSXCROSS_VERSION\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_OSX_VERSION_MIN=$OSX_VERSION_MIN\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_TARGET=$TARGET\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_SDK_VERSION=$SDK_VERSION\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_SDK=$SDK_DIR/MacOSX$SDK_VERSION.sdk\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_TARBALL_DIR=$TARBALL_DIR\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_PATCH_DIR=$PATCH_DIR\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_TARGET_DIR=$TARGET_DIR\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_BUILD_DIR=$BUILD_DIR\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_CCTOOLS_PATH=$TARGET_DIR\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_TARGET_OPTION=$CLANG_TARGET_OPTION\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_LINKER_VERSION=$LINKER_VERSION\"" >> $OSXCROSS_CONF
chmod +x $OSXCROSS_CONF
function test_compiler
{

132
build_gcc.sh Executable file
View File

@ -0,0 +1,132 @@
#!/usr/bin/env bash
export LC_ALL="C"
export LIBRARY_PATH=""
which osxcross-conf || {
echo "you need to complete ./build.sh first, before you can start building gcc"
exit 1
}
eval `osxcross-conf`
set -e
# How many concurrent jobs should be used for compiling?
JOBS=`grep -c ^processor /proc/cpuinfo`
# 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
}
require wget
BASE_DIR=`pwd`
pushd $OSXCROSS_BUILD_DIR
if [ ! -f "have_gcc_${GCC_VERSION}" ]; then
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*
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
touch "have_gcc_${GCC_VERSION}"
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 ""

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
eval `oclang-conf`
eval `osxcross-conf`
type=`basename $0`
if [ "$type" != "${type/o64/}" ] || [ "$type" != "${type/x86_64/}" ]; then
@ -22,23 +22,23 @@ else
COMPILER="clang"
fi
if [ "$OCLANG_OSX_VERSION_MIN" != "default" ]; then
OSX_VERSION_MIN_OPT="-mmacosx-version-min=$OCLANG_OSX_VERSION_MIN"
if [ "$OSXCROSS_OSX_VERSION_MIN" != "default" ]; then
OSX_VERSION_MIN_OPT="-mmacosx-version-min=$OSXCROSS_OSX_VERSION_MIN"
else
OSX_VERSION_MIN_OPT=""
fi
export COMPILER_PATH="$OCLANG_CCTOOLS_PATH:${COMPILER_PATH}"
export COMPILER_PATH="$OSXCROSS_CCTOOLS_PATH:${COMPILER_PATH}"
STDINC=$OCLANG_SDK/usr/include
CPLUSINC1=$OCLANG_SDK/usr/lib/gcc/i686-apple-$OCLANG_TARGET/4.2.1/include
CPLUSINC2=$OCLANG_SDK/usr/include/c++/4.0.0
CPLUSINC3=$OCLANG_SDK/usr/include/c++/4.0.0/$ARCH2-apple-darwin9
TARGET=$ARCH1-apple-$OCLANG_TARGET
STDINC=$OSXCROSS_SDK/usr/include
CPLUSINC1=$OSXCROSS_SDK/usr/lib/gcc/i686-apple-$OSXCROSS_TARGET/4.2.1/include
CPLUSINC2=$OSXCROSS_SDK/usr/include/c++/4.0.0
CPLUSINC3=$OSXCROSS_SDK/usr/include/c++/4.0.0/$ARCH2-apple-darwin9
TARGET=$ARCH1-apple-$OSXCROSS_TARGET
$COMPILER $OCLANG_TARGET_OPTION $TARGET -isysroot $OCLANG_SDK \
$COMPILER $OSXCROSS_TARGET_OPTION $TARGET -isysroot $OSXCROSS_SDK \
-isystem $STDINC -isystem $CPLUSINC1 -isystem $CPLUSINC2 -isystem $CPLUSINC3 \
$OSX_VERSION_MIN_OPT -mlinker-version=$OCLANG_LINKER_VERSION $OCLANG_OPT_ARGS \
$OSX_VERSION_MIN_OPT -mlinker-version=$OSXCROSS_LINKER_VERSION $OSXCROSS_OPT_ARGS \
${1+"$@"}
exit $?

37
ogcc/ogcc Executable file
View File

@ -0,0 +1,37 @@
#!/usr/bin/env bash
eval `osxcross-conf`
type=`basename $0`
if [ "$type" != "${type/o64/}" ] || [ "$type" != "${type/x86_64/}" ]; then
ARCH1="x86_64"
ARCH2=$ARCH1
else
if [ "$type" != "${type/o32/}" ] || [ "$type" != "${type/i386/}" ]; then
ARCH1="i386"
ARCH2="i686"
else
echo "unknown arch"
exit 1
fi
fi
if [ "$type" != "${type/++/}" ]; then
COMPILER="$OSXCROSS_TARGET_DIR/bin/$ARCH1-apple-$OSXCROSS_TARGET-base-g++"
OSXCROSS_OPT_ARGS+=" -static-libgcc -static-libstdc++ -arch $ARCH1"
else
COMPILER="$OSXCROSS_TARGET_DIR/bin/$ARCH1-apple-$OSXCROSS_TARGET-base-gcc"
OSXCROSS_OPT_ARGS+=" -static-libgcc -arch $ARCH1"
fi
if [ "$OSXCROSS_OSX_VERSION_MIN" != "default" ]; then
OSX_VERSION_MIN_OPT="-mmacosx-version-min=$OSXCROSS_OSX_VERSION_MIN"
else
OSX_VERSION_MIN_OPT=""
fi
export COMPILER_PATH="$OSXCROSS_CCTOOLS_PATH:${COMPILER_PATH}"
$COMPILER $OSX_VERSION_MIN_OPT $OSXCROSS_OPT_ARGS ${1+"$@"}
exit $?

View File

@ -10,6 +10,6 @@ rm -rf tarballs/*MacOSX*
find . -name "*~" -exec rm {} \;
find . -name "*.save" -exec rm {} \;
rm -rf *.tar.xz
tar -cf - * | xz -9 -c - > $BASEDIR/oclang.tar.xz || exit 1
tar -cf - * | xz -9 -c - > $BASEDIR/osxcross.tar.xz || exit 1
popd
rm -rf $TMPDIR

View File

@ -0,0 +1,45 @@
diff -urN build/gcc-4.8.2/gcc/collect2.c /home/thomas/tmp/gcc-4.8.2/gcc/collect2.c
--- gcc/collect2.c 2013-06-20 19:12:17.000000000 +0200
+++ gcc/collect2.c 2013-11-11 20:08:35.355672907 +0100
@@ -3046,6 +3046,7 @@
}
#endif /* COLLECT_EXPORT_LIST */
+#undef COLLECT_RUN_DSYMUTIL
#ifdef COLLECT_RUN_DSYMUTIL
static int flag_dsym = false;
static int flag_idsym = false;
diff -urN build/gcc-4.8.2/gcc/config/darwin.h /home/thomas/tmp/gcc-4.8.2/gcc/config/darwin.h
--- gcc/config/darwin.h 2013-02-12 00:30:10.000000000 +0100
+++ gcc/config/darwin.h 2013-11-11 20:17:15.387653343 +0100
@@ -195,10 +195,13 @@
%{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm: \
%{gdwarf-2:%{!gstabs*:%{!g0: -dsym}}}}}}}}}}}"
+#undef DSYMUTIL_SPEC
+#define DSYMUTIL_SPEC ""
+
#define LINK_COMMAND_SPEC LINK_COMMAND_SPEC_A DSYMUTIL_SPEC
/* Tell collect2 to run dsymutil for us as necessary. */
-#define COLLECT_RUN_DSYMUTIL 1
+#define COLLECT_RUN_DSYMUTIL 0
/* We only want one instance of %G, since libSystem (Darwin's -lc) does not depend
on libgcc. */
diff -urN build/gcc-4.8.2/gcc/config/darwin9.h /home/thomas/tmp/gcc-4.8.2/gcc/config/darwin9.h
--- gcc/config/darwin9.h 2013-01-10 21:38:27.000000000 +0100
+++ gcc/config/darwin9.h 2013-11-11 20:23:12.619639903 +0100
@@ -32,8 +32,11 @@
%{.c|.cc|.C|.cpp|.cp|.c++|.cxx|.CPP|.m|.mm|.s|.f|.f90|.f95|.f03|.f77|.for|.F|.F90|.F95|.F03: \
%{g*:%{!gstabs*:%{!g0: -dsym}}}}}}}}}}}"
+#undef DSYMUTIL_SPEC
+#define DSYMUTIL_SPEC ""
+
/* Tell collect2 to run dsymutil for us as necessary. */
-#define COLLECT_RUN_DSYMUTIL 1
+#define COLLECT_RUN_DSYMUTIL 0
#undef PIE_SPEC
#define PIE_SPEC \

10
patches/ld64-3.patch Normal file
View File

@ -0,0 +1,10 @@
--- ld64/src/ld/parsers/macho_relocatable_file.cpp 2013-11-11 20:31:31.178808527 +0100
+++ ld64/src/ld/parsers/macho_relocatable_file.cpp 2013-11-11 20:31:39.126808228 +0100
@@ -3709,6 +3709,7 @@
template <typename A>
void CFISection<A>::warnFunc(void* ref, uint64_t funcAddr, const char* msg)
{
+ return;
Parser<A>* parser = (Parser<A>*)ref;
if ( ! parser->convertUnwindInfo() )
return;