summaryrefslogtreecommitdiff
path: root/mcon/U/ccflags.U
blob: b134f57a71307174c7e2d39b3264528eb2288215 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
?RCS: $Id$
?RCS:
?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
?RCS:
?RCS: You may redistribute only under the terms of the Artistic License,
?RCS: as specified in the README file that comes with the distribution.
?RCS: You may reuse parts of this distribution only within the terms of
?RCS: that same Artistic License; a copy of which may be found at the root
?RCS: of the source tree for dist 4.0.
?RCS:
?RCS: $Log: ccflags.U,v $
?RCS: Revision 3.0.1.9  1997/02/28  15:27:07  ram
?RCS: patch61: removed support for NO_PROTOTYPE detection on SCO
?RCS: patch61: new locincpth variable
?RCS: patch61: added info on the "additional ld flags" question
?RCS:
?RCS: Revision 3.0.1.8  1995/07/25  13:48:54  ram
?RCS: patch56: re-arranged compile line to include ldflags before objects
?RCS:
?RCS: Revision 3.0.1.7  1995/05/12  12:08:33  ram
?RCS: patch54: now checks for cc/ccflags/ldflags coherency
?RCS:
?RCS: Revision 3.0.1.6  1994/10/29  16:07:02  ram
?RCS: patch36: gcc versioning no longer relies on the C compiler's name
?RCS: patch36: simplified check for gcc version checking (ADO)
?RCS:
?RCS: Revision 3.0.1.5  1994/08/29  16:06:35  ram
?RCS: patch32: propagate -posix flag from ccflags to ldflags
?RCS:
?RCS: Revision 3.0.1.4  1994/05/06  14:28:45  ram
?RCS: patch23: -fpcc-struct-return only needed in gcc 1.x (ADO)
?RCS: patch23: cppflags now computed on an option-by-option basis
?RCS: patch23: magically added cc flags now only done the first time
?RCS:
?RCS: Revision 3.0.1.3  1993/09/13  15:58:29  ram
?RCS: patch10: explicitly mention -DDEBUG just in case they need it (WAD)
?RCS: patch10: removed all the "tans" variable usage (WAD)
?RCS:
?RCS: Revision 3.0.1.2  1993/08/27  14:39:38  ram
?RCS: patch7: added support for OSF/1 machines
?RCS:
?RCS: Revision 3.0.1.1  1993/08/25  14:00:24  ram
?RCS: patch6: added defaults for cppflags, ccflags and ldflags
?RCS:
?RCS: Revision 3.0  1993/08/18  12:05:31  ram
?RCS: Baseline for dist 3.0 netwide release.
?RCS:
?MAKE:ccflags ldflags lkflags cppflags optimize pthread locincpth: test cat \
	Myread Guess Options Oldconfig gccversion mips_type +usrinc \
	package contains rm rm_try +cc cppstdin cppminus cpprun cpplast libpth \
	loclibpth hint
?MAKE:	-pick add $@ %<
?S:ccflags:
?S:	This variable contains any additional C compiler flags desired by
?S:	the user.  It is up to the Makefile to use this.
?S:.
?S:cppflags:
?S:	This variable holds the flags that will be passed to the C pre-
?S:	processor. It is up to the Makefile to use it.
?S:.
?S:optimize:
?S:	This variable contains any optimizer/debugger flag that should be used.
?S:	It is up to the Makefile to use it.
?S:.
?S:pthread:
?S:	This variable contains any thread-specific flag that should be used.
?S:	It is up to the Makefile to use it.
?S:.
?S:ldflags:
?S:	This variable contains any additional C loader flags desired by
?S:	the user.  It is up to the Makefile to use this.
?S:.
?S:lkflags:
?S:	This variable contains any additional C partial linker flags desired by
?S:	the user.  It is up to the Makefile to use this.
?S:.
?S:locincpth:
?S:	This variable contains a list of additional directories to be
?S:	searched by the compiler.  The appropriate -I directives will
?S:	be added to ccflags.  This is intended to simplify setting
?S:	local directories from the Configure command line.
?S:	It's not much, but it parallels the loclibpth stuff in libpth.U.
?S:.
?T:inctest thisincl xxx flag inclwanted ftry previous thislibdir
?F:!cpp.c
?D:cppflags=''
?D:ccflags=''
?D:ldflags=''
?D:optimize=''
?D:pthread=''
?INIT:: Possible local include directories to search.
?INIT:: Set locincpth to "" in a hint file to defeat local include searches.
?INIT:locincpth=""
?INIT::
?INIT:: no include file wanted by default
?INIT:inclwanted=''
?INIT:
: determine optimize, if desired, or use for debug flag also
case "$optimize" in
' '|$undef) dflt='none';;
'')
	case "$gccversion" in
	'') dflt='-O';;
	*) dflt='-O2 -g';;
	esac
	;;
