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