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