Ticket #23244: c-wrapper.2

File c-wrapper.2, 2.4 KB (added by Veence (Vincent), 14 years ago)

Replace the first version (buggy)

Line 
1#!/bin/sh
2COMPILER='/usr/pkg/bin/gcc-mp-4.4'
3SUFFIX='\.c'
4OUTPUT_O='NO'
5OUTPUT=''
6NAMED_OUTPUT=''
7LASTFILE=''
8INTEL='YES'
9SIZE32='NO'
10SIZE64='NO'
11NEWARGS=''
12
13SKIP='NO'
14
15for arg in $@
16do
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} and remember the last one
53                # Transform them in .o
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
60done
61
62# What is the output?
63
64if [ ${NAMED_OUTPUT}"X" != "X" ]; then
65        OUTPUT=$NAMED_OUTPUT
66
67elif [ $OUTPUT_O = 'NO' ]; then
68        # It is an executable whose is name is the LASTFILE without suffix
69        OUTPUT=`echo ${LASTFILE} | sed "s/${SUFFIX}//"`
70fi
71
72# Othewise, the output is just the ${OUTPUT} variable as computed before
73# Now, compile
74
75if [ $SIZE32 = 'NO' ] && [ $SIZE64 = 'NO' ]; then
76        # No size indication given, just proceed with default
77        if `${COMPILER} $NEWARGS`; then
78                exit 0
79        else
80                exit 1
81        fi
82
83elif [ $SIZE32 = 'YES' ] && [ $SIZE64 = 'NO' ]; then
84        # 32-bit
85        if `${COMPILER} -m32 $NEWARGS`; then
86                exit 0
87        else
88                exit 1
89        fi
90       
91elif [ $SIZE32 = 'NO' ] && [ $SIZE64 = 'YES' ]; then
92        # 64-bit
93        if `${COMPILER} -m64 $NEWARGS`; then
94                exit 0
95        else
96                exit 1
97        fi
98
99else
100        # Universal case
101        if `${COMPILER} -m32 $NEWARGS`; then
102                for filename in ${OUTPUT}
103                do
104                        mv ${filename} ${filename}.32
105                done
106       
107                if `${COMPILER} -m64 $NEWARGS`; then
108                        for filename in ${OUTPUT}
109                        do
110                                mv ${filename} ${filename}.64
111                                if [ $INTEL = 'YES' ]; then
112                                        lipo -create -arch x86_64 ${filename}.64 \
113                                                 -arch i386 ${filename}.32 \
114                                                 -output ${filename}
115                                else
116                                        lipo -create -arch ppc64 ${filename}.64 \
117                                                 -arch ppc ${filename}.32 \
118                                                 -output ${filename}
119                                fi
120                       
121                                rm -f ${filename}.32 ${filename}.64
122                        done
123                else
124                        exit 1
125                fi
126        else
127                exit 1
128        fi
129fi
130exit 0