| 1 | #!/bin/sh |
|---|
| 2 | COMPILER='@@@' |
|---|
| 3 | SUFFIX='+++' |
|---|
| 4 | PREFIX='___' |
|---|
| 5 | OUTPUT_O='NO' |
|---|
| 6 | OUTPUT='' |
|---|
| 7 | NAMED_OUTPUT='' |
|---|
| 8 | LASTFILE='' |
|---|
| 9 | INTEL='NO' |
|---|
| 10 | SIZE32='NO' |
|---|
| 11 | SIZE64='NO' |
|---|
| 12 | NEWARGS='' |
|---|
| 13 | |
|---|
| 14 | SKIP='NO' |
|---|
| 15 | |
|---|
| 16 | for arg in $@ |
|---|
| 17 | do |
|---|
| 18 | if [ $SKIP = 'ARCH' ]; then |
|---|
| 19 | # intercept -arch option and set SIZEXX |
|---|
| 20 | SKIP='NO' |
|---|
| 21 | if [ $arg = 'x86_64' ] || [ $arg = 'ppc64' ]; then |
|---|
| 22 | SIZE64='YES' |
|---|
| 23 | else |
|---|
| 24 | SIZE32='YES' |
|---|
| 25 | fi |
|---|
| 26 | |
|---|
| 27 | # which architecture are we compiling for? |
|---|
| 28 | if [ $arg = 'x86_64' ] || [ $arg = 'i386' ]; then |
|---|
| 29 | INTEL='YES' |
|---|
| 30 | fi |
|---|
| 31 | |
|---|
| 32 | elif [ $arg = '-arch' ]; then |
|---|
| 33 | SKIP='ARCH' |
|---|
| 34 | |
|---|
| 35 | elif [ $arg = '--version' ]; then |
|---|
| 36 | ${COMPILER} --version |
|---|
| 37 | exit 0 |
|---|
| 38 | |
|---|
| 39 | else |
|---|
| 40 | NEWARGS+="$arg " |
|---|
| 41 | |
|---|
| 42 | # if the -c option is given, the output is .o |
|---|
| 43 | if [ $arg = '-c' ]; then |
|---|
| 44 | OUTPUT_O='YES' |
|---|
| 45 | fi |
|---|
| 46 | |
|---|
| 47 | # if the output file is given by a -o option, record it |
|---|
| 48 | if [ $SKIP = 'O' ]; then |
|---|
| 49 | SKIP='NO' |
|---|
| 50 | NAMED_OUTPUT=$arg |
|---|
| 51 | fi |
|---|
| 52 | |
|---|
| 53 | if [ $arg = '-o' ]; then |
|---|
| 54 | SKIP='O' |
|---|
| 55 | fi |
|---|
| 56 | |
|---|
| 57 | # Note each file ending by ${SUFFIX} and remember the last one |
|---|
| 58 | # Transform them in .o |
|---|
| 59 | if `echo $arg | grep -q "${SUFFIX}$"`; then |
|---|
| 60 | LASTFILE=$arg |
|---|
| 61 | OUTPUT+=`echo $arg | sed "s/${SUFFIX}/\.o/"` |
|---|
| 62 | OUTPUT+=' ' |
|---|
| 63 | fi |
|---|
| 64 | fi |
|---|
| 65 | done |
|---|
| 66 | |
|---|
| 67 | # What is the output? |
|---|
| 68 | |
|---|
| 69 | if [ ${NAMED_OUTPUT}"X" != "X" ]; then |
|---|
| 70 | OUTPUT=$NAMED_OUTPUT |
|---|
| 71 | |
|---|
| 72 | elif [ $OUTPUT_O = 'NO' ]; then |
|---|
| 73 | # It is an executable whose is name is the LASTFILE without suffix |
|---|
| 74 | OUTPUT=`echo ${LASTFILE} | sed "s/${SUFFIX}//"` |
|---|
| 75 | fi |
|---|
| 76 | |
|---|
| 77 | # Othewise, the output is just the ${OUTPUT} variable as computed before |
|---|
| 78 | |
|---|
| 79 | # For some reason, -dynamiclib and -lpython2.6 are missing when linking |
|---|
| 80 | # .so files. Add them, except if -bundle is set (incompatible switches) |
|---|
| 81 | if [ `echo $OUTPUT | sed -E 's|.*\.||'` = "so" ] && \ |
|---|
| 82 | ! `echo $NEWARGS | grep -q bundle`; then |
|---|
| 83 | NEWARGS="${NEWARGS} ${PREFIX}/lib/libpython2.6.dylib -dynamiclib" |
|---|
| 84 | fi |
|---|
| 85 | |
|---|
| 86 | # Now, compile |
|---|
| 87 | |
|---|
| 88 | if [ $SIZE32 = 'NO' ] && [ $SIZE64 = 'NO' ]; then |
|---|
| 89 | # No size indication given, just proceed with default |
|---|
| 90 | if `${COMPILER} $NEWARGS`; then |
|---|
| 91 | exit 0 |
|---|
| 92 | else |
|---|
| 93 | exit 1 |
|---|
| 94 | fi |
|---|
| 95 | |
|---|
| 96 | elif [ $SIZE32 = 'YES' ] && [ $SIZE64 = 'NO' ]; then |
|---|
| 97 | # 32-bit |
|---|
| 98 | if `${COMPILER} -m32 $NEWARGS`; then |
|---|
| 99 | exit 0 |
|---|
| 100 | else |
|---|
| 101 | exit 1 |
|---|
| 102 | fi |
|---|
| 103 | |
|---|
| 104 | elif [ $SIZE32 = 'NO' ] && [ $SIZE64 = 'YES' ]; then |
|---|
| 105 | # 64-bit |
|---|
| 106 | if `${COMPILER} -m64 $NEWARGS`; then |
|---|
| 107 | exit 0 |
|---|
| 108 | else |
|---|
| 109 | exit 1 |
|---|
| 110 | fi |
|---|
| 111 | |
|---|
| 112 | else |
|---|
| 113 | # Universal case |
|---|
| 114 | if `${COMPILER} -m32 $NEWARGS`; then |
|---|
| 115 | for filename in ${OUTPUT} |
|---|
| 116 | do |
|---|
| 117 | mv ${filename} ${filename}.32 |
|---|
| 118 | done |
|---|
| 119 | |
|---|
| 120 | if `${COMPILER} -m64 $NEWARGS`; then |
|---|
| 121 | for filename in ${OUTPUT} |
|---|
| 122 | do |
|---|
| 123 | mv ${filename} ${filename}.64 |
|---|
| 124 | if [ $INTEL = 'YES' ]; then |
|---|
| 125 | lipo -create -arch x86_64 ${filename}.64 \ |
|---|
| 126 | -arch i386 ${filename}.32 \ |
|---|
| 127 | -output ${filename} |
|---|
| 128 | else |
|---|
| 129 | lipo -create -arch ppc64 ${filename}.64 \ |
|---|
| 130 | -arch ppc ${filename}.32 \ |
|---|
| 131 | -output ${filename} |
|---|
| 132 | fi |
|---|
| 133 | |
|---|
| 134 | rm -f ${filename}.32 ${filename}.64 |
|---|
| 135 | done |
|---|
| 136 | else |
|---|
| 137 | exit 1 |
|---|
| 138 | fi |
|---|
| 139 | else |
|---|
| 140 | exit 1 |
|---|
| 141 | fi |
|---|
| 142 | fi |
|---|
| 143 | exit 0 |
|---|