gcc-fat.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/sh
  2. #
  3. # Build Universal binaries on Mac OS X, thanks Ryan!
  4. #
  5. # Usage: ./configure CC="sh gcc-fat.sh" && make && rm -rf x86 x64
  6. DEVELOPER="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer"
  7. # Intel 32-bit compiler flags (10.6 runtime compatibility)
  8. GCC_COMPILE_X86="gcc -arch i386 -mmacosx-version-min=10.6 \
  9. -DMAC_OS_X_VERSION_MIN_REQUIRED=1040 \
  10. -I/usr/local/include"
  11. GCC_LINK_X86="-mmacosx-version-min=10.6"
  12. # Intel 64-bit compiler flags (10.6 runtime compatibility)
  13. GCC_COMPILE_X64="gcc -arch x86_64 -mmacosx-version-min=10.6 \
  14. -DMAC_OS_X_VERSION_MIN_REQUIRED=1050 \
  15. -I/usr/local/include"
  16. GCC_LINK_X64="-mmacosx-version-min=10.6"
  17. # Output both PowerPC and Intel object files
  18. args="$*"
  19. compile=yes
  20. link=yes
  21. while test x$1 != x; do
  22. case $1 in
  23. --version) exec gcc $1;;
  24. -v) exec gcc $1;;
  25. -V) exec gcc $1;;
  26. -print-prog-name=*) exec gcc $1;;
  27. -print-search-dirs) exec gcc $1;;
  28. -E) GCC_COMPILE_X86="$GCC_COMPILE_X86 -E"
  29. GCC_COMPILE_X64="$GCC_COMPILE_X64 -E"
  30. compile=no; link=no;;
  31. -c) link=no;;
  32. -o) output=$2;;
  33. *.c|*.cc|*.cpp|*.S) source=$1;;
  34. esac
  35. shift
  36. done
  37. if test x$link = xyes; then
  38. GCC_COMPILE_X86="$GCC_COMPILE_X86 $GCC_LINK_X86"
  39. GCC_COMPILE_X64="$GCC_COMPILE_X64 $GCC_LINK_X64"
  40. fi
  41. if test x"$output" = x; then
  42. if test x$link = xyes; then
  43. output=a.out
  44. elif test x$compile = xyes; then
  45. output=`echo $source | sed -e 's|.*/||' -e 's|\(.*\)\.[^\.]*|\1|'`.o
  46. fi
  47. fi
  48. # Compile X86 32-bit
  49. if test x"$output" != x; then
  50. dir=x86/`dirname $output`
  51. if test -d $dir; then
  52. :
  53. else
  54. mkdir -p $dir
  55. fi
  56. fi
  57. set -- $args
  58. while test x$1 != x; do
  59. if test -f "x86/$1" && test "$1" != "$output"; then
  60. x86_args="$x86_args x86/$1"
  61. else
  62. x86_args="$x86_args $1"
  63. fi
  64. shift
  65. done
  66. $GCC_COMPILE_X86 $x86_args || exit $?
  67. if test x"$output" != x; then
  68. cp $output x86/$output
  69. fi
  70. # Compile X86 32-bit
  71. if test x"$output" != x; then
  72. dir=x64/`dirname $output`
  73. if test -d $dir; then
  74. :
  75. else
  76. mkdir -p $dir
  77. fi
  78. fi
  79. set -- $args
  80. while test x$1 != x; do
  81. if test -f "x64/$1" && test "$1" != "$output"; then
  82. x64_args="$x64_args x64/$1"
  83. else
  84. x64_args="$x64_args $1"
  85. fi
  86. shift
  87. done
  88. $GCC_COMPILE_X64 $x64_args || exit $?
  89. if test x"$output" != x; then
  90. cp $output x64/$output
  91. fi
  92. if test x"$output" != x; then
  93. lipo -create -o $output x86/$output x64/$output
  94. fi