Add note to readme about glibc unistd.h header problem
[blocksruntime.git] / buildlib-osx
blobb7162475dfe44902c17b50bad897ef153115af93
1 #!/bin/bash
3 # Attempt to build a universal library for OSX
5 done=
6 dp="$(xcode-select -print-path 2>/dev/null)"
7 : ${dp:=/Developer}
9 gc40="$(type -P gcc-4.0 2>/dev/null)"
10 gc42="$(type -P gcc-4.2 2>/dev/null)"
11 mp42="$(type -P gcc-apple-4.2 2>/dev/null)"
12 lv42="$(type -P llvm-gcc-4.2 2>/dev/null)"
13 gca0=
14 gca2=
15 if [ -n "$gc42" ]; then
16 gca2="$gc42"
17 elif [ -n "$mp42" ]; then
18 gca2="$mp42"
19 elif [ -n "$lv42" ]; then
20 gca2="$lv42"
22 if [ -n "$gc40" ]; then
23 gca0="$gc40"
24 elif [ -n "$gca2" ]; then
25 gca0="$gca2"
28 if [ -d "$dp/SDKs" ]; then
29 # First see if 10.4u is available and gcc-4.0
30 if [ -z "$done" -a -r "$dp/SDKs/MacOSX10.4u.sdk/SDKSettings.plist" -a -n "$gc40" ]; then
31 done=1
32 NEWCC="$gc40"
33 NEWCFLAGS="-arch x86_64 -arch ppc64 -arch i386 -arch ppc"
34 NEWCFLAGS="$NEWCFLAGS -isysroot$dp/SDKs/MacOSX10.4u.sdk"
36 # Or see if 10.5 is available, any compiler will do
37 if [ -z "$done" -a -r "$dp/SDKs/MacOSX10.5.sdk/SDKSettings.plist" -a -n "$gca0" ]; then
38 done=1
39 NEWCC="$gca0"
40 NEWCFLAGS="-arch x86_64 -arch ppc64 -arch i386 -arch ppc"
41 NEWCFLAGS="$NEWCFLAGS -isysroot$dp/SDKs/MacOSX10.5.sdk"
43 # Or see if 10.6 is available, any 4.2 compiler will do
44 if [ -z "$done" -a -r "$dp/SDKs/MacOSX10.6.sdk/SDKSettings.plist" -a -n "$gca2" ]; then
45 done=1
46 NEWCC="$gca2"
47 NEWCFLAGS="-arch x86_64 -arch i386 -arch ppc"
48 NEWCFLAGS="$NEWCFLAGS -isysroot$dp/SDKs/MacOSX10.6.sdk"
50 # Or see if 10.7 is available, any 4.2 compiler will do
51 if [ -z "$done" -a -r "$dp/SDKs/MacOSX10.7.sdk/SDKSettings.plist" -a -n "$gca2" ]; then
52 done=1
53 NEWCC="$gca2"
54 NEWCFLAGS="-arch x86_64 -arch i386"
55 NEWCFLAGS="$NEWCFLAGS -isysroot$dp/SDKs/MacOSX10.7.sdk"
58 if [ -z "$done" ]; then
59 # Select by OS version as we have no SDKs
60 dv="$(sysctl -n kern.osrelease 2>/dev/null | cut -d. -f1 2>/dev/null)"
61 if [ -z "$done" -a "$dv" = "8" ]; then
62 # Tiger 10.4.x
63 done=1
64 NEWCC="$gca0"
65 # Tiger's system libraries are not guaranteed to be universal
67 if [ -z "$done" -a "$dv" = "9" ]; then
68 # Leopard 10.5.x
69 done=1
70 NEWCC="$gca0"
71 NEWCFLAGS="-arch x86_64 -arch ppc64 -arch i386 -arch ppc"
73 if [ -z "$done" -a "$dv" = "10" ]; then
74 # Snow Leopard 10.6.x
75 done=1
76 NEWCC="$gca2"
77 NEWCFLAGS="-arch x86_64 -arch i386 -arch ppc"
79 if [ -z "$done" -a "$dv" = "11" ]; then
80 # Lion 10.7.x
81 done=1
82 NEWCC="$gca2"
83 NEWCFLAGS="-arch x86_64 -arch i386"
86 if [ -n "$NEWCC" -a -z "$CC" ]; then
87 export CC="$NEWCC"
89 if [ -n "$done" ]; then
90 if [ -z "$MACOSX_DEPLOYMENT_TARGET" ]; then
91 export MACOSX_DEPLOYMENT_TARGET=10.4
94 if [ -n "$NEWCFLAGS" ]; then
95 if [ -z "$CFLAGS" ]; then
96 export CFLAGS="-O2 $NEWCFLAGS"
97 else
98 export CFLAGS="$CFLAGS $NEWCFLAGS"
101 build="$(dirname "$0")/buildlib"
102 if [ -n "$MACOSX_DEPLOYMENT_TARGET" ]; then
103 echo "MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET"
105 exec "$build"