1 | #!/bin/sh |
---|
2 | COMPILER='/usr/pkg/bin/gcc-mp-4.4' |
---|
3 | SUFFIX='\.c' |
---|
4 | OUTPUT_O='NO' |
---|
5 | OUTPUT='' |
---|
6 | NAMED_OUTPUT='' |
---|
7 | LASTFILE='' |
---|
8 | INTEL='YES' |
---|
9 | SIZE32='NO' |
---|
10 | SIZE64='NO' |
---|
11 | NEWARGS='' |
---|
12 | |
---|
13 | SKIP='NO' |
---|
14 | |
---|
15 | for arg in $@ |
---|
16 | do |
---|
17 | if [ $SKIP = 'ARCH' ]; then |
---|
18 | # intercept -arch option and set SIZEXX |
---|
19 | SKIP='NO' |
---|
20 | if [ $arg = 'x86_64' ] || [ $arg = 'ppc64' ]; then |
---|
21 | SIZE64='YES' |
---|
22 | else |
---|
23 | SIZE32='YES' |
---|
24 | fi |
---|
25 | |
---|
26 | # which architecture are we compiling for? |
---|
27 | if [ $arg = 'ppc64' ] || [ $arg = 'ppc' ]; then |
---|
28 | INTEL='NO' |
---|
29 | fi |
---|
30 | |
---|
31 | elif [ $arg = '-arch' ]; then |
---|
32 | SKIP='ARCH' |
---|
33 | |
---|
34 | else |
---|
35 | NEWARGS+="$arg " |
---|
36 | |
---|
37 | # if the -c option is given, the output is .o |
---|
38 | if [ $arg = '-c' ]; then |
---|
39 | OUTPUT_O='YES' |
---|
40 | fi |
---|
41 | |
---|
42 | # if the output file is given by a -o option, record it |
---|
43 | if [ $SKIP = 'O' ]; then |
---|
44 | SKIP='NO' |
---|
45 | NAMED_OUTPUT=$arg |
---|
46 | fi |
---|
47 | |
---|
48 | if [ $arg = '-o' ]; then |
---|
49 | SKIP='O' |
---|
50 | fi |
---|
51 | |
---|
52 | # note each file ending by ${SUFFIX} |
---|
53 | # transform it in .o and remember the last one |
---|
54 | if `echo $arg | grep -q "${SUFFIX}$"`; then |
---|
55 | LASTFILE=$arg |
---|
56 | OUTPUT+=`echo $arg | sed "s/${SUFFIX}/\.o/"` |
---|
57 | OUTPUT+=' ' |
---|
58 | fi |
---|
59 | fi |
---|
60 | done |
---|
61 | |
---|
62 | # What is the output? |
---|
63 | |
---|
64 | if [ ${NAMED_OUTPUT}"X" != "X" ]; then |
---|
65 | OUTPUT=$NAMED_OUTPUT |
---|
66 | |
---|
67 | elif [ $OUTPUT_O = 'NO' ]; then |
---|
68 | # It is an executable whose is name is the LASTFILE without suffix |
---|
69 | OUTPUT=`echo ${LASTFILE} | sed "s/${SUFFIX}//"` |
---|
70 | fi |
---|
71 | |
---|
72 | # Othewise, the output is just the ${OUTPUT} variable as computed before |
---|
73 | # Now, compile |
---|
74 | |
---|
75 | if [ $SIZE32 = 'YES' ] && [ $SIZE64 = 'NO' ]; then |
---|
76 | if `${COMPILER} -m32 $NEWARGS`; then |
---|
77 | exit 0 |
---|
78 | else |
---|
79 | exit 1 |
---|
80 | fi |
---|
81 | |
---|
82 | elif [ $SIZE32 = 'NO' ] && [ $SIZE64 = 'YES' ]; then |
---|
83 | if `${COMPILER} -m64 $NEWARGS`; then |
---|
84 | exit 0 |
---|
85 | else |
---|
86 | exit 1 |
---|
87 | fi |
---|
88 | |
---|
89 | else |
---|
90 | # Universal case |
---|
91 | if `${COMPILER} -m32 $NEWARGS`; then |
---|
92 | for filename in ${OUTPUT} |
---|
93 | do |
---|
94 | mv ${OUTPUT} ${OUTPUT}.32 |
---|
95 | done |
---|
96 | |
---|
97 | if `${COMPILER} -m64 $NEWARGS`; then |
---|
98 | for filename in ${OUTPUT} |
---|
99 | do |
---|
100 | mv ${OUTPUT} ${OUTPUT}.64 |
---|
101 | if [ $INTEL = 'YES' ]; then |
---|
102 | lipo -create -arch x86_64 ${OUTPUT}.64 \ |
---|
103 | -arch i386 ${OUTPUT}.32 \ |
---|
104 | -output ${OUTPUT} |
---|
105 | else |
---|
106 | lipo -create -arch ppc64 ${OUTPUT}.64 \ |
---|
107 | -arch ppc ${OUTPUT}.32 \ |
---|
108 | -output ${OUTPUT} |
---|
109 | fi |
---|
110 | |
---|
111 | rm -f ${OUTPUT}.32 ${OUTPUT}.64 |
---|
112 | done |
---|
113 | else |
---|
114 | exit 1 |
---|
115 | fi |
---|
116 | else |
---|
117 | exit 1 |
---|
118 | fi |
---|
119 | fi |
---|
120 | exit 0 |
---|