use a nifty preprocessor trick to workaround the __block issue in unistd.h

get rid of the  || exit 1  in build.sh by using  set -e
This commit is contained in:
Thomas Pöchtrager 2013-11-13 19:36:39 +01:00
parent fba6b74ff9
commit d502ab0138
8 changed files with 64 additions and 47 deletions

View File

@ -2,7 +2,7 @@
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,
Don't forget to run "source ~/.profile" after adding the PATH exports 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,

View File

@ -59,6 +59,8 @@ case $SDK_VERSION in
*) echo "Invalid SDK Version"; exit 1 ;;
esac
set -e
echo ""
echo "Building OSXCross toolchain, Version: $OSXCROSS_VERSION"
echo ""
@ -75,9 +77,9 @@ echo ""
export PATH=$TARGET_DIR/bin:$PATH
mkdir -p $BUILD_DIR || exit 1
mkdir -p $TARGET_DIR || exit 1
mkdir -p $SDK_DIR || exit 1
mkdir -p $BUILD_DIR
mkdir -p $TARGET_DIR
mkdir -p $SDK_DIR
require $CC
require $CXX
@ -92,57 +94,45 @@ require automake
require libtool
CLANG_TARGET_OPTION=`./oclang/check_clang_target_option.sh`
test $? -eq 0 || exit 1
pushd $BUILD_DIR || exit 1
pushd $BUILD_DIR
if [ ! -f "have_cctools_$TARGET" ]; then
BLOCK_LINE=`grep -n "__block," /usr/include/unistd.h`
while [ $? -eq 0 ]
do
BLOCK_LINE_NUM=`echo "$BLOCK_LINE" | cut -d ':' -f 1`
BLOCK_LINE_BAD=`echo "$BLOCK_LINE" | cut -d ':' -f 2`
BLOCK_LINE_GOOD=`echo "$BLOCK_LINE_BAD" | sed 's/__block,/__libc_block,/g'`
echo ""
echo "Your /usr/include/unistd.h header file appears to be broken."
echo "Replace __block with __libc_block on line $BLOCK_LINE_NUM, otherwise compiling cctools will fail!"
echo ""
echo "Bad: $BLOCK_LINE_BAD"
echo "Good: $BLOCK_LINE_GOOD"
echo ""
read -p "Press enter to continue when you have fixed the header file"
BLOCK_LINE=`grep -n "__block," /usr/include/unistd.h`
done
tar xzfv $TARBALL_DIR/cctools-*.tar.gz || exit 1
tar xzfv $TARBALL_DIR/xar*.tar.gz || exit 1
tar xzfv $TARBALL_DIR/cctools-*.tar.gz
tar xzfv $TARBALL_DIR/xar*.tar.gz
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
patch -p0 < $PATCH_DIR/cctools-ld64-1.patch
patch -p0 < $PATCH_DIR/cctools-ld64-2.patch
patch -p0 < $PATCH_DIR/cctools-ld64-3.patch
patch -p0 < $PATCH_DIR/cctools-llvm-3.4.patch
patch -p0 < $PATCH_DIR/cctools-conf-1.patch
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
./autogen.sh
./configure --prefix=$TARGET_DIR --target=x86_64-apple-$TARGET || exit 1
make -j$JOBS || exit 1
make install || exit 1
./configure --prefix=$TARGET_DIR --target=x86_64-apple-$TARGET
make -j$JOBS
make install -j$JOBS
pushd $TARGET_DIR/bin
CCTOOLS=`find . -name "x86_64-apple-darwin*"`
CCTOOLS=($CCTOOLS)
for CCTOOL in ${CCTOOLS[@]}; do
CCTOOL_I386=`echo "$CCTOOL" | sed 's/x86_64/i386/g'`
ln -sf $CCTOOL $CCTOOL_I386 || exit 1
ln -sf $CCTOOL $CCTOOL_I386
done
popd
popd
pushd xar*
./configure --prefix=$TARGET_DIR || exit 1
make -j$JOBS || exit
make install || exit 1
./configure --prefix=$TARGET_DIR
make -j$JOBS
make install -j$JOBS
popd
function check
@ -183,8 +173,8 @@ echo "extracting $SDK_FILENAME ..."
case $SDK in
*.pkg)
xar -xf $SDK || exit 1
(cat Payload | gunzip -dc | cpio -i 2>/dev/null) || exit 1
xar -xf $SDK
cat Payload | gunzip -dc | cpio -i 2>/dev/null
;;
*.tar.xz)
tar xJf $SDK
@ -195,20 +185,22 @@ case $SDK in
esac
rm -rf $SDK_DIR/MacOSX$SDK_VERSION* 2>/dev/null
mv -f SDKs/*$SDK_VERSION* $SDK_DIR || exit 1
mv -f SDKs/*$SDK_VERSION* $SDK_DIR
pushd $SDK_DIR/MacOSX$SDK_VERSION.sdk || exit 1
pushd $SDK_DIR/MacOSX$SDK_VERSION.sdk
set +e
ln -s $SDK_DIR/MacOSX$SDK_VERSION.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/std*.h usr/include 2>/dev/null
set -e
popd
popd
cp oclang/oclang $TARGET_DIR/bin || exit 1
cp -f oclang/oclang $TARGET_DIR/bin
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/o32-clang || exit 1
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/o32-clang++ || exit 1
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/o64-clang || exit 1
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/o64-clang++ || exit 1
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/o32-clang
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/o32-clang++
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
ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/i386-apple-$TARGET-clang++
@ -217,7 +209,7 @@ ln -sf $TARGET_DIR/bin/oclang $TARGET_DIR/bin/x86_64-apple-$TARGET-clang++
OSXCROSS_CONF="$TARGET_DIR/bin/osxcross-conf"
rm $OSXCROSS_CONF 2>/dev/null
rm -f $OSXCROSS_CONF 2>/dev/null
echo "#!/usr/bin/env bash" > $OSXCROSS_CONF
echo "echo \"export OSXCROSS_VERSION=$OSXCROSS_VERSION\"" >> $OSXCROSS_CONF
@ -237,7 +229,7 @@ chmod +x $OSXCROSS_CONF
function test_compiler
{
echo -ne "testing $1 ... "
($1 $2 -O2 -Wall -o test && rm test) || exit 1
$1 $2 -O2 -Wall -o test && rm test
echo "works"
}

View File

@ -0,0 +1,21 @@
--- 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])])

4
patches/fix-unistd-issue.sh Executable file
View File

@ -0,0 +1,4 @@
#!/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"