add libc++ build script

update README with libc++ build instructions and samples
fix mavericks SDK download link (pointed to 10.8)
build xar only for <=10.5
add -g0 to the clang invocation command to avoid dsymutil from being run (debugging is not supported, but I guess you don't want to debug the resulting binaries anyway if you build them on a non OS X system)
attempt to make the toolchain less path dependent (gcc still breaks though, because of hardcoded paths), but clang and cctools can be moved now
update cctools to 845
add DISABLE_LTO_SUPPORT option (DISABLE_LTO_SUPPORT=1 ./build.sh) to disable linking against libLTO.so
add support for 32 bit systems
add FreeBSD support
update PACKAGE script
This commit is contained in:
Thomas Pöchtrager 2013-12-15 19:06:50 +01:00
parent b62b01644f
commit 2a4842f3cc
21 changed files with 724 additions and 210 deletions

View File

@ -1,5 +1,10 @@
0.5: 0.5:
- fixed: help clang to find its own intrinsic headers (this issue appears to be fixed in clang 3.4+) - fixed: help clang to find its own intrinsic headers (this issue appears to be fixed in clang 3.4+)
- changed: attempt to make the toolchain less path dependent
- fixed: building the toolchain on 32 bit systems
- added: libc++ support (for both, clang and gcc)
- changed: update cctools to 845
- added: FreeBSD support
0.4: 0.4:
- added: gcc support - added: gcc support

View File

@ -1,27 +1,24 @@
## OSXCross: OS X cross toolchain for Linux ## ## OS X Cross toolchain for Linux and FreeBSD ##
### WHAT IS THE GOAL OF OSXCROSS? ### ### WHAT IS THE GOAL OF OSXCROSS? ###
The goal of OSXCross is to deliver you a high quality cross toolchain targeting OS X on Linux. The goal of OSXCross is to provide a well working OS X cross toolchain for Linux and FreeBSD.
### HOW DOES IT WORK? ### ### HOW DOES IT WORK? ###
[Clang/LLVM is a cross compiler by default](http://clang.llvm.org/docs/CrossCompilation.html) and is now available on nearly every Linux distribution. [Clang/LLVM is a cross compiler by default](http://clang.llvm.org/docs/CrossCompilation.html) and is now available on nearly every Linux distribution.
Therefore we "just" need a proper Therefore we "just" need a proper
[port](https://code.google.com/p/ios-toolchain-based-on-clang-for-linux/source/browse/#svn%2Ftrunk%2Fcctools-porting%2Fpatches) [port](https://github.com/tpoechtrager/cctools-port)
of the [cctools](http://www.opensource.apple.com/tarballs/cctools) (ld, lipo, ...) for Linux, and the OS X SDK. of the [cctools](http://www.opensource.apple.com/tarballs/cctools) (ld, lipo, ...) for Linux, and the OS X SDK.
If you want, then you can build an up-to-date vanilla GCC as well. If you want, then you can build an up-to-date vanilla GCC as well.
### WHAT IS NOT WORKING (YET)? ### ### WHAT IS NOT WORKING (YET)? ###
* Clang: * Debug info is weak, because of the [missing](https://github.com/tpoechtrager/osxcross/blob/master/patches/gcc-dsymutil.patch)
* using [libc++](http://libcxx.llvm.org/) (`-stdlib=libc++`) doesn't work yet (missing headers, besides that it should work)
* GCC:
* debug info is weak, because of the [missing](https://github.com/tpoechtrager/osxcross/blob/master/patches/gcc-dsymutil.patch)
[`dsymutil`](http://www.manpagez.com/man/1/dsymutil) (shows only function names, no line numbers) [`dsymutil`](http://www.manpagez.com/man/1/dsymutil) (shows only function names, no line numbers)
* GCC itself [doesn't build with GCC](https://github.com/tpoechtrager/osxcross/commit/12f5dcdde4bc1000180d25ffda229f0a13cf723d), * GCC itself [doesn't build with GCC](https://github.com/tpoechtrager/osxcross/commit/12f5dcdde4bc1000180d25ffda229f0a13cf723d),
but builds fine when clang is used to build GCC but builds fine when clang is used to build GCC
Everything else besides that should work. Everything else besides that should work.
@ -36,22 +33,32 @@ Download the SDK version (links below) you want to the tarball/ (important!) dir
Then assure you have the following installed on your Linux box: Then assure you have the following installed on your Linux box:
`Clang 3.2+`, `llvm-devel`, `automake`, `autogen`, `libtool`, `Clang 3.2+`, `llvm-devel`, `automake`, `autogen`, `libtool`,
`libxml2-devel`, `uuid-devel`, `openssl-devel` and the `bash shell`. `libxml2-devel` (<=10.5 only), `uuid-devel`, `openssl-devel` and the `bash shell`.
Hint: On Ubuntu 12.04 LTS you can use [llvm.org/apt](http://llvm.org/apt) to get a newer version of clang.
Now edit the `SDK_VERSION` in `build.sh`, so it matches the version you have downloaded before. Now edit the `SDK_VERSION` in `build.sh`, so it matches the version you have downloaded before.
Then run `./build.sh` to build the cross toolchain (It will build in it's own directory). Then run `./build.sh` to build the cross toolchain (It will build in it's own directory).
**Don't forget** to add the printed `export PATH=...` to your `~/.profile` or `~/.bashrc`. **Don't forget** to add the printed `` `<path>/osxcross-env` `` to your `~/.profile` or `~/.bashrc`.
Then either run `source ~/.profile` or restart your shell session. Then either run `source ~/.profile` or restart your shell session.
That's it. See Usage Examples below. That's it. See usage examples below.
##### Building libc++: #####
If you want to build libc++ for modern C++11 with clang, then you can do this by running `./build_libcxx.sh`.
The resulting library will be linked statically into the applications, to avoid troubles with different
libc++.dylib versions on OS X.
See below in how to use libc++ as the standard library.
##### Building GCC: ##### ##### Building GCC: #####
If you want to build GCC as well, then you can do this by running `./build_gcc.sh`. If you want to build GCC as well, then you can do this by running `./build_gcc.sh`.
But before you do this, make sure you have got the gcc build depedencies installed on your system, But before you do this, make sure you have got the gcc build depedencies installed on your system,
on debian like systems you can run `apt-get build-dep gcc` to install them. on debian like systems you can run `apt-get install mpc-dev mpfr-dev gmp-dev` to install them.
### SDK DOWNLOAD LINKS: ### ### SDK DOWNLOAD LINKS: ###
@ -83,6 +90,25 @@ You can use the shortcut `o32-...` or `i386-apple-darwin...` what ever you like
* `CC=o32-clang CXX=o32-clang++ ./configure --host=i386-apple-darwinXX` * `CC=o32-clang CXX=o32-clang++ ./configure --host=i386-apple-darwinXX`
##### Building test.cpp with libc++: #####
* Clang:
* C++98: `o32-clang++ -stdlib=libc++ test.cpp -o test`
* C++11: `o32-clang++ -stdlib=libc++ -std=c++11 tes1.cpp -o test`
* C++1y: `o32-clang++ -stdlib=libc++ -std=c++1y test1.cpp -o test`
* Clang (shortcut):
* C++98: `o32-clang++-libc++ test.cpp -o test`
* C++11: `o32-clang++-libc++ -std=c++11 test.cpp -o test`
* C++1y: `o32-clang++-libc++ -std=c++1y test.cpp -o test`
* GCC (defaults to C++11 with libc++)
* C++11: `o32-g++-libc++ test.cpp`
* C++1y: `o32-g++-libc++ -std=c++1y test.cpp -o test`
##### Building test1.cpp and test2.cpp with LTO (Link Time Optimization): ##### ##### Building test1.cpp and test2.cpp with LTO (Link Time Optimization): #####
* build the first object file: `o32-clang++ test1.cpp -O3 -flto -c` * build the first object file: `o32-clang++ test1.cpp -O3 -flto -c`
@ -91,7 +117,7 @@ You can use the shortcut `o32-...` or `i386-apple-darwin...` what ever you like
##### Building a universal binary: ##### ##### Building a universal binary: #####
* clang: * Clang:
* `o64-clang++ test.cpp -O3 -arch i386 -arch x86_64 -o test` * `o64-clang++ test.cpp -O3 -arch i386 -arch x86_64 -o test`
* GCC: * GCC:
* build the 32 bit binary: `o32-g++ test.cpp -O3 -o test.i386` * build the 32 bit binary: `o32-g++ test.cpp -O3 -o test.i386`

1
TODO
View File

@ -1,2 +1 @@
report the __block issue in unistd.h to the maintainers report the __block issue in unistd.h to the maintainers
optional libc++ support (low priority)

160
build.sh
View File

@ -7,7 +7,7 @@ export CC=clang
export CXX=clang++ export CXX=clang++
# How many concurrent jobs should be used for compiling? # How many concurrent jobs should be used for compiling?
JOBS=`grep -c ^processor /proc/cpuinfo` JOBS=`tools/get_cpu_count.sh` || exit 1
# SDK version to use # SDK version to use
SDK_VERSION=10.8 SDK_VERSION=10.8
@ -47,7 +47,7 @@ if [ $JOBS -eq 1 ]; then
JOBSSTR="job" JOBSSTR="job"
fi fi
if [ "$OSX_VERSION_MIN" == "" ]; then if [ -z "$OSX_VERSION_MIN" ]; then
OSX_VERSION_MIN="default" OSX_VERSION_MIN="default"
fi fi
@ -72,7 +72,6 @@ echo "Tarball Directory: $TARBALL_DIR"
echo "Build Directory: $BUILD_DIR" echo "Build Directory: $BUILD_DIR"
echo "Install Directory: $TARGET_DIR" echo "Install Directory: $TARGET_DIR"
echo "SDK Install Directory: $SDK_DIR" echo "SDK Install Directory: $SDK_DIR"
echo "Compile with $JOBS concurrent $JOBSSTR"
echo "" echo ""
read -p "Press enter to start building" read -p "Press enter to start building"
echo "" echo ""
@ -97,35 +96,44 @@ require automake
require libtool require libtool
set -e set -e
CLANG_TARGET_OPTION=`./oclang/check_clang_target_option.sh` CLANG_TARGET_OPTION=`./oclang/check_target_option.sh`
pushd $BUILD_DIR pushd $BUILD_DIR
if [ ! -f "have_cctools_$TARGET" ]; then trap 'test $? -eq 0 || rm -f $BUILD_DIR/have_cctools*' EXIT
tar xzfv $TARBALL_DIR/cctools-*.tar.gz if [ "`ls $TARBALL_DIR/cctools*.tar.* | wc -l | tr -d ' '`" != "1" ]; then
echo ""
echo "There should only be one cctools*.tar.* archive in the tarballs directory"
echo ""
exit 1
fi
CCTOOLS_REVHASH=`ls $TARBALL_DIR/cctools*.tar.* | \
tr '_' ' ' | tr '.' ' ' | \
awk '{print $3}'`
if [ ! -f "have_cctools_${CCTOOLS_REVHASH}_$TARGET" ]; then
rm -rf cctools*
rm -rf xar*
tar xJfv $TARBALL_DIR/cctools*.tar.xz
tar xzfv $TARBALL_DIR/xar*.tar.gz tar xzfv $TARBALL_DIR/xar*.tar.gz
pushd cctools* pushd cctools*/cctools
patch -p0 < $PATCH_DIR/cctools-ld64-1.patch patch -p0 < $PATCH_DIR/cctools-ld64-1.patch
patch -p0 < $PATCH_DIR/cctools-ld64-2.patch patch -p0 < $PATCH_DIR/cctools-ld64-2.patch
patch -p0 < $PATCH_DIR/cctools-ld64-3.patch patch -p0 < $PATCH_DIR/cctools-ld64-3.patch
patch -p0 < $PATCH_DIR/cctools-conf-1.patch
patch -p0 < $PATCH_DIR/cctools-llvm-lto.patch
CF=$CFLAGS CXXF=$CXXFLAGS LF=$LDFLAGS
eval `$BASE_DIR/oclang/find_lto_header.sh`
set +e
grep -n "__block," /usr/include/unistd.h &>/dev/null
if [ $? -eq 0 ]; then
echo "applying workaround for buggy unistd.h"
$PATCH_DIR/fix-unistd-issue.sh
fi
set -e
./autogen.sh ./autogen.sh
echo ""
echo "if you see automake warnings, ignore them"
echo "automake 1.14+ is supposed to print a lot of warnings"
echo ""
./configure --prefix=$TARGET_DIR --target=x86_64-apple-$TARGET ./configure --prefix=$TARGET_DIR --target=x86_64-apple-$TARGET
make -j$JOBS make -j$JOBS
make install -j$JOBS make install -j$JOBS
export CFLAGS=$CF CXXFLAGS=$CXXF LDFLAGS=$LF popd
pushd $TARGET_DIR/bin pushd $TARGET_DIR/bin
CCTOOLS=`find . -name "x86_64-apple-darwin*"` CCTOOLS=`find . -name "x86_64-apple-darwin*"`
@ -136,14 +144,25 @@ for CCTOOL in ${CCTOOLS[@]}; do
done done
popd popd
popd fi # have cctools
if [ ! -f "have_xar_$TARGET" ]; then
if [ -n "$FORCE_XAR_BUILD" ] || [ `echo "$SDK_VERSION<=10.5" | bc -l` -eq 1 ]; then
pushd xar* pushd xar*
set +e
sed -i 's/-Wall/-w/g' configure
set -e
./configure --prefix=$TARGET_DIR ./configure --prefix=$TARGET_DIR
make -j$JOBS make -j$JOBS
make install -j$JOBS make install -j$JOBS
popd popd
fi # SDK <= 10.5
fi # have xar
if [ ! -f "have_cctools_$TARGET" ]; then
function check function check
{ {
[ -f "/$TARGET_DIR/bin/$1-apple-$TARGET-lipo" ] || exit 1 [ -f "/$TARGET_DIR/bin/$1-apple-$TARGET-lipo" ] || exit 1
@ -157,7 +176,7 @@ function check
check i386 check i386
check x86_64 check x86_64
touch "have_cctools_$TARGET" touch "have_cctools_${CCTOOLS_REVHASH}_$TARGET"
fi # HAVE_CCTOOLS fi # HAVE_CCTOOLS
@ -184,6 +203,7 @@ echo "extracting $SDK_FILENAME ..."
case $SDK in case $SDK in
*.pkg) *.pkg)
which xar &>/dev/null || { echo "please build with: FORCE_XAR_BUILD=1 ./build.sh" && exit 1; }
xar -xf $SDK xar -xf $SDK
cat Payload | gunzip -dc | cpio -i 2>/dev/null cat Payload | gunzip -dc | cpio -i 2>/dev/null
;; ;;
@ -207,44 +227,86 @@ popd
popd popd
cp -f oclang/oclang $TARGET_DIR/bin WRAPPER=$TARGET_DIR/bin/x86_64-apple-$TARGET-oclang
cp -f oclang/oclang $WRAPPER
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/o32-clang WRAPPER_SCRIPT=`basename $WRAPPER`
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/o32-clang++ WRAPPER_DIR=`dirname $WRAPPER`
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/o64-clang
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/o64-clang++
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/i386-apple-$TARGET-clang pushd $WRAPPER_DIR
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 $WRAPPER_SCRIPT o32-clang
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/x86_64-apple-$TARGET-clang++ ln -sf $WRAPPER_SCRIPT o32-clang++
ln -sf $WRAPPER_SCRIPT o32-clang++-libc++
ln -sf $WRAPPER_SCRIPT o64-clang
ln -sf $WRAPPER_SCRIPT o64-clang++
ln -sf $WRAPPER_SCRIPT o64-clang++-libc++
ln -sf $WRAPPER_SCRIPT i386-apple-$TARGET-clang
ln -sf $WRAPPER_SCRIPT i386-apple-$TARGET-clang++
ln -sf $WRAPPER_SCRIPT i386-apple-$TARGET-clang++-libc++
ln -sf $WRAPPER_SCRIPT x86_64-apple-$TARGET-clang
ln -sf $WRAPPER_SCRIPT x86_64-apple-$TARGET-clang++
ln -sf $WRAPPER_SCRIPT x86_64-apple-$TARGET-clang++-libc++
popd
OSXCROSS_CONF="$TARGET_DIR/bin/osxcross-conf" OSXCROSS_CONF="$TARGET_DIR/bin/osxcross-conf"
OSXCROSS_ENV="$TARGET_DIR/bin/osxcross-env"
rm -f $OSXCROSS_CONF 2>/dev/null rm -f $OSXCROSS_CONF $ENV_CONF
echo "#!/usr/bin/env bash" > $OSXCROSS_CONF
echo "" >> $OSXCROSS_CONF
echo "pushd \"\${0%/*}\" &>/dev/null" >> $OSXCROSS_CONF
echo "" >> $OSXCROSS_CONF
echo "DIR=\`pwd\`" >> $OSXCROSS_CONF
echo "OSXCROSS_ROOT=\$DIR/../.." >> $OSXCROSS_CONF
echo "" >> $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=\$DIR/../`basename $SDK_DIR`/MacOSX$SDK_VERSION.sdk\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_TARBALL_DIR=\$OSXCROSS_ROOT/`basename $TARBALL_DIR`\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_PATCH_DIR=\$OSXCROSS_ROOT/`basename $PATCH_DIR`\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_TARGET_DIR=\$OSXCROSS_ROOT/`basename $TARGET_DIR`\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_BUILD_DIR=\$OSXCROSS_ROOT/`basename $BUILD_DIR`\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_CCTOOLS_PATH=\$DIR\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_TARGET_OPTION=$CLANG_TARGET_OPTION\"" >> $OSXCROSS_CONF
echo "echo \"export OSXCROSS_LINKER_VERSION=$LINKER_VERSION\"" >> $OSXCROSS_CONF
echo "" >> $OSXCROSS_CONF
echo "popd &>/dev/null" >> $OSXCROSS_CONF
echo "" >> $OSXCROSS_CONF
if [ -f "$BUILD_DIR/cctools*/cctools/tmp/ldpath" ]; then
LIB_PATH="`cat $BUILD_DIR/cctools*/cctools/tmp/ldpath`"
else
LIB_PATH=""
fi
echo "#!/bin/sh" > $OSXCROSS_ENV
echo "" >> $OSXCROSS_ENV
echo "BDIR=\`readlink -f \\\`dirname \$0\\\`\`" >> $OSXCROSS_ENV
echo "" >> $OSXCROSS_ENV
echo "echo \"export PATH=\$PATH:\$BDIR\"" >> $OSXCROSS_ENV
echo "echo \"export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:\$BDIR/../lib${LIB_PATH}"\" >> $OSXCROSS_ENV
chmod +x $OSXCROSS_CONF $OSXCROSS_ENV
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/bin\"" >> $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 function test_compiler
{ {
echo -ne "testing $1 ... " echo -ne "testing $1 ... "
$1 $2 -O2 -Wall -o test && rm test $1 $2 -O2 -Wall -o test
rm test
echo "works" echo "works"
} }
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:`cat $BUILD_DIR/cctools*/cctools/tmp/ldpath`" # libLTO.so
echo "" echo ""
test_compiler o32-clang $BASE_DIR/oclang/test.c test_compiler o32-clang $BASE_DIR/oclang/test.c
@ -254,11 +316,11 @@ test_compiler o32-clang++ $BASE_DIR/oclang/test.cpp
test_compiler o64-clang++ $BASE_DIR/oclang/test.cpp test_compiler o64-clang++ $BASE_DIR/oclang/test.cpp
echo "" echo ""
echo "Now add" echo "Now add the following line"
echo "" echo ""
echo "export PATH=\$PATH:$TARGET_DIR/bin" echo "\`$OSXCROSS_ENV\`"
echo "" echo ""
echo "to your ~/.bashrc or ~/.profile" echo "to your ~/.bashrc or ~/.profile (including the '\`')"
echo "" echo ""
echo "Done! Now you can use o32-clang(++) and o64-clang(++) like a normal compiler" echo "Done! Now you can use o32-clang(++) and o64-clang(++) like a normal compiler"

View File

@ -1,24 +1,27 @@
#!/usr/bin/env bash #!/usr/bin/env bash
pushd "${0%/*}" &>/dev/null
export LC_ALL="C" export LC_ALL="C"
export LIBRARY_PATH="" export LIBRARY_PATH=""
export CC=clang export CC=clang
export CXX=clang++ export CXX=clang++
which osxcross-conf &>/dev/null || { `tools/osxcross_conf.sh`
if [ $? -ne 0 ]; then
echo "you need to complete ./build.sh first, before you can start building gcc" echo "you need to complete ./build.sh first, before you can start building gcc"
exit 1 exit 1
} fi
set -e set -e
eval `osxcross-conf`
# How many concurrent jobs should be used for compiling? # How many concurrent jobs should be used for compiling?
JOBS=`grep -c ^processor /proc/cpuinfo` JOBS=`tools/get_cpu_count.sh`
# GCC version to build # GCC version to build
# (<4.7 will not work properly with libc++)
GCC_VERSION=4.8.2 GCC_VERSION=4.8.2
# GCC mirror # GCC mirror
@ -43,12 +46,15 @@ BASE_DIR=`pwd`
pushd $OSXCROSS_BUILD_DIR pushd $OSXCROSS_BUILD_DIR
trap 'test $? -eq 0 || rm -f $OSXCROSS_BUILD_DIR/have_gcc*' EXIT
if [ ! -f "have_gcc_${GCC_VERSION}_${OSXCROSS_TARGET}" ]; then if [ ! -f "have_gcc_${GCC_VERSION}_${OSXCROSS_TARGET}" ]; then
pushd $OSXCROSS_TARBALL_DIR pushd $OSXCROSS_TARBALL_DIR
wget -c "$GCC_MIRROR/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.bz2" wget -c "$GCC_MIRROR/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.bz2"
popd popd
echo "cleaning up ..."
rm -rf gcc* 2>/dev/null rm -rf gcc* 2>/dev/null
echo "extracting gcc ..." echo "extracting gcc ..."
@ -64,6 +70,18 @@ patch -p0 < $OSXCROSS_PATCH_DIR/gcc-dsymutil.patch
mkdir -p build mkdir -p build
pushd build pushd build
if [ "`uname -s`" == "FreeBSD" ]; then
export CPATH="/usr/local/include"
export LIBRARY_PATH="/usr/local/lib"
MAKE=gmake
IS_FREEBSD=1
else
MAKE=make
IS_FREEBSD=0
fi
require $MAKE
../configure \ ../configure \
--target=x86_64-apple-$OSXCROSS_TARGET \ --target=x86_64-apple-$OSXCROSS_TARGET \
--with-ld=$OSXCROSS_TARGET_DIR/bin/x86_64-apple-$OSXCROSS_TARGET-ld \ --with-ld=$OSXCROSS_TARGET_DIR/bin/x86_64-apple-$OSXCROSS_TARGET-ld \
@ -76,8 +94,12 @@ pushd build
--enable-lto \ --enable-lto \
--prefix=$OSXCROSS_TARGET_DIR --prefix=$OSXCROSS_TARGET_DIR
make -j$JOBS if [ $IS_FREEBSD -eq 1 ]; then
make install -j$JOBS export LIBRARY_PATH=""
fi
$MAKE -j$JOBS
$MAKE install -j$JOBS
popd #build popd #build
popd #gcc popd #gcc
@ -88,11 +110,15 @@ fi #have gcc
popd #build dir popd #build dir
cp ogcc/ogcc $OSXCROSS_TARGET_DIR/bin WRAPPER=$OSXCROSS_TARGET_DIR/bin/x86_64-apple-${OSXCROSS_TARGET}-ogcc
cp ogcc/ogcc $WRAPPER
pushd $OSXCROSS_TARGET_DIR/bin WRAPPER_SCRIPT=`basename $WRAPPER`
WRAPPER_DIR=`dirname $WRAPPER`
if [ ! -f $OSXCROSS_TARGET_DIR/bin/i386-apple-$OSXCROSS_TARGET-base-gcc ]; then pushd $WRAPPER_DIR
if [ ! -f 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-gcc x86_64-apple-$OSXCROSS_TARGET-base-gcc
mv x86_64-apple-$OSXCROSS_TARGET-g++ x86_64-apple-$OSXCROSS_TARGET-base-g++ mv x86_64-apple-$OSXCROSS_TARGET-g++ x86_64-apple-$OSXCROSS_TARGET-base-g++
@ -100,22 +126,29 @@ if [ ! -f $OSXCROSS_TARGET_DIR/bin/i386-apple-$OSXCROSS_TARGET-base-gcc ]; then
ln -sf x86_64-apple-$OSXCROSS_TARGET-base-g++ i386-apple-$OSXCROSS_TARGET-base-g++ ln -sf x86_64-apple-$OSXCROSS_TARGET-base-g++ i386-apple-$OSXCROSS_TARGET-base-g++
fi fi
ln -sf ogcc o32-gcc ln -sf $WRAPPER_SCRIPT o32-gcc
ln -sf ogcc o32-g++ ln -sf $WRAPPER_SCRIPT o32-g++
ln -sf ogcc o64-gcc ln -sf $WRAPPER_SCRIPT o32-g++-libc++
ln -sf ogcc o64-g++
ln -sf ogcc i386-apple-$OSXCROSS_TARGET-gcc ln -sf $WRAPPER_SCRIPT o64-gcc
ln -sf ogcc i386-apple-$OSXCROSS_TARGET-g++ ln -sf $WRAPPER_SCRIPT o64-g++
ln -sf ogcc x86_64-apple-$OSXCROSS_TARGET-gcc ln -sf $WRAPPER_SCRIPT o64-g++-libc++
ln -sf ogcc x86_64-apple-$OSXCROSS_TARGET-g++
popd #target dir / bin ln -sf $WRAPPER_SCRIPT i386-apple-$OSXCROSS_TARGET-gcc
ln -sf $WRAPPER_SCRIPT i386-apple-$OSXCROSS_TARGET-g++
ln -sf $WRAPPER_SCRIPT i386-apple-$OSXCROSS_TARGET-g++-libc++
ln -sf $WRAPPER_SCRIPT x86_64-apple-$OSXCROSS_TARGET-gcc
ln -sf $WRAPPER_SCRIPT x86_64-apple-$OSXCROSS_TARGET-g++
ln -sf $WRAPPER_SCRIPT x86_64-apple-$OSXCROSS_TARGET-g++-libc++
popd #wrapper dir
function test_compiler function test_compiler
{ {
echo -ne "testing $1 ... " echo -ne "testing $1 ... "
$1 $2 -O2 -Wall -o test && rm test $1 $2 -O2 -Wall -o test
rm test
echo "works" echo "works"
} }

168
build_libcxx.sh Executable file
View File

@ -0,0 +1,168 @@
#!/usr/bin/env bash
pushd "${0%/*}" &>/dev/null
export LC_ALL="C"
`tools/osxcross_conf.sh`
if [ $? -ne 0 ]; then
echo "you need to complete ./build.sh first, before you can start building libc++"
exit 1
fi
set -e
eval `osxcross-conf`
if [ `echo "${OSXCROSS_SDK_VERSION}<10.7" | bc -l` -eq 1 ]; then
echo "you must use the SDK from 10.7 or newer to get libc++ compiled"
exit 1
fi
# How many concurrent jobs should be used for compiling?
JOBS=`tools/get_cpu_count.sh`
# libc++ version to build
LIBCXX_VERSION=3.3
function require
{
which $1 &>/dev/null
while [ $? -ne 0 ]
do
echo ""
read -p "Install $1 then press enter"
which $1 &>/dev/null
done
}
BASE_DIR=`pwd`
set +e
require wget
require cmake
set -e
pushd $OSXCROSS_BUILD_DIR
trap 'test $? -eq 0 || rm -f $OSXCROSS_BUILD_DIR/have_libcxx*' EXIT
if [ ! -f "have_libcxx_${LIBCXX_VERSION}_${OSXCROSS_TARGET}" ]; then
pushd $OSXCROSS_TARBALL_DIR
wget -c "http://llvm.org/releases/3.3/libcxx-${LIBCXX_VERSION}.src.tar.gz"
popd
tar xzfv "$OSXCROSS_TARBALL_DIR/libcxx-${LIBCXX_VERSION}.src.tar.gz"
pushd libcxx-${LIBCXX_VERSION}*
rm -rf build
mkdir build
pushd build
# remove conflicting versions
rm -rf $OSXCROSS_SDK/usr/include/c++/v1
rm -rf $OSXCROSS_SDK/usr/lib/libc++.dylib
rm -rf $OSXCROSS_SDK/usr/lib/libc++.*.dylib
function cmakeerror()
{
echo -e "\e[1m"
echo "It looks like CMake failed."
echo "If you see something like:"
echo -e "\e[31m"
echo "CMake Error at /usr/share/cmake-2.8/Modules/Platform/Darwin.cmake:<LINE NUMBER> (list):"
echo " list sub-command REMOVE_DUPLICATES requires list to be present."
echo -e "\e[0m\e[1m"
echo "Then either remove this line (look for the LINE NUMBER) or comment it out (with #) in /usr/share/cmake-.../Modules/Platform/Darwin.cmake"
echo "It appears to be a bug in CMake."
echo ""
echo "Then re-run this script."
echo -e "\e[0m"
exit 1
}
cmake .. \
-DCMAKE_CXX_COMPILER=x86_64-apple-$OSXCROSS_TARGET-clang++ \
-DCMAKE_C_COMPILER=x86_64-apple-$OSXCROSS_TARGET-clang \
-DCMAKE_SYSTEM_NAME=Darwin \
-DCMAKE_OSX_SYSROOT=$OSXCROSS_SDK \
-DLIBCXX_ENABLE_SHARED=No \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$OSXCROSS_SDK/../libcxx_$OSXCROSS_SDK_VERSION \
-DCMAKE_AR=$OSXCROSS_CCTOOLS_PATH/x86_64-apple-$OSXCROSS_TARGET-ar \
-DCMAKE_RANLIB=$OSXCROSS_CCTOOLS_PATH/x86_64-apple-$OSXCROSS_TARGET-ranlib \
-DCMAKE_CXX_FLAGS="-arch i386 -arch x86_64" || cmakeerror
make -j$JOBS
make install -j$JOBS
popd #build
popd #libcxx
touch "have_libcxx_${LIBCXX_VERSION}_${OSXCROSS_TARGET}"
fi #have libcxx
popd #build dir
function test_compiler_clang
{
echo -ne "testing $2 -stdlib=libc++ ... "
$1 $3 -O2 -stdlib=libc++ -std=c++11 -Wall -o test
rm test
echo "ok"
}
function test_compiler_gcc
{
echo -ne "testing $2 ... "
$1 $3 -O2 -std=c++0x -Wall -o test
rm test
echo "ok"
}
HAVE_GCC=0
echo ""
echo "testing libc++ (including a lot c++11 headers + linking a small test program)"
echo ""
test_compiler_clang i386-apple-$OSXCROSS_TARGET-clang++ o32-clang++ $BASE_DIR/oclang/test_libcxx.cpp
test_compiler_clang x86_64-apple-$OSXCROSS_TARGET-clang++ o64-clang++ $BASE_DIR/oclang/test_libcxx.cpp
which i386-apple-$OSXCROSS_TARGET-g++-libc++ &>/dev/null && \
HAVE_GCC=1 \
test_compiler_gcc i386-apple-$OSXCROSS_TARGET-g++-libc++ o32-g++-libc++ $BASE_DIR/oclang/test_libcxx.cpp
which x86_64-apple-$OSXCROSS_TARGET-g++-libc++ &>/dev/null && \
HAVE_GCC=1 && \
test_compiler_gcc x86_64-apple-$OSXCROSS_TARGET-g++-libc++ o64-g++-libc++ $BASE_DIR/oclang/test_libcxx.cpp
echo ""
echo "Done!"
echo ""
echo "Example usage:"
echo ""
if [ $HAVE_GCC -eq 1 ]; then
echo "Clang:"
echo ""
fi
echo "Example 1: o32-clang++ -stdlib=libc++ -Wall test.cpp -o test"
echo "Example 2: o64-clang++ -stdlib=libc++ -std=c++11 -Wall test.cpp"
echo "Example 3: o32-clang++-libc++ -Wall test.cpp -o test"
echo "Example 4: o64-clang++-libc++ -std=c++11 -Wall test.cpp -o test"
echo "Example 5: x86_64-apple-$OSXCROSS_TARGET-clang++-libc++ -Wall test.cpp -o test"
echo "Example 6: i386-apple-$OSXCROSS_TARGET-clang++-libc++ -std=c++11 -Wall test.cpp -o test"
echo ""
if [ $HAVE_GCC -eq 1 ]; then
echo "GCC:"
echo ""
echo "Example 1: o32-g++-libc++ -Wall test.cpp -o test"
echo "Example 2: o64-g++-libc++ -std=c++1y -Wall test.cpp -o test"
echo "Example 3: x86_64-apple-$OSXCROSS_TARGET-g++-libc++ -Wall test.cpp -o test"
echo "Example 4: i386-apple-$OSXCROSS_TARGET-g++-libc++ -std=c++1y -Wall test.cpp -o test"
echo ""
fi

View File

@ -17,14 +17,17 @@ CLANG_DIR=`dirname \`which clang\``
CLANG_INTRIN_DIR="$CLANG_DIR/../include/clang/$CLANG_VERSION/include" CLANG_INTRIN_DIR="$CLANG_DIR/../include/clang/$CLANG_VERSION/include"
test ! -e "$CLANG_INTRIN_DIR" && CLANG_INTRIN_DIR="$CLANG_DIR/../lib/clang/$CLANG_VERSION/include" test ! -e "$CLANG_INTRIN_DIR" && CLANG_INTRIN_DIR="$CLANG_DIR/../lib/clang/$CLANG_VERSION/include"
test ! -e "$CLANG_INTRIN_DIR" && CLANG_INTRIN_DIR="$CLANG_DIR/../include/clang/$CLANG_VERSION/include"
test ! -e "$CLANG_INTRIN_DIR" && CLANG_INTRIN_DIR="$CLANG_DIR/../include/clang/$CLANG_VERSION"
test -e "$CLANG_INTRIN_DIR" || { echo "can not find clang intrinsics directory" && exit 1; } test -e "$CLANG_INTRIN_DIR" || { echo "can not find clang intrinsics directory" && exit 1; }
test -f "$CLANG_INTRIN_DIR/xmmintrin.h" || { echo "xmmintrin.h does not exist in $CLANG_INTRIN_DIR" && exit 1; } test -f "$CLANG_INTRIN_DIR/xmmintrin.h" || { echo "xmmintrin.h does not exist in $CLANG_INTRIN_DIR" && exit 1; }
echo "found clang intrinsic headers: $CLANG_INTRIN_DIR" echo "found clang intrinsic headers: $CLANG_INTRIN_DIR"
ln -sf $CLANG_INTRIN_DIR/float.h $SDK_DIR/usr/include test -f $CLANG_INTRIN_DIR/float.h && ln -sf $CLANG_INTRIN_DIR/float.h $SDK_DIR/usr/include
ln -sf $CLANG_INTRIN_DIR/stdarg.h $SDK_DIR/usr/include test -f $CLANG_INTRIN_DIR/stdarg.h && ln -sf $CLANG_INTRIN_DIR/stdarg.h $SDK_DIR/usr/include
ln -sf $CLANG_INTRIN_DIR/*intrin*.h $SDK_DIR/usr/include ln -sf $CLANG_INTRIN_DIR/*intrin*.h $SDK_DIR/usr/include
ln -sf $CLANG_INTRIN_DIR/mm*.h $SDK_DIR/usr/include ln -sf $CLANG_INTRIN_DIR/mm*.h $SDK_DIR/usr/include
ln -sf $CLANG_INTRIN_DIR/*va*.h $SDK_DIR/usr/include ln -sf $CLANG_INTRIN_DIR/*va*.h $SDK_DIR/usr/include

View File

@ -1,13 +1,17 @@
#!/usr/bin/env bash #!/usr/bin/env bash
eval `osxcross-conf` pushd "${0%/*}" &>/dev/null
eval `./osxcross-env`
eval `./osxcross-conf`
popd &>/dev/null
type=`basename $0` type=`basename $0`
if [ "$type" != "${type/o64/}" ] || [ "$type" != "${type/x86_64/}" ]; then if [ $type != "${type/o64/}" ] || [ $type != "${type/x86_64/}" ]; then
ARCH1="x86_64" ARCH1="x86_64"
ARCH2=$ARCH1 ARCH2=$ARCH1
else else
if [ "$type" != "${type/o32/}" ] || [ "$type" != "${type/i386/}" ]; then if [ $type != "${type/o32/}" ] || [ $type != "${type/i386/}" ]; then
ARCH1="i386" ARCH1="i386"
ARCH2="i686" ARCH2="i686"
else else
@ -16,45 +20,90 @@ else
fi fi
fi fi
if [ "$type" != "${type/++/}" ]; then if [ $type != "${type/++/}" ]; then
COMPILER="clang++" COMPILER="clang++"
else else
COMPILER="clang" COMPILER="clang"
fi fi
if [ $COMPILER == "clang++" ] && [ "$type" != "${type/libc++/}" ]; then
USE_LIBCXX=1
else
USE_LIBCXX=0
fi
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
for p in "$@" for p in "$@"
do do
if [[ "$p" == -mmacosx-version-min=* ]]; then if [[ "$p" == -mmacosx-version-min=* ]]; then
OSXCROSS_OSX_VERSION_MIN="default" OSXCROSS_OSX_VERSION_MIN="default"
break
MIN_TARGET_VERSION=`echo "$p" | tr '=' ' ' | tr '.' ' ' | awk '{printf "%d %d", $2, $3}'`
MIN_TARGET_VERSION_MAJOR=`echo $MIN_TARGET_VERSION | awk '{print $1}'`
MIN_TARGET_VERSION_MINOR=`echo $MIN_TARGET_VERSION | awk '{print $2}'`
if [ $MIN_TARGET_VERSION_MAJOR -ge 10 ] && [ $MIN_TARGET_VERSION_MINOR -ge 9 ]; then
# default to libc++ on >= 10.9
USE_LIBCXX=1
fi
fi fi
if [ "$p" == "-stdlib=libc++" ]; then
USE_LIBCXX=2
fi
# if [[ "$p" == -g* ]] && [ "$p" != "-g0" ] && [ "$p" != "-ggdb0" ]; then
# echo -e "\e[1mosxcross \e[35mwarning:\e[0m\e[1m replacing '$p' with '-g0'\e[0m" 1>&2
# fi
done done
fi fi
if [ "$OSXCROSS_OSX_VERSION_MIN" != "default" ]; then if [ $OSXCROSS_OSX_VERSION_MIN != "default" ]; then
OSX_VERSION_MIN_OPT="-mmacosx-version-min=$OSXCROSS_OSX_VERSION_MIN" OSX_VERSION_MIN_OPT="-mmacosx-version-min=$OSXCROSS_OSX_VERSION_MIN"
else else
OSX_VERSION_MIN_OPT="" OSX_VERSION_MIN_OPT=""
fi fi
export COMPILER_PATH="$OSXCROSS_CCTOOLS_PATH:${COMPILER_PATH}" export COMPILER_PATH="$OSXCROSS_CCTOOLS_PATH:$COMPILER_PATH"
STDINC=$OSXCROSS_SDK/usr/include 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 if [ $USE_LIBCXX -ne 0 ]; then
CPLUSINC3=$OSXCROSS_SDK/usr/include/c++/4.0.0/$ARCH2-apple-darwin9 if [ ! -f "$OSXCROSS_SDK/../libcxx_$OSXCROSS_SDK_VERSION/lib/libc++.a" ]; then
echo -e "\e[1mosxcross \e[31merror:\e[0m\e[1m you must build libc++ before you can use it (./build_libcxx.sh)\e[0m" 1>&2
exit 1
fi
CPLUSINC="-nostdinc++ -cxx-isystem $OSXCROSS_SDK/../libcxx_$OSXCROSS_SDK_VERSION/include/c++/v1"
if [ $USE_LIBCXX -eq 1 ]; then
CPLUSINC="$CPLUSINC -stdlib=libc++"
fi
CPLUSINC="$CPLUSINC -Qunused-arguments -lc++abi"
export LIBRARY_PATH="$LIBRARY_PATH:$OSXCROSS_SDK/../libcxx_$OSXCROSS_SDK_VERSION/lib"
else
CPLUSINC="-isystem $OSXCROSS_SDK/usr/lib/gcc/i686-apple-$OSXCROSS_TARGET/4.2.1/include"
CPLUSINC="$CPLUSINC -cxx-isystem $OSXCROSS_SDK/usr/include/c++/4.0.0 "
CPLUSINC="$CPLUSINC -cxx-isystem $OSXCROSS_SDK/usr/include/c++/4.0.0/$ARCH2-apple-darwin9 "
fi
TARGET=$ARCH1-apple-$OSXCROSS_TARGET TARGET=$ARCH1-apple-$OSXCROSS_TARGET
XMMINTRIN=`readlink "$STDINC/xmmintrin.h"` XMMINTRIN=`readlink "$STDINC/xmmintrin.h"`
if [ $? -eq 0 ] && [ ! -f "$XMMINTRIN" ]; then if [ $? -eq 0 ] && [ ! -f "$XMMINTRIN" ]; then
echo "oclang error: dead intrinsic link found - please re-run ./build.sh" 1>&2 pushd "${0%/*}" &>/dev/null
exit 1 if [ -f "osxcross-fix-intrinsic-headers" ]; then
echo -e "\e[1mosxcross:\e[0m\e[35m fixing intrinsic symlinks...\e[0m" 1>&2
./osxcross-fix-intrinsic-headers $OSXCROSS_SDK || { echo -e "\e[31mfailed.\e[0m" 1>&2 && exit 1; }
echo -e "\e[1mdone.\e[0m" 1>&2
else
echo -e "\e[1mosxcross \e[31merror:\e[0m\e[1m dead intrinsic link found - please re-run ./build.sh\e[0m" 1>&2
exit 1
fi
fi fi
$COMPILER $OSXCROSS_TARGET_OPTION $TARGET -isysroot $OSXCROSS_SDK \ $COMPILER $OSXCROSS_TARGET_OPTION $TARGET -isysroot $OSXCROSS_SDK \
-isystem $STDINC -isystem $CPLUSINC1 -isystem $CPLUSINC2 -isystem $CPLUSINC3 \ $CPLUSINC \
$OSX_VERSION_MIN_OPT -mlinker-version=$OSXCROSS_LINKER_VERSION $OSXCROSS_OPT_ARGS \ $OSX_VERSION_MIN_OPT -mlinker-version=$OSXCROSS_LINKER_VERSION $OSXCROSS_OPT_ARGS \
${1+"$@"} ${1+"$@"} -g0
exit $? exit $?

41
oclang/test_libcxx.cpp Normal file
View File

@ -0,0 +1,41 @@
#include <typeindex>
#include <type_traits>
#include <chrono>
#include <tuple>
#include <scoped_allocator>
#include <cstdint>
#include <cinttypes>
#include <system_error>
#include <array>
#include <forward_list>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <ratio>
#include <cfenv>
#include <codecvt>
#include <regex>
#include <thread>
#include <mutex>
#include <future>
#include <condition_variable>
#include <ctgmath>
#include <cstdbool>
#include <iostream>
int main()
{
auto test = []() -> int
{
return 0;
};
std::mutex m;
std::thread t(test);
t.join();
std::cout << "Hello World!" << std::endl;
return 0;
}

View File

@ -1,27 +1,47 @@
#!/usr/bin/env bash #!/usr/bin/env bash
eval `osxcross-conf` pushd "${0%/*}" &>/dev/null
eval `./osxcross-env`
eval `./osxcross-conf`
popd &>/dev/null
type=`basename $0` type=`basename $0`
if [ "$type" != "${type/o64/}" ] || [ "$type" != "${type/x86_64/}" ]; then if [ $type != "${type/o64/}" ] || [ $type != "${type/x86_64/}" ]; then
ARCH1="x86_64" ARCH="x86_64"
ARCH2=$ARCH1 ARCHFLAG="-m64"
else else
if [ "$type" != "${type/o32/}" ] || [ "$type" != "${type/i386/}" ]; then if [ $type != "${type/o32/}" ] || [ $type != "${type/i386/}" ]; then
ARCH1="i386" ARCH="i386"
ARCH2="i686" ARCHFLAG="-m32"
else else
echo "unknown arch" echo "unknown arch"
exit 1 exit 1
fi fi
fi fi
if [ "$type" != "${type/++/}" ]; then if [ $type != "${type/++/}" ]; then
COMPILER="$OSXCROSS_TARGET_DIR/bin/$ARCH1-apple-$OSXCROSS_TARGET-base-g++" COMPILER="$OSXCROSS_TARGET_DIR/bin/$ARCH-apple-$OSXCROSS_TARGET-base-g++"
OSXCROSS_OPT_ARGS+=" -static-libgcc -static-libstdc++"
else else
COMPILER="$OSXCROSS_TARGET_DIR/bin/$ARCH1-apple-$OSXCROSS_TARGET-base-gcc" COMPILER="$OSXCROSS_TARGET_DIR/bin/$ARCH-apple-$OSXCROSS_TARGET-base-gcc"
OSXCROSS_OPT_ARGS+=" -static-libgcc" fi
if [[ $COMPILER == *g++ ]] && [ "$type" != "${type/libc++/}" ]; then
if [ ! -f "$OSXCROSS_SDK/../libcxx_$OSXCROSS_SDK_VERSION/lib/libc++.a" ]; then
echo -e "\e[1mosxcross \e[31merror:\e[0m\e[1m you must build libc++ before you can use it (./build_libcxx.sh)\e[0m" 1>&2
exit 1
fi
OSXCROSS_OPT_ARGS="$OSXCROSS_OPT_ARGS -std=c++0x -nostdinc++ -nodefaultlibs"
OSXCROSS_OPT_ARGS="$OSXCROSS_OPT_ARGS -lc -isystem $OSXCROSS_SDK/../libcxx_$OSXCROSS_SDK_VERSION/include/c++/v1"
OSXCROSS_OPT_ARGS="$OSXCROSS_OPT_ARGS -L$OSXCROSS_SDK/../libcxx_$OSXCROSS_SDK_VERSION/lib -lc++ -lc++abi"
OSXCROSS_OPT_ARGS="$OSXCROSS_OPT_ARGS -L$OSXCROSS_SDK/usr/lib -lgcc_s.10.5"
else
if [[ $COMPILER == *g++ ]]; then
OSXCROSS_OPT_ARGS="$OSXCROSS_OPT_ARGS -static-libgcc -static-libstdc++"
else
OSXCROSS_OPT_ARGS="$OSXCROSS_OPT_ARGS -static-libgcc"
fi
fi fi
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
@ -38,17 +58,17 @@ if [ $# -gt 0 ]; then
done done
if [ $ARCHGIVEN -eq 0 ]; then if [ $ARCHGIVEN -eq 0 ]; then
OSXCROSS_OPT_ARGS+=" -arch $ARCH1" OSXCROSS_OPT_ARGS="$OSXCROSS_OPT_ARGS $ARCHFLAG"
fi fi
fi fi
if [ "$OSXCROSS_OSX_VERSION_MIN" != "default" ]; then if [ $OSXCROSS_OSX_VERSION_MIN != "default" ]; then
OSX_VERSION_MIN_OPT="-mmacosx-version-min=$OSXCROSS_OSX_VERSION_MIN" OSX_VERSION_MIN_OPT="-mmacosx-version-min=$OSXCROSS_OSX_VERSION_MIN"
else else
OSX_VERSION_MIN_OPT="" OSX_VERSION_MIN_OPT=""
fi fi
export COMPILER_PATH="$OSXCROSS_CCTOOLS_PATH:${COMPILER_PATH}" export COMPILER_PATH="$OSXCROSS_CCTOOLS_PATH:$COMPILER_PATH"
$COMPILER $OSX_VERSION_MIN_OPT $OSXCROSS_OPT_ARGS ${1+"$@"} $COMPILER $OSX_VERSION_MIN_OPT $OSXCROSS_OPT_ARGS ${1+"$@"}

View File

@ -1,15 +1,81 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -ex
test -z "$COMPRESSLEVEL" && COMPRESSLEVEL=9
if [ -n "$BINARYPACKAGE" ]; then
SUFFIX=""
else
SUFFIX="_src"
BINARYPACKAGE="0"
fi
TMPDIR=`mktemp -d` TMPDIR=`mktemp -d`
test $? -eq 0 || exit 1
BASEDIR=`pwd` BASEDIR=`pwd`
cp -r . $TMPDIR
pushd $TMPDIR || exit 1 REVHASH=`git rev-parse --short HEAD`
rm -rf build OSXCROSSVER=`cat build.sh | grep "OSXCROSS_VERSION" | head -n1 | tr '=' ' ' | awk '{print $2}'`
rm -rf target
rm -rf tarballs/*MacOSX* pushd $TMPDIR
find . -name "*~" -exec rm {} \;
find . -name "*.save" -exec rm {} \; mkdir osxcross
rm -rf *.tar.xz pushd osxcross
tar -cf - * | xz -9 -c - > $BASEDIR/osxcross.tar.xz || exit 1
if [ $BINARYPACKAGE != "1" ]; then
cp -r $BASEDIR/tarballs .
cp -r $BASEDIR/patches .
cp -r $BASEDIR/tools .
cp -r $BASEDIR/oclang .
cp -r $BASEDIR/ogcc .
else
ldd `ls $BASEDIR/target/bin/x86_64-apple-darwin*-ld | head -n1` | grep "libLTO.so" &>/dev/null && \
echo "-->> WARNING: ld is linked dynamically against libLTO.so! Consider recompiling with DISABLE_LTO_SUPPORT=1 <<--" && \
sleep 5
cp -r $BASEDIR/target/* .
cp $BASEDIR/build/cctools*/cctools/APPLE_LICENSE CCTOOLS.LICENSE
cp $BASEDIR/oclang/find_intrinsic_headers.sh bin/osxcross-fix-intrinsic-headers
READMEINSTALL="README_INSTALL"
echo "- BINARY INSTALLATION INSTRUCTIONS -" > $READMEINSTALL
echo "" >> $READMEINSTALL
echo "Add " >> $READMEINSTALL
echo "" >> $READMEINSTALL
echo " \`<absolute path>/bin/osxcross-env\`" >> $READMEINSTALL
echo "" >> $READMEINSTALL
echo "To your ~/.profile or ~/.bashrc," >> $READMEINSTALL
echo "then restart your shell session." >> $READMEINSTALL
echo "" >> $READMEINSTALL
echo "That's it." >> $READMEINSTALL
echo "" >> $READMEINSTALL
fi
find $BASEDIR -maxdepth 1 -type f -print0 | xargs -0 -i cp {} .
if [ $BINARYPACKAGE == "1" ]; then
rm -f *.sh
rm -f TODO
fi
rm -rf tarballs/gcc*
rm -rf tarballs/MacOSX*
rm -rf tarballs/libcxx*
rm -f tools/cpucount
rm -f osxcross*.tar.*
find . \( -name "*.save" -o -name "*~" -o -name "*.kate-swp" \) -exec rm {} \;
rm -rf osxcross*.tar.*
popd popd
tar -cf - * | xz -$COMPRESSLEVEL -c - > $BASEDIR/osxcross-v${OSXCROSSVER}_${REVHASH}${SUFFIX}.tar.xz
popd
rm -rf $TMPDIR rm -rf $TMPDIR

View File

@ -1,21 +0,0 @@
--- configure.ac 2013-11-13 19:16:27.023967416 +0100
+++ configure.ac 2013-11-13 19:16:40.323967379 +0100
@@ -35,18 +35,6 @@
AC_CHECK_TOOL([HOST_RANLIB], [ranlib], :)
AC_CHECK_TOOL([HOST_AR], [ar], :)
-#detect buggy unistd.h contains __block.
-buggy_unistd=`grep "\*__block," /usr/include/unistd.h`
-if test "$buggy_unistd"; then
- echo "==========================================="
- echo "Buggy unistd.h found"
- echo "\"__block\" is a reserved word of clang compiler for blocks support."
- echo "Please replace \"__block\" in /usr/include/unistd.h to \"__libc_block\""
- echo "==========================================="
- exit
-fi
-
-
AC_CHECK_HEADERS([llvm-c/lto.h], [], [AC_MSG_ERROR([*** lto.h not found, Please install llvm dev packages according to your system])])
AC_CHECK_HEADERS([openssl/md5.h], [], [AC_MSG_ERROR([*** md5.h not found, Please install ssl dev packages according to your system])])
AC_CHECK_HEADERS([uuid/uuid.h], [], [AC_MSG_ERROR([*** uuid.h not found, Please install uuid dev packages according to your system])])

View File

@ -1,40 +0,0 @@
--- configure.ac 2013-12-01 21:31:58.462322949 +0100
+++ configure.ac 2013-12-01 21:30:38.670319304 +0100
@@ -35,7 +35,6 @@
AC_CHECK_TOOL([HOST_RANLIB], [ranlib], :)
AC_CHECK_TOOL([HOST_AR], [ar], :)
-AC_CHECK_HEADERS([llvm-c/lto.h], [], [AC_MSG_ERROR([*** lto.h not found, Please install llvm dev packages according to your system])])
AC_CHECK_HEADERS([openssl/md5.h], [], [AC_MSG_ERROR([*** md5.h not found, Please install ssl dev packages according to your system])])
AC_CHECK_HEADERS([uuid/uuid.h], [], [AC_MSG_ERROR([*** uuid.h not found, Please install uuid dev packages according to your system])])
@@ -189,29 +188,6 @@
AC_C_BIGENDIAN([AC_SUBST([ENDIAN_FLAG],[-D__BIG_ENDIAN__=1])],
[AC_SUBST([ENDIAN_FLAG],[-D__LITTLE_ENDIAN__=1])])
-# Check LTO
-AC_CHECK_PROG(HAVE_LLVM_CONFIG, llvm-config, true, false)
-
-if test "x$HAVE_LLVM_CONFIG" = "xfalse"; then
- AC_CHECK_PROG(HAVE_LLVM_CONFIG_32, llvm-config-3.2, true, false)
- if test "x$HAVE_LLVM_CONFIG_32" = "xfalse"; then
- AC_MSG_ERROR([llvm-config or llvm-config-3.2 not found on your system,please install related packages])
- else
- LLVM_LIBDIR=`llvm-config-3.2 --libdir`
- if test -f $LLVM_LIBDIR/libLTO.so;then
- LTO_LIBS="-L`llvm-config-3.2 --libdir` -lLTO"
- LTO_DEFS="-DLTO_SUPPORT=1"
- fi
- fi
-else
- LLVM_LIBDIR=`llvm-config --libdir`
- if test -f $LLVM_LIBDIR/libLTO.so;then
- LTO_LIBS="-L`llvm-config --libdir` -lLTO"
- LTO_DEFS="-DLTO_SUPPORT=1"
- fi
-fi
-
-
AC_SUBST(LTO_LIBS)
AC_SUBST(LTO_DEFS)

View File

@ -1,4 +0,0 @@
#!/usr/bin/env bash
find . -type f \( -name "*.c" -o -name "*.cpp" -o -name "*.cc" -o -name "*.h" -o -name "*.hpp" \) -print0 | \
xargs -0 sed -i "s/#include <unistd.h>/#undef __block\n#include <unistd.h>\n#define __block __attribute__((__blocks__(byref)))/g"

View File

@ -1,20 +0,0 @@
--- configure 2013-10-02 19:22:22.125610322 +0200
+++ configure 2013-10-02 19:23:08.833608564 +0200
@@ -7742,7 +7742,7 @@
echo $ECHO_N "(cached) $ECHO_C" >&6
else
ac_check_lib_save_LIBS=$LIBS
-LIBS="-lcrypto $LIBS"
+LIBS="-lcrypto -ldl $LIBS -lm"
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
@@ -7805,7 +7805,7 @@
#define HAVE_LIBCRYPTO 1
_ACEOF
- LIBS="-lcrypto $LIBS"
+ LIBS="-lcrypto -ldl $LIBS -lm"
else
have_libcrypto="0"

Binary file not shown.

99
tools/cpucount.c Normal file
View File

@ -0,0 +1,99 @@
/*
* Copyright (C) 2012 by Thomas Poechtrager
* t.poechtrager@gmail.com
*
* OSXCross is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* OSXCross is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#ifdef __CYGWIN__
#define WIN32
#endif //__CYGWIN__
#ifdef WIN32
#include <windows.h>
#endif //WIN32
#ifdef __linux__
#define __USE_GNU
#include <sched.h>
#undef __USE_GNU
#endif //__linux__
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
#include <unistd.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#ifndef HW_AVAILCPU
#define HW_AVAILCPU 25
#endif //HW_AVAILCPU
#endif //BSD
int getcpucount()
{
#ifdef WIN32
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
return sysinfo.dwNumberOfProcessors;
#else
#ifdef __linux__
cpu_set_t cs;
int i, cpucount = 0;
CPU_ZERO(&cs);
sched_getaffinity(0, sizeof(cs), &cs);
for(i = 0; i < 128; i++)
{
if(CPU_ISSET(i, &cs))
cpucount++;
}
return cpucount ? cpucount : 1;
#else
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
int cpucount = 0;
int mib[4];
size_t len = sizeof(cpucount);
mib[0] = CTL_HW;
mib[1] = HW_AVAILCPU;
sysctl(mib, 2, &cpucount, &len, NULL, 0);
if(cpucount < 1)
{
mib[1] = HW_NCPU;
sysctl(mib, 2, &cpucount, &len, NULL, 0);
}
return cpucount ? cpucount : 1;
#else
#warning unknown platform
return 1;
#endif //BSD
#endif //__linux__
#endif //WIN32
}
int main()
{
printf("%d\n", getcpucount());
return 0;
}

16
tools/get_cpu_count.sh Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -e
prog="cpucount"
pushd "${0%/*}" >/dev/null 2>&1
case "$(uname -s)" in
*NT*)
prog="${prog}.exe" ;;
esac
test ! -f $prog && cc cpucount.c -o cpucount
eval "./${prog}"

12
tools/osxcross_conf.sh Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
pushd "${0%/*}" &>/dev/null
OSXCROSS_CONF=`which osxcross-conf 2>/dev/null`
test $? -eq 0 || OSXCROSS_CONF="../target/bin/osxcross-conf"
test -f $OSXCROSS_CONF || exit 1
$OSXCROSS_CONF || exit 1
`dirname $OSXCROSS_CONF`/osxcross-env
popd &>/dev/null