This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add -Wdeclaration-after-statement to default flags for gcc 3+
[metaconfig.git] / U / compline / ccflags.U
1 ?RCS: $Id: ccflags.U,v 3.0.1.9 1997/02/28 15:27:07 ram Exp $
2 ?RCS:
3 ?RCS: Copyright (c) 1991-1993, 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 3.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: explicitely 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         libs loclibpth hint usesocks sh run
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 ?D:cppflags=''
82 ?D:ccflags=''
83 ?D:ldflags=''
84 ?D:optimize=''
85 ?INIT:: Possible local include directories to search.
86 ?INIT:: Set locincpth to "" in a hint file to defeat local include searches.
87 ?INIT:locincpth="/usr/local/include /opt/local/include /usr/gnu/include"
88 ?INIT:locincpth="$locincpth /opt/gnu/include /usr/GNU/include /opt/GNU/include"
89 ?INIT::
90 ?INIT:: no include file wanted by default
91 ?INIT:inclwanted=''
92 ?INIT:
93 : determine optimization, if desired, or use for debug flag also
94 ?X: Allow for Configure -Uoptimize -- it's not strictly sensible, but
95 ?X: it has happened and we know what they mean.   AD  2/16/98
96 case "$optimize" in
97 ' '|$undef) dflt='none';;
98 '') dflt='-O';;
99 *) dflt="$optimize";;
100 esac
101 $cat <<EOH
102
103 By default, $package compiles with the -O flag to use the optimizer.
104 Alternately, you might want to use the symbolic debugger, which uses
105 the -g flag (on traditional Unix systems).  Either flag can be
106 specified here.  To use neither flag, specify the word "none".
107
108 EOH
109 rp="What optimizer/debugger flag should be used?"
110 . ./myread
111 optimize="$ans"
112 case "$optimize" in
113 'none') optimize=" ";;
114 esac
115
116 dflt=''
117 : We will not override a previous value, but we might want to
118 : augment a hint file
119 case "$hint" in
120 default|recommended)
121         case "$gccversion" in
122         1*) dflt='-fpcc-struct-return' ;;
123         esac
124         case "$optimize" in
125         *-g*) dflt="$dflt -DDEBUGGING";;
126         esac
127 ?X: check for POSIXized ISC
128         case "$gccversion" in
129         2*) if test -d /etc/conf/kconfig.d &&
130                         $contains _POSIX_VERSION $usrinc/sys/unistd.h >/dev/null 2>&1
131                 then
132                         # Interactive Systems (ISC) POSIX mode.
133                         dflt="$dflt -posix"
134                 fi
135                 ;;
136         esac
137 ?X: If the user has gcc-2.95 or greater, try adding -fno-strict-alias.
138 ?X: Since the gcc "version" can be non-numeric, e.g.
139 ?X: "2.95.1 19990809 (prerelease)" , we'll do the test on any version
140 ?X: greater than 2.8.
141 ?X:     --Andy Dougherty  27 Aug 1999
142         case "$gccversion" in
143         1*) ;;
144         2.[0-8]*) ;;
145         ?*)     echo " "
146                 echo "Checking if your compiler accepts -fno-strict-aliasing" 2>&1
147                 echo 'int main(void) { return 0; }' > gcctest.c
148                 if $cc -O2 -fno-strict-aliasing -o gcctest gcctest.c; then
149                         echo "Yes, it does." 2>&1
150                         case "$ccflags" in
151                         *strict-aliasing*)
152                                 echo "Leaving current flags $ccflags alone." 2>&1
153                                 ;;
154                         *) dflt="$dflt -fno-strict-aliasing" ;;
155                         esac
156                 else
157                         echo "Nope, it doesn't, but that's ok." 2>&1
158                 fi
159                 ;;
160         esac
161 ?X: HMB 200405
162 ?X: -pipe has shown a compile time speedup of about 40% on Linux and HP-UX
163 ?X: and also worked on cygwin-1.5.9
164 ?X: If a system fails, disable it in the hints. 99% of gcc uses binutils
165         # For gcc, adding -pipe speeds up compilations for some, but apparently
166         # some assemblers can't read from stdin.  (It also slows down compilations
167         # in other cases, but those are apparently rarer these days.)  AD 5/2004.
168         case "$gccversion" in
169         ?*)     echo " "
170                 echo "Checking if your compiler accepts -pipe" 2>&1
171                 echo 'int main(void) { return 0; }' > gcctest.c
172                 if $cc -pipe -o gcctest gcctest.c; then
173                         echo "Yes, it does." 2>&1
174                         case "$ccflags" in
175                         *-pipe*)
176                                 echo "Leaving current flags $ccflags alone." 2>&1
177                                 ;;
178                         *) dflt="$dflt -pipe" ;;
179                         esac
180                 else
181                         echo "Nope, it doesn't, but that's ok." 2>&1
182                 fi
183
184                 echo "Checking if your compiler accepts -Wdeclaration-after-statement" 2>&1
185                 echo 'int main(void) { return 0; }' > gcctest.c
186                 if $cc -Wdeclaration-after-statement -o gcctest gcctest.c; then
187                         echo "Yes, it does." 2>&1
188                         case "$ccflags" in
189                         *-Wdeclaration-after-statement*)
190                                 echo "Leaving current flags $ccflags alone." 2>&1
191                                 ;;
192                         *) dflt="$dflt -Wdeclaration-after-statement" ;;
193                         esac
194                 else
195                         echo "Nope, it doesn't, but that's ok." 2>&1
196                 fi
197                 ;;
198         esac
199         ;;
200 esac
201
202 ?X: In USG mode, a MIPS system may need some BSD includes
203 case "$mips_type" in
204 *BSD*|'') inclwanted="$locincpth $usrinc";;
205 *) inclwanted="$locincpth $inclwanted $usrinc/bsd";;
206 esac
207 for thisincl in $inclwanted; do
208         if $test -d $thisincl; then
209                 if $test x$thisincl != x$usrinc; then
210                         case "$dflt" in
211                         *" -I$thisincl "*);;
212                         *) dflt="$dflt -I$thisincl ";;
213                         esac
214                 fi
215         fi
216 done
217
218 ?X: Include test function (header, symbol)
219 inctest='if $contains $2 $usrinc/$1 >/dev/null 2>&1; then
220         xxx=true;
221 elif $contains $2 $usrinc/sys/$1 >/dev/null 2>&1; then
222         xxx=true;
223 else
224         xxx=false;
225 fi;
226 if $xxx; then
227         case "$dflt" in
228         *$2*);;
229         *) dflt="$dflt -D$2";;
230         esac;
231 fi'
232
233 set signal.h LANGUAGE_C; eval $inctest
234
235 case "$usesocks" in
236 $define)
237         ccflags="$ccflags -DSOCKS"
238         ;;
239 esac
240
241 case "$hint" in
242 default|recommended) dflt="$ccflags $dflt" ;;
243 *) dflt="$ccflags";;
244 esac
245
246 case "$dflt" in
247 ''|' ') dflt=none;;
248 esac
249
250 $cat <<EOH
251
252 Your C compiler may want other flags.  For this question you should include
253 -I/whatever and -DWHATEVER flags and any other flags used by the C compiler,
254 but you should NOT include libraries or ld flags like -lwhatever.  If you
255 want $package to honor its debug switch, you should include -DDEBUGGING here.
256 Your C compiler might also need additional flags, such as -D_POSIX_SOURCE.
257
258 To use no flags, specify the word "none".
259
260 EOH
261 ?X: strip leading space
262 set X $dflt
263 shift
264 dflt=${1+"$@"}
265 rp="Any additional cc flags?"
266 . ./myread
267 case "$ans" in
268 none) ccflags='';;
269 *) ccflags="$ans";;
270 esac
271
272 : the following weeds options from ccflags that are of no interest to cpp
273 case "$cppflags" in
274 '') cppflags="$ccflags" ;;
275 *)  cppflags="$cppflags $ccflags" ;;
276 esac
277 case "$gccversion" in
278 1*) cppflags="$cppflags -D__GNUC__"
279 esac
280 case "$mips_type" in
281 '');;
282 *BSD*) cppflags="$cppflags -DSYSTYPE_BSD43";;
283 esac
284 case "$cppflags" in
285 '');;
286 *)
287         echo " "
288         echo "Let me guess what the preprocessor flags are..." >&4
289         set X $cppflags
290         shift
291         cppflags=''
292         $cat >cpp.c <<'EOM'
293 #define BLURFL foo
294
295 BLURFL xx LFRULB
296 EOM
297 ?X:
298 ?X: For each cc flag, try it out with both cppstdin and cpprun, since the
299 ?X: first is almost surely a cc wrapper. We have to try both in case
300 ?X: of cc flags like '-Olimit 2900' that are actually two words...
301 ?X:
302         previous=''
303         for flag in $*
304         do
305                 case "$flag" in
306                 -*) ftry="$flag";;
307                 *) ftry="$previous $flag";;
308                 esac
309                 if $cppstdin -DLFRULB=bar $cppflags $ftry $cppminus <cpp.c \
310                         >cpp1.out 2>/dev/null && \
311                         $cpprun -DLFRULB=bar $cppflags $ftry $cpplast <cpp.c \
312                         >cpp2.out 2>/dev/null && \
313                         $contains 'foo.*xx.*bar' cpp1.out >/dev/null 2>&1 && \
314                         $contains 'foo.*xx.*bar' cpp2.out >/dev/null 2>&1
315                 then
316                         cppflags="$cppflags $ftry"
317                         previous=''
318                 else
319                         previous="$flag"
320                 fi
321         done
322         set X $cppflags
323         shift
324         cppflags=${1+"$@"}
325         case "$cppflags" in
326         *-*)  echo "They appear to be: $cppflags";;
327         esac
328         $rm -f cpp.c cpp?.out
329         ;;
330 esac
331
332 : flags used in final linking phase
333 case "$ldflags" in
334 '') if ./venix; then
335                 dflt='-i -z'
336         else
337                 dflt=''
338         fi
339         case "$ccflags" in
340         *-posix*) dflt="$dflt -posix" ;;
341         esac
342         ;;
343 *) dflt="$ldflags";;
344 esac
345
346 : Try to guess additional flags to pick up local libraries.
347 for thislibdir in $libpth; do
348         case " $loclibpth " in
349         *" $thislibdir "*)
350                 case "$dflt " in
351                 *"-L$thislibdir "*) ;;
352                 *)  dflt="$dflt -L$thislibdir" ;;
353                 esac
354                 ;;
355         esac
356 done
357
358 case "$dflt" in
359 '') dflt='none' ;;
360 esac
361
362 $cat <<EOH
363
364 Your C linker may need flags.  For this question you should
365 include -L/whatever and any other flags used by the C linker, but you
366 should NOT include libraries like -lwhatever.
367
368 Make sure you include the appropriate -L/path flags if your C linker
369 does not normally search all of the directories you specified above,
370 namely
371         $libpth
372 To use no flags, specify the word "none".
373
374 EOH
375
376 rp="Any additional ld flags (NOT including libraries)?"
377 . ./myread
378 case "$ans" in
379 none) ldflags='';;
380 *) ldflags="$ans";;
381 esac
382 rmlist="$rmlist pdp11"
383
384 @if lkflags
385 : partial linking may need other flags
386 case "$lkflags" in
387 '') case "$ldflags" in
388         '') dflt='none';;
389         *) dflt="$ldflags";;
390         esac;;
391 *) dflt="$lkflags";;
392 esac
393 echo " "
394 rp="Partial linking flags to be used (NOT including -r)?"
395 . ./myread
396 case "$ans" in
397 none) lkflags='';;
398 *) lkflags="$ans";;
399 esac
400
401 @end
402 ?X:
403 ?X: If the user changes compilers after selecting a hint file, it's
404 ?X: possible that the suggested ccflags/ldflags will be wrong.  Try to
405 ?X: compile and run a simple test program.  Let the user see all the
406 ?X: error messages. -- ADO and RAM
407 ?X: Sometimes, particularly on Linux systems, there is a bad library
408 ?X: (e.g. a dangling symlink or incompatible library or a "run-time"
409 ?X: version but not a "development" version of a library).  This test
410 ?X: will catch those sorts of problems too, though how to fix them
411 ?X: may not be obvious.
412 ?X:
413 : coherency check
414 echo " "
415 echo "Checking your choice of C compiler and flags for coherency..." >&4
416 $cat > try.c <<'EOF'
417 #include <stdio.h>
418 int main() { printf("Ok\n"); return(0); }
419 EOF
420 ?X: Strip extra blanks in case some of the following variables are empty
421 set X $cc -o try $optimize $ccflags $ldflags try.c $libs
422 shift
423 $cat >try.msg <<'EOM'
424 I've tried to compile and run the following simple program:
425
426 EOM
427 $cat try.c >> try.msg
428
429 $cat >> try.msg <<EOM
430
431 I used the command:
432
433         $*
434         $run ./try
435
436 and I got the following output:
437
438 EOM
439 dflt=y
440 ?X: Use "sh -c" to avoid error messages tagged with leading "Configure:".
441 ?X: We need to try the resulting executable, because cc might yield a 0 status
442 ?X: even when ld failed, in which case the executable will not run properly,
443 ?X: if its x bit is set at all...
444 ?X:
445 ?X: Also check the xxx=`$run ./try` output to check for misconfigured -lsfio.
446 ?X: If sfio's iffe goofed and it uses _exit instead of exit, then the
447 ?X: output buffers don't get flushed and we don't see any output
448 ?X: when run from within `backticks`.  What fun.
449 ?X: --Andy Dougherty 2/13/1998
450 if $sh -c "$cc -o try $optimize $ccflags $ldflags try.c $libs" >>try.msg 2>&1; then
451         if $sh -c "$run ./try" >>try.msg 2>&1; then
452                 xxx=`$run ./try`
453                 case "$xxx" in
454                 "Ok") dflt=n ;;
455                 *)      echo 'The program compiled OK, but produced no output.' >> try.msg
456                         case " $libs " in
457                         *" -lsfio "*)
458                                 cat >> try.msg <<'EOQS'
459 If $libs contains -lsfio, and sfio is mis-configured, then it
460 sometimes (apparently) runs and exits with a 0 status, but with no
461 output!  It may have to do with sfio's use of _exit vs. exit.
462
463 EOQS
464                                 rp="You have a big problem.  Shall I abort Configure"
465                                 dflt=y
466                                 ;;
467                         esac
468                         ;;
469                 esac
470         else
471                 echo "The program compiled OK, but exited with status $?." >>try.msg
472                 rp="You have a problem.  Shall I abort Configure"
473                 dflt=y
474         fi
475 else
476         echo "I can't compile the test program." >>try.msg
477         rp="You have a BIG problem.  Shall I abort Configure"
478         dflt=y
479 fi
480 case "$dflt" in
481 y)
482         $cat try.msg >&4
483 ?X: using -K will prevent default aborting--maybe they're cross compiling?
484         case "$knowitall" in
485         '')
486                 echo "(The supplied flags or libraries might be incorrect.)"
487                 ;;
488         *) dflt=n;;
489         esac
490         echo " "
491         . ./myread
492         case "$ans" in
493         n*|N*) ;;
494         *)      echo "Ok.  Stopping Configure." >&4
495                 exit 1
496                 ;;
497         esac
498         ;;
499 n) echo "OK, that should do.";;
500 esac
501 $rm -f try try.* core
502