*) dflt="$optimize";;
esac
case "$gccversion" in
'') $cat <<EOH

Some C compilers have problems with their optimizers.  By default, $package
compiles with the -O flag to use the optimizer.  Alternately, you might want
to use the symbolic debugger, which uses the -g flag (on traditional Unix
systems).  Either flag can be specified here.  To use neither flag, specify
the word "none".

EOH
	;;
*) $cat <<EOH

With the GNU C compiler, it is possible to supply both -O2 and -g flags, to
be able to reasonably optimize, whilst retaining the ability to use a
symbolic debugger.  Either flag can be specified here.  To use neither flag,
specify the word "none".

EOH
	;;
esac
rp="What optimizer/debugger flag should be used?"
. ./myread
optimize="$ans"
case "$optimize" in
'none') optimize=" ";;
esac

?X: When they are using I_PTHREAD, check whether we need/can supply -pthread
?X: to the compiler for proper threading support.  This is usually necessary
?X: with gcc, in addition to the required -lpthread that need to be listed
?X: at link time.
@if I_PTHREAD
: see whether we need -pthread at the compile/link stage
case "$pthread" in
''|$undef)
	$cat > try.c <<'EOF'
int main() { return 0; }
EOF
	if $cc -pthread -c try.c >/dev/null 2>&1; then
		dflt='-pthread'
	else
		dflt='none'
	fi
	;;
*) dflt="$pthread";;
esac
$cat <<EOH

Some C compilers need to have special flags supplied at compile and link time
to be able to generate code that will work correctly with POSIX threads.
When no specific flags are required, specify the word "none".

EOH
rp="What thread-support compiler/linker flag should be used?"
. ./myread
pthread="$ans"
case "$pthread" in
'none') pthread="";;
esac
@end

dflt=''
: We will not override a previous value, but we might want to
: augment a hint file
case "$hint" in
default|recommended)
	case "$gccversion" in
	1) dflt='-fpcc-struct-return' ;;
	esac
?X: check for POSIXized ISC
	case "$gccversion" in
	2) if test -d /etc/conf/kconfig.d &&
			$contains _POSIX_VERSION $usrinc/sys/unistd.h >/dev/null 2>&1
		then
			dflt="$dflt -posix"
		fi
		;;
	esac
?X: turn warnings on if they're using gcc
	case "$gccversion" in
	1|2) dflt="$dflt -Wall";;
?X: starting with version 3, add "-W -Wall -Wformat=2 -Wshadow" by default
	*) dflt="$dflt -W -Wall -Wformat=2 -Wshadow";;
	esac
	;;
esac

?X: In USG mode, a MIPS system may need some BSD includes
case "$mips_type" in
*BSD*|'') inclwanted="$locincpth $usrinc";;
*) inclwanted="$locincpth $inclwanted $usrinc/bsd";;
esac
for thisincl in $inclwanted; do
	if $test -d $thisincl; then
		if $test x$thisincl != x$usrinc; then
			case "$dflt" in
			*$thisincl*);;
			*) dflt="$dflt -I$thisincl";;
			esac
		fi
	fi
done

?X: Include test function (header, symbol)
inctest='if $contains $2 $usrinc/$1 >/dev/null 2>&1; then
	xxx=true;
elif $contains $2 $usrinc/sys/$1 >/dev/null 2>&1; then
	xxx=true;
else
	xxx=false;
fi;
if $xxx; then
	case "$dflt" in
	*$2*);;
	*) dflt="$dflt -D$2";;
	esac;
fi'

?X:
?X: OSF/1 uses __LANGUAGE_C__ instead of LANGUAGE_C
?X:
if ./osf1; then
	set signal.h __LANGUAGE_C__; eval $inctest
else
	set signal.h LANGUAGE_C; eval $inctest
fi

case "$hint" in
default|recommended) dflt="$dflt $ccflags" ;;
*) dflt="$ccflags";;
esac

case "$dflt" in
''|' ') dflt=none;;
esac
$cat <<EOH

Your C compiler may want other flags.  For this question you should include
-I/whatever and -DWHATEVER flags and any other flags used by the C compiler,
but you should NOT include libraries or ld flags like -lwhatever.

To use no flags, specify the word "none".

EOH
?X: strip leading space
set X $dflt
shift
dflt=${1+"$@"}
rp="Any additional cc flags?"
. ./myread
case "$ans" in
none) ccflags='';;
*) ccflags="$ans";;
esac

: the following weeds options from ccflags that are of no interest to cpp
cppflags="$ccflags"
case "$gccversion" in
1) cppflags="$cppflags -D__GNUC__"
esac
case "$mips_type" in
'');;
*BSD*) cppflags="$cppflags -DSYSTYPE_BSD43";;
esac
case "$cppflags" in
'');;
*)
	echo " "
	echo "Let me guess what the preprocessor flags are..." >&4
	set X $cppflags
	shift
	cppflags=''
	$cat >cpp.c <<'EOM'
