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