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