#define BLURFL foo

BLURFL xx LFRULB
EOM
?X:
?X: For each cc flag, try it out with both cppstdin and cpprun, since the
?X: first is almost surely a cc wrapper. We have to try both in case
?X: of cc flags like '-Olimit 2900' that are actually two words...
?X:
	previous=''
	for flag in $*
	do
		case "$flag" in
		-*) ftry="$flag";;
		*) ftry="$previous $flag";;
		esac
		if $cppstdin -DLFRULB=bar $ftry $cppminus <cpp.c \
			>cpp1.out 2>/dev/null && \
			$cpprun -DLFRULB=bar $ftry $cpplast <cpp.c \
			>cpp2.out 2>/dev/null && \
			$contains 'foo.*xx.*bar' cpp1.out >/dev/null 2>&1 && \
			$contains 'foo.*xx.*bar' cpp2.out >/dev/null 2>&1
		then
			cppflags="$cppflags $ftry"
			previous=''
		else
			previous="$flag"
		fi
	done
	set X $cppflags
	shift
	cppflags=${1+"$@"}
	case "$cppflags" in
	*-*)  echo "They appear to be: $cppflags";;
	esac
	$rm -f cpp.c cpp?.out
	;;
esac

: flags used in final linking phase
case "$ldflags" in
'') if ./venix; then
		dflt='-i -z'
	else
		dflt=''
	fi
	case "$ccflags" in
	*-posix*) dflt="$dflt -posix" ;;
	esac
	;;
*) dflt="$ldflags";;
esac

: Try to guess additional flags to pick up local libraries.
for thislibdir in $libpth; do
	case " $loclibpth " in
	*" $thislibdir "*)
		case "$dflt " in 
		*"-L$thislibdir "*) ;;
		*)  dflt="$dflt -L$thislibdir" ;;
		esac
		;;
	esac
done

case "$dflt" in
'') dflt='none' ;;
*) set X $dflt; shift; dflt="$@";;
esac

$cat <<EOH

Your C linker may need flags.  For this question you should
include -L/whatever and any other flags used by the C linker, but you
should NOT include libraries like -lwhatever.

Make sure you include the appropriate -L/path flags if your C linker
does not normally search all of the directories you specified above,
namely
	$libpth
To use no flags, specify the word "none".

EOH

rp="Any additional ld flags (NOT including libraries)?"
. ./myread
case "$ans" in
none) ldflags='';;
*) ldflags="$ans";;
esac
rmlist="$rmlist pdp11"

@if lkflags
: partial linking may need other flags
case "$lkflags" in
'') case "$ldflags" in
	'') dflt='none';;
	*) dflt="$ldflags";;
	esac;;
*) dflt="$lkflags";;
esac
echo " "
rp="Partial linking flags to be used (NOT including -r)?"
. ./myread
case "$ans" in
none) lkflags='';;
*) lkflags="$ans";;
esac

@end
?X:
?X: If the user changes compilers after selecting a hint file, it's
?X: possible that the suggested ccflags/ldflags will be wrong.  Try to
?X: compile and run a simple test program.  Let the user see all the
?X: error messages. -- ADO and RAM
?X:
: coherency check
echo " "
echo "Checking your choice of C compiler and flags for coherency..." >&4
?X: Strip extra blanks in case some of the following variables are empty
set X $cc $optimize $pthread $ccflags $ldflags -o try try.c
shift
$cat >try.msg <<EOM
I've tried to compile and run a simple program with:

	$*
	./try

and I got the following output:

EOM
$cat > try.c <<'EOF'
int main() { return 0; }
EOF
dflt=y
?X: Use "sh -c" to avoid error messages tagged with leading "Configure:".
?X: We need to try the resulting executable, because cc might yield a 0 status
?X: even when ld failed, in which case the executable will not run properly,
?X: if its x bit is set at all...
if sh -c "$cc $optimize $ccflags $ldflags -o try try.c" >>try.msg 2>&1; then
	if sh -c './try' >>try.msg 2>&1; then
		dflt=n
	else
		echo "The program compiled OK, but exited with status $?." >>try.msg
		rp="You have a problem.  Shall I abort Configure"
		dflt=y
	fi
else
	echo "I can't compile the test program." >>try.msg
	rp="You have a BIG problem.  Shall I abort Configure"
	dflt=y
fi
case "$dflt" in
y)
	$cat try.msg >&4
?X: using -K will prevent default aborting--maybe they're cross compiling?
	case "$knowitall" in
	'')
		echo "(The supplied flags might be incorrect with this C compiler.)"
		;;
	*) dflt=n;;
	esac
	echo " "
	. ./myread
	case "$ans" in
	n*|N*) ;;
	*)	echo "Ok.  Stopping Configure." >&4
		exit 1
		;;
	esac
	;;
n) echo "OK, that should do.";;
esac
$rm_try