Commit | Line | Data |
---|---|---|
d8875586 MBT |
1 | ?RCS: $Id: ccflags.U 17 2006-11-04 12:13:28Z rmanfredi $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi | |
4 | ?RCS: | |
5 | ?RCS: You may redistribute only under the terms of the Artistic Licence, | |
6 | ?RCS: as specified in the README file that comes with the distribution. | |
7 | ?RCS: You may reuse parts of this distribution only within the terms of | |
8 | ?RCS: that same Artistic Licence; a copy of which may be found at the root | |
9 | ?RCS: of the source tree for dist 4.0. | |
10 | ?RCS: | |
11 | ?RCS: $Log: ccflags.U,v $ | |
12 | ?RCS: Revision 3.0.1.9 1997/02/28 15:27:07 ram | |
13 | ?RCS: patch61: removed support for NO_PROTOTYPE detection on SCO | |
14 | ?RCS: patch61: new locincpth variable | |
15 | ?RCS: patch61: added info on the "additional ld flags" question | |
16 | ?RCS: | |
17 | ?RCS: Revision 3.0.1.8 1995/07/25 13:48:54 ram | |
18 | ?RCS: patch56: re-arranged compile line to include ldflags before objects | |
19 | ?RCS: | |
20 | ?RCS: Revision 3.0.1.7 1995/05/12 12:08:33 ram | |
21 | ?RCS: patch54: now checks for cc/ccflags/ldflags coherency | |
22 | ?RCS: | |
23 | ?RCS: Revision 3.0.1.6 1994/10/29 16:07:02 ram | |
24 | ?RCS: patch36: gcc versionning no longer relies on the C compiler's name | |
25 | ?RCS: patch36: simplified check for gcc version checking (ADO) | |
26 | ?RCS: | |
27 | ?RCS: Revision 3.0.1.5 1994/08/29 16:06:35 ram | |
28 | ?RCS: patch32: propagate -posix flag from ccflags to ldflags | |
29 | ?RCS: | |
30 | ?RCS: Revision 3.0.1.4 1994/05/06 14:28:45 ram | |
31 | ?RCS: patch23: -fpcc-struct-return only needed in gcc 1.x (ADO) | |
32 | ?RCS: patch23: cppflags now computed on an option-by-option basis | |
33 | ?RCS: patch23: magically added cc flags now only done the first time | |
34 | ?RCS: | |
35 | ?RCS: Revision 3.0.1.3 1993/09/13 15:58:29 ram | |
36 | ?RCS: patch10: explicitly mention -DDEBUG just in case they need it (WAD) | |
37 | ?RCS: patch10: removed all the "tans" variable usage (WAD) | |
38 | ?RCS: | |
39 | ?RCS: Revision 3.0.1.2 1993/08/27 14:39:38 ram | |
40 | ?RCS: patch7: added support for OSF/1 machines | |
41 | ?RCS: | |
42 | ?RCS: Revision 3.0.1.1 1993/08/25 14:00:24 ram | |
43 | ?RCS: patch6: added defaults for cppflags, ccflags and ldflags | |
44 | ?RCS: | |
45 | ?RCS: Revision 3.0 1993/08/18 12:05:31 ram | |
46 | ?RCS: Baseline for dist 3.0 netwide release. | |
47 | ?RCS: | |
48 | ?MAKE:ccflags ldflags lkflags cppflags optimize locincpth: test cat \ | |
49 | Myread Guess Options Oldconfig gccversion mips_type +usrinc \ | |
50 | package contains rm +cc cppstdin cppminus cpprun cpplast libpth \ | |
51 | loclibpth hint | |
52 | ?MAKE: -pick add $@ %< | |
53 | ?S:ccflags: | |
54 | ?S: This variable contains any additional C compiler flags desired by | |
55 | ?S: the user. It is up to the Makefile to use this. | |
56 | ?S:. | |
57 | ?S:cppflags: | |
58 | ?S: This variable holds the flags that will be passed to the C pre- | |
59 | ?S: processor. It is up to the Makefile to use it. | |
60 | ?S:. | |
61 | ?S:optimize: | |
62 | ?S: This variable contains any optimizer/debugger flag that should be used. | |
63 | ?S: It is up to the Makefile to use it. | |
64 | ?S:. | |
65 | ?S:ldflags: | |
66 | ?S: This variable contains any additional C loader flags desired by | |
67 | ?S: the user. It is up to the Makefile to use this. | |
68 | ?S:. | |
69 | ?S:lkflags: | |
70 | ?S: This variable contains any additional C partial linker flags desired by | |
71 | ?S: the user. It is up to the Makefile to use this. | |
72 | ?S:. | |
73 | ?S:locincpth: | |
74 | ?S: This variable contains a list of additional directories to be | |
75 | ?S: searched by the compiler. The appropriate -I directives will | |
76 | ?S: be added to ccflags. This is intended to simplify setting | |
77 | ?S: local directories from the Configure command line. | |
78 | ?S: It's not much, but it parallels the loclibpth stuff in libpth.U. | |
79 | ?S:. | |
80 | ?T:inctest thisincl xxx flag inclwanted ftry previous thislibdir | |
81 | ?F:!cpp.c | |
82 | ?D:cppflags='' | |
83 | ?D:ccflags='' | |
84 | ?D:ldflags='' | |
85 | ?D:optimize='' | |
86 | ?INIT:: Possible local include directories to search. | |
87 | ?INIT:: Set locincpth to "" in a hint file to defeat local include searches. | |
88 | ?INIT:locincpth="/usr/local/include /opt/local/include /usr/gnu/include" | |
89 | ?INIT:locincpth="$locincpth /opt/gnu/include /usr/GNU/include /opt/GNU/include" | |
90 | ?INIT:: | |
91 | ?INIT:: no include file wanted by default | |
92 | ?INIT:inclwanted='' | |
93 | ?INIT: | |
94 | : determine optimize, if desired, or use for debug flag also | |
95 | case "$optimize" in | |
96 | ' '|$undef) dflt='none';; | |
97 | '') | |
98 | case "$gccversion" in | |
99 | '') dflt='-O';; | |
100 | *) dflt='-O2 -g';; | |
101 | esac | |
102 | ;; | |
103 | *) dflt="$optimize";; | |
104 | esac | |
105 | case "$gccversion" in | |
106 | '') $cat <<EOH | |
107 | ||
108 | Some C compilers have problems with their optimizers. By default, $package | |
109 | compiles with the -O flag to use the optimizer. Alternately, you might want | |
110 | to use the symbolic debugger, which uses the -g flag (on traditional Unix | |
111 | systems). Either flag can be specified here. To use neither flag, specify | |
112 | the word "none". | |
113 | ||
114 | EOH | |
115 | ;; | |
116 | *) $cat <<EOH | |
117 | ||
118 | With the GNU C compiler, it is possible to supply both -O2 and -g flags, to | |
119 | be able to reasonably optimize, whilst retaining the ability to use a | |
120 | symbolic debugger. Either flag can be specified here. To use neither flag, | |
121 | specify the word "none". | |
122 | ||
123 | EOH | |
124 | ;; | |
125 | esac | |
126 | rp="What optimizer/debugger flag should be used?" | |
127 | . ./myread | |
128 | optimize="$ans" | |
129 | case "$optimize" in | |
130 | 'none') optimize=" ";; | |
131 | esac | |
132 | ||
133 | dflt='' | |
134 | : We will not override a previous value, but we might want to | |
135 | : augment a hint file | |
136 | case "$hint" in | |
137 | default|recommended) | |
138 | case "$gccversion" in | |
139 | 1*) dflt='-fpcc-struct-return' ;; | |
140 | esac | |
141 | ?X: check for POSIXized ISC | |
142 | case "$gccversion" in | |
143 | 2*) if test -d /etc/conf/kconfig.d && | |
144 | $contains _POSIX_VERSION $usrinc/sys/unistd.h >/dev/null 2>&1 | |
145 | then | |
146 | dflt="$dflt -posix" | |
147 | fi | |
148 | ;; | |
149 | esac | |
150 | ?X: turn warnings on if they're using gcc | |
151 | case "$gccversion" in | |
152 | 1*|2*) dflt="$dflt -Wall";; | |
153 | ?X: starting with version 3, add "-W -Wall -Wformat=2 -Wshadow" by default | |
154 | *) dflt="$dflt -W -Wall -Wformat=2 -Wshadow";; | |
155 | esac | |
156 | ;; | |
157 | esac | |
158 | ||
159 | ?X: In USG mode, a MIPS system may need some BSD includes | |
160 | case "$mips_type" in | |
161 | *BSD*|'') inclwanted="$locincpth $usrinc";; | |
162 | *) inclwanted="$locincpth $inclwanted $usrinc/bsd";; | |
163 | esac | |
164 | for thisincl in $inclwanted; do | |
165 | if $test -d $thisincl; then | |
166 | if $test x$thisincl != x$usrinc; then | |
167 | case "$dflt" in | |
168 | *$thisincl*);; | |
169 | *) dflt="$dflt -I$thisincl";; | |
170 | esac | |
171 | fi | |
172 | fi | |
173 | done | |
174 | ||
175 | ?X: Include test function (header, symbol) | |
176 | inctest='if $contains $2 $usrinc/$1 >/dev/null 2>&1; then | |
177 | xxx=true; | |
178 | elif $contains $2 $usrinc/sys/$1 >/dev/null 2>&1; then | |
179 | xxx=true; | |
180 | else | |
181 | xxx=false; | |
182 | fi; | |
183 | if $xxx; then | |
184 | case "$dflt" in | |
185 | *$2*);; | |
186 | *) dflt="$dflt -D$2";; | |
187 | esac; | |
188 | fi' | |
189 | ||
190 | ?X: | |
191 | ?X: OSF/1 uses __LANGUAGE_C__ instead of LANGUAGE_C | |
192 | ?X: | |
193 | if ./osf1; then | |
194 | set signal.h __LANGUAGE_C__; eval $inctest | |
195 | else | |
196 | set signal.h LANGUAGE_C; eval $inctest | |
197 | fi | |
198 | ||
199 | case "$hint" in | |
200 | default|recommended) dflt="$ccflags $dflt" ;; | |
201 | *) dflt="$ccflags";; | |
202 | esac | |
203 | ||
204 | case "$dflt" in | |
205 | ''|' ') dflt=none;; | |
206 | esac | |
207 | $cat <<EOH | |
208 | ||
209 | Your C compiler may want other flags. For this question you should include | |
210 | -I/whatever and -DWHATEVER flags and any other flags used by the C compiler, | |
211 | but you should NOT include libraries or ld flags like -lwhatever. | |
212 | ||
213 | To use no flags, specify the word "none". | |
214 | ||
215 | EOH | |
216 | ?X: strip leading space | |
217 | set X $dflt | |
218 | shift | |
219 | dflt=${1+"$@"} | |
220 | rp="Any additional cc flags?" | |
221 | . ./myread | |
222 | case "$ans" in | |
223 | none) ccflags='';; | |
224 | *) ccflags="$ans";; | |
225 | esac | |
226 | ||
227 | : the following weeds options from ccflags that are of no interest to cpp | |
228 | cppflags="$ccflags" | |
229 | case "$gccversion" in | |
230 | 1*) cppflags="$cppflags -D__GNUC__" | |
231 | esac | |
232 | case "$mips_type" in | |
233 | '');; | |
234 | *BSD*) cppflags="$cppflags -DSYSTYPE_BSD43";; | |
235 | esac | |
236 | case "$cppflags" in | |
237 | '');; | |
238 | *) | |
239 | echo " " | |
240 | echo "Let me guess what the preprocessor flags are..." >&4 | |
241 | set X $cppflags | |
242 | shift | |
243 | cppflags='' | |
244 | $cat >cpp.c <<'EOM' | |
245 | #define BLURFL foo | |
246 | ||
247 | BLURFL xx LFRULB | |
248 | EOM | |
249 | ?X: | |
250 | ?X: For each cc flag, try it out with both cppstdin and cpprun, since the | |
251 | ?X: first is almost surely a cc wrapper. We have to try both in case | |
252 | ?X: of cc flags like '-Olimit 2900' that are actually two words... | |
253 | ?X: | |
254 | previous='' | |
255 | for flag in $* | |
256 | do | |
257 | case "$flag" in | |
258 | -*) ftry="$flag";; | |
259 | *) ftry="$previous $flag";; | |
260 | esac | |
261 | if $cppstdin -DLFRULB=bar $ftry $cppminus <cpp.c \ | |
262 | >cpp1.out 2>/dev/null && \ | |
263 | $cpprun -DLFRULB=bar $ftry $cpplast <cpp.c \ | |
264 | >cpp2.out 2>/dev/null && \ | |
265 | $contains 'foo.*xx.*bar' cpp1.out >/dev/null 2>&1 && \ | |
266 | $contains 'foo.*xx.*bar' cpp2.out >/dev/null 2>&1 | |
267 | then | |
268 | cppflags="$cppflags $ftry" | |
269 | previous='' | |
270 | else | |
271 | previous="$flag" | |
272 | fi | |
273 | done | |
274 | set X $cppflags | |
275 | shift | |
276 | cppflags=${1+"$@"} | |
277 | case "$cppflags" in | |
278 | *-*) echo "They appear to be: $cppflags";; | |
279 | esac | |
280 | $rm -f cpp.c cpp?.out | |
281 | ;; | |
282 | esac | |
283 | ||
284 | : flags used in final linking phase | |
285 | case "$ldflags" in | |
286 | '') if ./venix; then | |
287 | dflt='-i -z' | |
288 | else | |
289 | dflt='' | |
290 | fi | |
291 | case "$ccflags" in | |
292 | *-posix*) dflt="$dflt -posix" ;; | |
293 | esac | |
294 | ;; | |
295 | *) dflt="$ldflags";; | |
296 | esac | |
297 | ||
298 | : Try to guess additional flags to pick up local libraries. | |
299 | for thislibdir in $libpth; do | |
300 | case " $loclibpth " in | |
301 | *" $thislibdir "*) | |
302 | case "$dflt " in | |
303 | *"-L$thislibdir "*) ;; | |
304 | *) dflt="$dflt -L$thislibdir" ;; | |
305 | esac | |
306 | ;; | |
307 | esac | |
308 | done | |
309 | ||
310 | case "$dflt" in | |
311 | '') dflt='none' ;; | |
312 | *) set X $dflt; shift; dflt="$@";; | |
313 | esac | |
314 | ||
315 | $cat <<EOH | |
316 | ||
317 | Your C linker may need flags. For this question you should | |
318 | include -L/whatever and any other flags used by the C linker, but you | |
319 | should NOT include libraries like -lwhatever. | |
320 | ||
321 | Make sure you include the appropriate -L/path flags if your C linker | |
322 | does not normally search all of the directories you specified above, | |
323 | namely | |
324 | $libpth | |
325 | To use no flags, specify the word "none". | |
326 | ||
327 | EOH | |
328 | ||
329 | rp="Any additional ld flags (NOT including libraries)?" | |
330 | . ./myread | |
331 | case "$ans" in | |
332 | none) ldflags='';; | |
333 | *) ldflags="$ans";; | |
334 | esac | |
335 | rmlist="$rmlist pdp11" | |
336 | ||
337 | @if lkflags | |
338 | : partial linking may need other flags | |
339 | case "$lkflags" in | |
340 | '') case "$ldflags" in | |
341 | '') dflt='none';; | |
342 | *) dflt="$ldflags";; | |
343 | esac;; | |
344 | *) dflt="$lkflags";; | |
345 | esac | |
346 | echo " " | |
347 | rp="Partial linking flags to be used (NOT including -r)?" | |
348 | . ./myread | |
349 | case "$ans" in | |
350 | none) lkflags='';; | |
351 | *) lkflags="$ans";; | |
352 | esac | |
353 | ||
354 | @end | |
355 | ?X: | |
356 | ?X: If the user changes compilers after selecting a hint file, it's | |
357 | ?X: possible that the suggested ccflags/ldflags will be wrong. Try to | |
358 | ?X: compile and run a simple test program. Let the user see all the | |
359 | ?X: error messages. -- ADO and RAM | |
360 | ?X: | |
361 | : coherency check | |
362 | echo " " | |
363 | echo "Checking your choice of C compiler and flags for coherency..." >&4 | |
364 | ?X: Strip extra blanks in case some of the following variables are empty | |
365 | set X $cc $optimize $ccflags $ldflags -o try try.c | |
366 | shift | |
367 | $cat >try.msg <<EOM | |
368 | I've tried to compile and run a simple program with: | |
369 | ||
370 | $* | |
371 | ./try | |
372 | ||
373 | and I got the following output: | |
374 | ||
375 | EOM | |
376 | $cat > try.c <<'EOF' | |
377 | #include <stdio.h> | |
378 | int main() { exit(0); } | |
379 | EOF | |
380 | dflt=y | |
381 | ?X: Use "sh -c" to avoid error messages tagged with leading "Configure:". | |
382 | ?X: We need to try the resulting executable, because cc might yield a 0 status | |
383 | ?X: even when ld failed, in which case the executable will not run properly, | |
384 | ?X: if its x bit is set at all... | |
385 | if sh -c "$cc $optimize $ccflags $ldflags -o try try.c" >>try.msg 2>&1; then | |
386 | if sh -c './try' >>try.msg 2>&1; then | |
387 | dflt=n | |
388 | else | |
389 | echo "The program compiled OK, but exited with status $?." >>try.msg | |
390 | rp="You have a problem. Shall I abort Configure" | |
391 | dflt=y | |
392 | fi | |
393 | else | |
394 | echo "I can't compile the test program." >>try.msg | |
395 | rp="You have a BIG problem. Shall I abort Configure" | |
396 | dflt=y | |
397 | fi | |
398 | case "$dflt" in | |
399 | y) | |
400 | $cat try.msg >&4 | |
401 | ?X: using -K will prevent default aborting--maybe they're cross compiling? | |
402 | case "$knowitall" in | |
403 | '') | |
404 | echo "(The supplied flags might be incorrect with this C compiler.)" | |
405 | ;; | |
406 | *) dflt=n;; | |
407 | esac | |
408 | echo " " | |
409 | . ./myread | |
410 | case "$ans" in | |
411 | n*|N*) ;; | |
412 | *) echo "Ok. Stopping Configure." >&4 | |
413 | exit 1 | |
414 | ;; | |
415 | esac | |
416 | ;; | |
417 | n) echo "OK, that should do.";; | |
418 | esac | |
419 | $rm -f try try.* core | |
420 |