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