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