1 | #!/bin/sh |
---|
2 | ## This script shall wrap/hide how we are going to compile C++ |
---|
3 | ## source files within the ANTLR (www.antlr.org) project. |
---|
4 | test -z "${verbose}" && { |
---|
5 | verbose=0 |
---|
6 | } |
---|
7 | |
---|
8 | ## check whether we have something to do .. |
---|
9 | test -z "$1" && exit 0 |
---|
10 | |
---|
11 | ## get arguments |
---|
12 | ARGV="$*" |
---|
13 | |
---|
14 | ## Command CXX is precomputed but user may override. |
---|
15 | if test -z "${CXX}" ; then |
---|
16 | CXX="g++" |
---|
17 | cxx="gcc" |
---|
18 | else |
---|
19 | cxx="`basename $CXX`" |
---|
20 | cxx="`echo $cxx|sed 's,\..*$,,'`" |
---|
21 | fi |
---|
22 | |
---|
23 | ## use whitespace to separate dirs, don't use compiler specific |
---|
24 | ## options like '-I' etc. That will be added at runtime when we |
---|
25 | ## know what compiler is in use. |
---|
26 | CXXINCLUDE=". /usr/neuro/local/yao/yao9/share/antlr-2.7.7/scripts/../lib/cpp" |
---|
27 | |
---|
28 | test -z "${DEBUG}" && { |
---|
29 | DEBUG="0" |
---|
30 | } |
---|
31 | |
---|
32 | ##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx## |
---|
33 | ## Here we set flags for well know programs ## |
---|
34 | ##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx## |
---|
35 | ## |
---|
36 | ## Do not set variable CXXFLAGS here, just use it's sister |
---|
37 | ## variable 'cxxflags'. This allows the call to override |
---|
38 | ## this settings - see handling of CXXFLAGS below. |
---|
39 | |
---|
40 | case "${cxx}" in |
---|
41 | gcc) |
---|
42 | cxxflags="-MM" |
---|
43 | ;; |
---|
44 | *) |
---|
45 | for x in ${ARGV} ; do |
---|
46 | echo > $x.d |
---|
47 | done |
---|
48 | return 0 |
---|
49 | ;; |
---|
50 | esac |
---|
51 | |
---|
52 | case ${cxx} in |
---|
53 | bcc32|CC|aCC|xlC) |
---|
54 | CXX_OPT_INCLUDE="-I" |
---|
55 | ;; |
---|
56 | *) |
---|
57 | CXX_OPT_INCLUDE="-I " |
---|
58 | ;; |
---|
59 | esac |
---|
60 | |
---|
61 | ##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx## |
---|
62 | ## **NO CHANGE NECESSARY BELOW THIS LINE - EXPERTS ONLY** ## |
---|
63 | ##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx## |
---|
64 | |
---|
65 | |
---|
66 | ## If specific flags have been configured then they overrule |
---|
67 | ## our precomputed flags. Still a user can override by using |
---|
68 | ## environment variable $CXXFLAGS - see below. |
---|
69 | test -n "" && { |
---|
70 | set x ; shift |
---|
71 | case $1 in |
---|
72 | +) |
---|
73 | shift |
---|
74 | CXXFLAGS="${cxxflags} $*" |
---|
75 | ;; |
---|
76 | -) |
---|
77 | shift |
---|
78 | cxxflags="$* ${cxxflags}" |
---|
79 | ;; |
---|
80 | =) |
---|
81 | shift |
---|
82 | cxxflags="$*" |
---|
83 | ;; |
---|
84 | *) |
---|
85 | if test -z "$1" ; then |
---|
86 | cxxflags="${cxxflags}" |
---|
87 | else |
---|
88 | cxxflags="$*" |
---|
89 | fi |
---|
90 | ;; |
---|
91 | esac |
---|
92 | } |
---|
93 | |
---|
94 | ## Regardless what has been configured, a user should always |
---|
95 | ## be able to override without the need to reconfigure or |
---|
96 | ## change this file. Therefore we check variable $CXXFLAGS. |
---|
97 | ## In almost all cases the precomputed flags are just ok but |
---|
98 | ## some additional flags are needed. To support this in an |
---|
99 | ## easy way, we check for the very first value. If this val- |
---|
100 | ## ue is |
---|
101 | ## '+' -> append content of CXXFLAGS to precomputed flags |
---|
102 | ## '-' -> prepend content -*- |
---|
103 | ## '=' -> do not use precomputed flags |
---|
104 | ## If none of these characters are given, the behaviour will |
---|
105 | ## be the same as if "=" would have been given. |
---|
106 | |
---|
107 | set x ${CXXFLAGS} ; shift |
---|
108 | case $1 in |
---|
109 | +) |
---|
110 | shift |
---|
111 | CXXFLAGS="${cxxflags} $*" |
---|
112 | ;; |
---|
113 | -) |
---|
114 | shift |
---|
115 | CXXFLAGS="$* ${cxxflags}" |
---|
116 | ;; |
---|
117 | =) |
---|
118 | shift |
---|
119 | CXXFLAGS="$*" |
---|
120 | ;; |
---|
121 | *) |
---|
122 | if test -z "$1" ; then |
---|
123 | CXXFLAGS="${cxxflags}" |
---|
124 | else |
---|
125 | CXXFLAGS="$*" |
---|
126 | fi |
---|
127 | ;; |
---|
128 | esac |
---|
129 | |
---|
130 | ##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%## |
---|
131 | ## No c u s t o m i z a t i o n below this line ## |
---|
132 | ##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%## |
---|
133 | |
---|
134 | ## translate args - requires that we are on cygwin. Other- |
---|
135 | ## wise we have to assume that args are already in proper |
---|
136 | ## format. |
---|
137 | |
---|
138 | case "linux-gnu" in |
---|
139 | cygwin) |
---|
140 | case "gcc" in |
---|
141 | cl|bcc32) |
---|
142 | ARGV="`cygpath -m ${ARGV}`" |
---|
143 | ;; |
---|
144 | esac |
---|
145 | ;; |
---|
146 | esac |
---|
147 | |
---|
148 | ## we only add valid directories - note that CXXINCLUDE is |
---|
149 | ## supposed to contain directories and not optionized' |
---|
150 | ## arguments. |
---|
151 | |
---|
152 | set x ${CXXINCLUDE} ; shift |
---|
153 | Y="" |
---|
154 | |
---|
155 | ## filter non valid directories |
---|
156 | while test $# -gt 0 ; do |
---|
157 | y="$1" ; shift |
---|
158 | test -d "${y}" && { |
---|
159 | Y="${Y} ${y}" |
---|
160 | } |
---|
161 | done |
---|
162 | |
---|
163 | set x ${Y} ; shift ; Y="" |
---|
164 | |
---|
165 | ## translate directories on cygwin |
---|
166 | case "linux-gnu" in |
---|
167 | cygwin) |
---|
168 | set x `cygpath -m ${*}` ; shift |
---|
169 | ;; |
---|
170 | esac |
---|
171 | |
---|
172 | ## prefix each arg with CXX_OPT_INCLUDE (for instance -I) |
---|
173 | while test $# -gt 0 ; do |
---|
174 | y="$1" ; shift |
---|
175 | Y="${Y} ${CXX_OPT_INCLUDE}${y}" |
---|
176 | done |
---|
177 | |
---|
178 | CXXINCLUDE="${Y}" |
---|
179 | |
---|
180 | ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx### |
---|
181 | ### LAST CHANCE COMPILER TUNIG HERE ### |
---|
182 | ###================================================================### |
---|
183 | |
---|
184 | case "${cxx}" in |
---|
185 | cl) |
---|
186 | ;; |
---|
187 | bcc32) |
---|
188 | ;; |
---|
189 | gcc) |
---|
190 | ;; |
---|
191 | xlC) |
---|
192 | ;; |
---|
193 | CC) |
---|
194 | ;; |
---|
195 | aCC) |
---|
196 | ;; |
---|
197 | *) |
---|
198 | ;; |
---|
199 | esac |
---|
200 | |
---|
201 | case "gcc" in |
---|
202 | *) |
---|
203 | CXXFLAGS="${CXXFLAGS} -c" |
---|
204 | ;; |
---|
205 | esac |
---|
206 | |
---|
207 | ###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
---|
208 | ### all variables participating in calling must be set now.. |
---|
209 | ###--------------------------------------------------------- |
---|
210 | |
---|
211 | CXX_CMD="${CXX} ${CXXFLAGS} ${CXXINCLUDE}" |
---|
212 | |
---|
213 | test -z "${ARGV}" && exit 0 |
---|
214 | |
---|
215 | |
---|
216 | for x in ${ARGV} ; do |
---|
217 | cmd="$CXX_CMD $x" |
---|
218 | |
---|
219 | case "${verbose}" in |
---|
220 | 0|no|nein|non) |
---|
221 | echo "*** update deps for `basename $x`" |
---|
222 | ;; |
---|
223 | *) |
---|
224 | echo "*** making $x.d" |
---|
225 | echo $cmd |
---|
226 | ;; |
---|
227 | esac |
---|
228 | |
---|
229 | $cmd > $x.$$$$ || { |
---|
230 | rc=$? |
---|
231 | cat <<EOF |
---|
232 | |
---|
233 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
---|
234 | >> E R R O R << |
---|
235 | ============================================================ |
---|
236 | |
---|
237 | $cmd |
---|
238 | |
---|
239 | ============================================================ |
---|
240 | Got an error while trying to execute command above. Error |
---|
241 | messages (if any) must have shown before. The exit code was: |
---|
242 | exit($rc) |
---|
243 | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
---|
244 | EOF |
---|
245 | exit $rc |
---|
246 | } |
---|
247 | ## on compiling ${dir}/x.cpp we get dep x.o : x.cpp ${dir}/y.h .. |
---|
248 | ## but we need to have x.o ${dir}/x.o ${dir}/x.d : ... |
---|
249 | dx=`echo $x|sed 's,\.[^.]*$,.o,g'` |
---|
250 | sed "s,\(.*\)\.o[ ]*:,\1.o ${dx} ${x}.d : ,g" < $x.$$$$ > $x.d |
---|
251 | rm -f $x.$$$$ |
---|
252 | |
---|
253 | done |
---|
254 | exit 0 |
---|
255 | |
---|