summaryrefslogtreecommitdiff
path: root/mcon/U/voidflags.U
blob: 6ca70fefbb1e8c7d8f169cffa81823193383a3c4 (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
?RCS: $Id$
?RCS:
?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
?RCS: 
?RCS: You may redistribute only under the terms of the Artistic Licence,
?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 Licence; a copy of which may be found at the root
?RCS: of the source tree for dist 4.0.
?RCS:
?RCS: $Log: voidflags.U,v $
?RCS: Revision 3.0.1.2  1997/02/28  16:27:58  ram
?RCS: patch61: don't prompt them if the void support is high enough for us
?RCS:
?RCS: Revision 3.0.1.1  1995/01/11  15:37:44  ram
?RCS: patch45: cosmetic change to avoid spurious blank lines when using -s
?RCS:
?RCS: Revision 3.0  1993/08/18  12:10:01  ram
?RCS: Baseline for dist 3.0 netwide release.
?RCS:
?MAKE:voidflags defvoidused: cat sed rm contains +cc +ccflags package \
	Oldconfig Myread
?MAKE:	-pick add $@ %<
?S:voidflags:
?S:	This variable contains the eventual value of the VOIDFLAGS symbol,
?S:	which indicates how much support of the void type is given by this
?S:	compiler.  See VOIDFLAGS for more info.
?S:.
?S:defvoidused:
?S:	This variable contains the default value of the VOIDUSED symbol (15).
?S:.
?X:	Exceptionally, we have to explicitely alias the symbol name for
?X: config_h.SH, otherwise the comment would not appear.
?C:VOIDFLAGS ~ %<:
?C:	This symbol indicates how much support of the void type is given by this
?C:	compiler.  What various bits mean:
?C:
?C:	    1 = supports declaration of void
?C:	    2 = supports arrays of pointers to functions returning void
?C:	    4 = supports comparisons between pointers to void functions and
?C:		    addresses of void functions
?C:	    8 = suports declaration of generic void pointers
?C:
?C:	The package designer should define VOIDUSED to indicate the requirements
?C:	of the package.  This can be done either by #defining VOIDUSED before
?C:	including config.h, or by defining defvoidused in Myinit.U.  If the
?C:	latter approach is taken, only those flags will be tested.  If the
?C:	level of void support necessary is not present, defines void to int.
?C:.
?H:?%<:#ifndef VOIDUSED
?H:?%<:#define VOIDUSED $defvoidused
?H:?%<:#endif
?H:?%<:#define VOIDFLAGS $voidflags
?H:?%<:#if (VOIDFLAGS & VOIDUSED) != VOIDUSED
?H:?%<:#define void int		/* is void to be avoided? */
?H:?%<:#define M_VOID			/* Xenix strikes again */
?H:?%<:#endif
?H:.
?W:%<:void
?F:!.out !try.c !flags
?LINT:usefile .out flags try.c
?INIT:: full support for void wanted by default
?INIT:defvoidused=15
?INIT:
?LINT:known void M_VOID VOIDUSED
: check for void type
echo " "
echo "Checking to see how well your C compiler groks the void type..." >&4
$cat >flags <<EOM

  Support flag bits are:
    1: basic void declarations.
    2: arrays of pointers to functions returning void.
    4: operations between pointers to and addresses of void functions.
    8: generic void pointers.

EOM
case "$voidflags" in
'')
	$cat >try.c <<'EOCP'
#if TRY & 1
void sub() {
#else
sub() {
#endif
	extern void moo();	/* function returning void */
	void (*goo)();		/* ptr to func returning void */
#if TRY & 8
	void *hue;		/* generic ptr */
#endif
#if TRY & 2
	void (*foo[10])();
#endif

#if TRY & 4
	if(goo == moo) {
		exit(0);
	}
#endif
	exit(0);
}
int main() { sub(); }
EOCP
?X: This unit used to use cc -S in those tests to try to speed up things, but
?X: unfortunately, AIX 3.2 does not support this option.
	if $cc $ccflags -c -DTRY=$defvoidused try.c >.out 2>&1 ; then
		voidflags=$defvoidused
		echo "Good.  It appears to support void to the level $package wants."
		if $contains warning .out >/dev/null 2>&1; then
			echo "However, you might get some warnings that look like this:"
			$sed -e 's/^/	/' .out
		fi
	else
echo "Hmm, your compiler has some difficulty with void. Checking further..." >&4
		$cat >&4 flags
		$rm -f flags
		if $cc $ccflags -c -DTRY=1 try.c >/dev/null 2>&1; then
			echo "It supports 1..."
			if $cc $ccflags -c -DTRY=3 try.c >/dev/null 2>&1; then
				echo "It also supports 2..."
				if $cc $ccflags -c -DTRY=7 try.c >/dev/null 2>&1; then
					voidflags=7
					echo "And it supports 4 but not 8 definitely."
				else
					echo "It doesn't support 4..."
					if $cc $ccflags -c -DTRY=11 try.c >/dev/null 2>&1; then
						voidflags=11
						echo "But it supports 8."
					else
						voidflags=3
						echo "Neither does it support 8."
					fi
				fi
			else
				echo "It does not support 2..."
				if $cc $ccflags -c -DTRY=13 try.c >/dev/null 2>&1; then
					voidflags=13
					echo "But it supports 4 and 8."
				else
					if $cc $ccflags -c -DTRY=5 try.c >/dev/null 2>&1; then
						voidflags=5
						echo "And it supports 4 but has not heard about 8."
					else
						echo "However it supports 8 but not 4."
					fi
				fi
			fi
		else
			echo "There is no support at all for void."
			voidflags=0
		fi
	fi
esac
?X: Only prompt user if support does not match the level we want
case "$voidflags" in
"$defvoidused")
	echo "Good.  I already know it supports void to the level $package wants."
	;;
*)
	dflt="$voidflags";
	test -f flags && $cat flags
	rp="Your void support flags add up to what?"
	. ./myread
	voidflags="$ans"
	;;
esac
$rm -f try.* .out flags