1 ?RCS: $Id: ccflags.U,v 3.0.1.9 1997/02/28 15:27:07 ram Exp $
3 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
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 3.0.
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
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
20 ?RCS: Revision 3.0.1.7 1995/05/12 12:08:33 ram
21 ?RCS: patch54: now checks for cc/ccflags/ldflags coherency
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)
27 ?RCS: Revision 3.0.1.5 1994/08/29 16:06:35 ram
28 ?RCS: patch32: propagate -posix flag from ccflags to ldflags
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
35 ?RCS: Revision 3.0.1.3 1993/09/13 15:58:29 ram
36 ?RCS: patch10: explicitely mention -DDEBUG just in case they need it (WAD)
37 ?RCS: patch10: removed all the "tans" variable usage (WAD)
39 ?RCS: Revision 3.0.1.2 1993/08/27 14:39:38 ram
40 ?RCS: patch7: added support for OSF/1 machines
42 ?RCS: Revision 3.0.1.1 1993/08/25 14:00:24 ram
43 ?RCS: patch6: added defaults for cppflags, ccflags and ldflags
45 ?RCS: Revision 3.0 1993/08/18 12:05:31 ram
46 ?RCS: Baseline for dist 3.0 netwide release.
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 libs loclibpth hint usesocks sh run
52 ?MAKE: -pick add $@ %<
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.
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.
62 ?S: This variable contains any optimizer/debugger flag that should be used.
63 ?S: It is up to the Makefile to use it.
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.
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.
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.
80 ?T:inctest thisincl xxx flag inclwanted ftry previous thislibdir
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"
91 ?INIT:: no include file wanted by default
94 ?INIT:: Enable -DEBUGGING and -DDEBUGGING from the command line
98 : determine optimization, if desired, or use for debug flag also
99 ?X: Allow for Configure -Uoptimize -- it's not strictly sensible, but
100 ?X: it has happened and we know what they mean. AD 2/16/98
102 ' '|$undef) dflt='none';;
104 *) dflt="$optimize";;
108 By default, $package compiles with the -O flag to use the optimizer.
109 Alternately, you might want to use the symbolic debugger, which uses
110 the -g flag (on traditional Unix systems). Either flag can be
111 specified here. To use neither flag, specify the word "none".
114 rp="What optimizer/debugger flag should be used?"
118 'none') optimize=" ";;
121 : Check what DEBUGGING is required from the command line
122 : -DEBUGGING or -DDEBUGGING or
123 : -DEBUGGING=both = -g + -DDEBUGGING
124 : -DEBUGGING=-g or -Doptimize=-g = -g
125 : -DEBUGGING=none or -UDEBUGGING =
126 : -DEBUGGING=old or -DEBUGGING=default = ? $optimize
129 *) DEBUGGING=$EBUGGING ;;
136 *) optimize="$optimize -g" ;;
140 *-g*) set `echo "X $optimize " | sed 's/ -g / /'`
149 both|$define) dflt='-DDEBUGGING'
152 : We will not override a previous value, but we might want to
153 : augment a hint file
156 case "$gccversion" in
157 1*) dflt="$dflt -fpcc-struct-return" ;;
159 case "$optimize:$DEBUGGING" in
160 *-g*:old) dflt="$dflt -DDEBUGGING";;
162 ?X: check for POSIXized ISC
163 case "$gccversion" in
164 2*) if test -d /etc/conf/kconfig.d &&
165 $contains _POSIX_VERSION $usrinc/sys/unistd.h >/dev/null 2>&1
167 # Interactive Systems (ISC) POSIX mode.
172 ?X: If the user has gcc-2.95 or greater, try adding -fno-strict-alias.
173 ?X: Since the gcc "version" can be non-numeric, e.g.
174 ?X: "2.95.1 19990809 (prerelease)" , we'll do the test on any version
175 ?X: greater than 2.8.
176 ?X: --Andy Dougherty 27 Aug 1999
177 case "$gccversion" in
181 echo "Checking if your compiler accepts -fno-strict-aliasing" 2>&1
182 echo 'int main(void) { return 0; }' > gcctest.c
183 if $cc -O2 -fno-strict-aliasing -o gcctest gcctest.c; then
184 echo "Yes, it does." 2>&1
187 echo "Leaving current flags $ccflags alone." 2>&1
189 *) dflt="$dflt -fno-strict-aliasing" ;;
192 echo "Nope, it doesn't, but that's ok." 2>&1
197 ?X: -pipe has shown a compile time speedup of about 40% on Linux and HP-UX
198 ?X: and also worked on cygwin-1.5.9
199 ?X: If a system fails, disable it in the hints. 99% of gcc uses binutils
200 # For gcc, adding -pipe speeds up compilations for some, but apparently
201 # some assemblers can't read from stdin. (It also slows down compilations
202 # in other cases, but those are apparently rarer these days.) AD 5/2004.
203 case "$gccversion" in
205 echo "Checking if your compiler accepts -pipe" 2>&1
206 echo 'int main(void) { return 0; }' > gcctest.c
207 if $cc -pipe -o gcctest gcctest.c; then
208 echo "Yes, it does." 2>&1
211 echo "Leaving current flags $ccflags alone." 2>&1
213 *) dflt="$dflt -pipe" ;;
216 echo "Nope, it doesn't, but that's ok." 2>&1
223 ?X: In USG mode, a MIPS system may need some BSD includes
225 *BSD*|'') inclwanted="$locincpth $usrinc";;
226 *) inclwanted="$locincpth $inclwanted $usrinc/bsd";;
228 for thisincl in $inclwanted; do
229 if $test -d $thisincl; then
230 if $test x$thisincl != x$usrinc; then
233 *) dflt="$dflt -I$thisincl ";;
239 ?X: Include test function (header, symbol)
240 inctest='if $contains $2 $usrinc/$1 >/dev/null 2>&1; then
242 elif $contains $2 $usrinc/sys/$1 >/dev/null 2>&1; then
250 *) dflt="$dflt -D$2";;
254 set signal.h LANGUAGE_C; eval $inctest
258 ccflags="$ccflags -DSOCKS"
263 default|recommended) dflt="$ccflags $dflt" ;;
273 Your C compiler may want other flags. For this question you should include
274 -I/whatever and -DWHATEVER flags and any other flags used by the C compiler,
275 but you should NOT include libraries or ld flags like -lwhatever. If you
276 want $package to honor its debug switch, you should include -DDEBUGGING here.
277 Your C compiler might also need additional flags, such as -D_POSIX_SOURCE.
279 To use no flags, specify the word "none".
282 ?X: strip leading space
286 rp="Any additional cc flags?"
293 : the following weeds options from ccflags that are of no interest to cpp
295 '') cppflags="$ccflags" ;;
296 *) cppflags="$cppflags $ccflags" ;;
298 case "$gccversion" in
299 1*) cppflags="$cppflags -D__GNUC__"
303 *BSD*) cppflags="$cppflags -DSYSTYPE_BSD43";;
309 echo "Let me guess what the preprocessor flags are..." >&4
319 ?X: For each cc flag, try it out with both cppstdin and cpprun, since the
320 ?X: first is almost surely a cc wrapper. We have to try both in case
321 ?X: of cc flags like '-Olimit 2900' that are actually two words...
328 *) ftry="$previous $flag";;
330 if $cppstdin -DLFRULB=bar $cppflags $ftry $cppminus <cpp.c \
331 >cpp1.out 2>/dev/null && \
332 $cpprun -DLFRULB=bar $cppflags $ftry $cpplast <cpp.c \
333 >cpp2.out 2>/dev/null && \
334 $contains 'foo.*xx.*bar' cpp1.out >/dev/null 2>&1 && \
335 $contains 'foo.*xx.*bar' cpp2.out >/dev/null 2>&1
337 cppflags="$cppflags $ftry"
347 *-*) echo "They appear to be: $cppflags";;
349 $rm -f cpp.c cpp?.out
353 : flags used in final linking phase
361 *-posix*) dflt="$dflt -posix" ;;
367 : Try to guess additional flags to pick up local libraries.
368 for thislibdir in $libpth; do
369 case " $loclibpth " in
372 *"-L$thislibdir "*) ;;
373 *) dflt="$dflt -L$thislibdir" ;;
385 Your C linker may need flags. For this question you should
386 include -L/whatever and any other flags used by the C linker, but you
387 should NOT include libraries like -lwhatever.
389 Make sure you include the appropriate -L/path flags if your C linker
390 does not normally search all of the directories you specified above,
393 To use no flags, specify the word "none".
397 rp="Any additional ld flags (NOT including libraries)?"
403 rmlist="$rmlist pdp11"
406 : partial linking may need other flags
408 '') case "$ldflags" in
415 rp="Partial linking flags to be used (NOT including -r)?"
424 ?X: If the user changes compilers after selecting a hint file, it's
425 ?X: possible that the suggested ccflags/ldflags will be wrong. Try to
426 ?X: compile and run a simple test program. Let the user see all the
427 ?X: error messages. -- ADO and RAM
428 ?X: Sometimes, particularly on Linux systems, there is a bad library
429 ?X: (e.g. a dangling symlink or incompatible library or a "run-time"
430 ?X: version but not a "development" version of a library). This test
431 ?X: will catch those sorts of problems too, though how to fix them
432 ?X: may not be obvious.
436 echo "Checking your choice of C compiler and flags for coherency..." >&4
439 int main() { printf("Ok\n"); return(0); }
441 ?X: Strip extra blanks in case some of the following variables are empty
442 set X $cc -o try $optimize $ccflags $ldflags try.c $libs
444 $cat >try.msg <<'EOM'
445 I've tried to compile and run the following simple program:
448 $cat try.c >> try.msg
450 $cat >> try.msg <<EOM
457 and I got the following output:
461 ?X: Use "sh -c" to avoid error messages tagged with leading "Configure:".
462 ?X: We need to try the resulting executable, because cc might yield a 0 status
463 ?X: even when ld failed, in which case the executable will not run properly,
464 ?X: if its x bit is set at all...
466 ?X: Also check the xxx=`$run ./try` output to check for misconfigured -lsfio.
467 ?X: If sfio's iffe goofed and it uses _exit instead of exit, then the
468 ?X: output buffers don't get flushed and we don't see any output
469 ?X: when run from within `backticks`. What fun.
470 ?X: --Andy Dougherty 2/13/1998
471 if $sh -c "$cc -o try $optimize $ccflags $ldflags try.c $libs" >>try.msg 2>&1; then
472 if $sh -c "$run ./try" >>try.msg 2>&1; then
476 *) echo 'The program compiled OK, but produced no output.' >> try.msg
479 cat >> try.msg <<'EOQS'
480 If $libs contains -lsfio, and sfio is mis-configured, then it
481 sometimes (apparently) runs and exits with a 0 status, but with no
482 output! It may have to do with sfio's use of _exit vs. exit.
485 rp="You have a big problem. Shall I abort Configure"
492 echo "The program compiled OK, but exited with status $?." >>try.msg
493 rp="You have a problem. Shall I abort Configure"
497 echo "I can't compile the test program." >>try.msg
498 rp="You have a BIG problem. Shall I abort Configure"
504 ?X: using -K will prevent default aborting--maybe they're cross compiling?
507 echo "(The supplied flags or libraries might be incorrect.)"
515 *) echo "Ok. Stopping Configure." >&4
520 n) echo "OK, that should do.";;
522 $rm -f try try.* core