This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add the files from dist/meta to perl's repo
[metaconfig.git] / dist / U / cppstdin.U
CommitLineData
d8875586
MBT
1?RCS: $Id: cppstdin.U 1 2006-08-24 12:32:52Z rmanfredi $
2?RCS:
3?RCS: Copyright (c) 1991-1997, 2004-2006, 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 4.0.
10?RCS:
11?RCS: $Log: cppstdin.U,v $
12?RCS: Revision 3.0.1.4 1994/10/29 16:08:34 ram
13?RCS: patch36: added ?F: line for metalint file checking
14?RCS:
15?RCS: Revision 3.0.1.3 1994/01/24 14:05:38 ram
16?RCS: patch16: comment for CPPLAST was missing
17?RCS:
18?RCS: Revision 3.0.1.2 1993/12/15 08:18:58 ram
19?RCS: patch15: new variables cpprun and cpplast, guaranteed wrapper-free
20?RCS: patch15: cppstdin now tries to use cc, even at the cost of a wrapper
21?RCS:
22?RCS: Revision 3.0.1.1 1993/08/25 14:00:53 ram
23?RCS: patch6: remove wrapper when not actually used
24?RCS:
25?RCS: Revision 3.0 1993/08/18 12:05:38 ram
26?RCS: Baseline for dist 3.0 netwide release.
27?RCS:
28?MAKE:cppstdin cppminus cpprun cpplast: contains test Myread Oldconfig Loc \
29 cpp +cc rm hint osname gccversion startsh eunicefix
30?MAKE: -pick add $@ %<
31?S:cppstdin:
32?S: This variable contains the command which will invoke the C
33?S: preprocessor on standard input and put the output to stdout.
34?S: It is primarily used by other Configure units that ask about
35?S: preprocessor symbols.
36?S:.
37?S:cppminus:
38?S: This variable contains the second part of the string which will invoke
39?S: the C preprocessor on the standard input and produce to standard
40?S: output. This variable will have the value "-" if cppstdin needs
41?S: a minus to specify standard input, otherwise the value is "".
42?S:.
43?S:cpprun:
44?S: This variable contains the command which will invoke a C preprocessor
45?S: on standard input and put the output to stdout. It is guaranteed not
46?S: to be a wrapper and may be a null string if no preprocessor can be
47?S: made directly available. This preprocessor might be different from the
48?S: one used by the C compiler. Don't forget to append cpplast after the
49?S: preprocessor options.
50?S:.
51?S:cpplast:
52?S: This variable has the same functionality as cppminus, only it applies to
53?S: cpprun and not cppstdin.
54?S:.
55?C:CPPSTDIN:
56?C: This symbol contains the first part of the string which will invoke
57?C: the C preprocessor on the standard input and produce to standard
58?C: output. Typical value of "cc -E" or "/lib/cpp", but it can also
59?C: call a wrapper. See CPPRUN.
60?C:.
61?C:CPPMINUS:
62?C: This symbol contains the second part of the string which will invoke
63?C: the C preprocessor on the standard input and produce to standard
64?C: output. This symbol will have the value "-" if CPPSTDIN needs a minus
65?C: to specify standard input, otherwise the value is "".
66?C:.
67?C:CPPRUN:
68?C: This symbol contains the string which will invoke a C preprocessor on
69?C: the standard input and produce to standard output. It needs to end
70?C: with CPPLAST, after all other preprocessor flags have been specified.
71?C: The main difference with CPPSTDIN is that this program will never be a
72?C: pointer to a shell wrapper, i.e. it will be empty if no preprocessor is
73?C: available directly to the user. Note that it may well be different from
74?C: the preprocessor used to compile the C program.
75?C:.
76?C:CPPLAST:
77?C: This symbol is intended to be used along with CPPRUN in the same manner
78?C: symbol CPPMINUS is used with CPPSTDIN. It contains either "-" or "".
79?C:.
80?H:#define CPPSTDIN "$cppstdin"
81?H:#define CPPMINUS "$cppminus"
82?H:#define CPPRUN "$cpprun"
83?H:#define CPPLAST "$cpplast"
84?H:.
85?F:cppstdin !testcpp.out !testcpp.c
86?T:wrapper x_cpp x_minus ok
87: see how we invoke the C preprocessor
88echo " "
89echo "Now, how can we feed standard input to your C preprocessor..." >&4
90cat <<'EOT' >testcpp.c
91#define ABC abc
92#define XYZ xyz
93ABC.XYZ
94EOT
95cd ..
96if $test ! -f cppstdin; then
97 echo "$startsh" >cppstdin
98if $test "X$osname" = "Xaix" -a "X$gccversion" = X; then
99?X: AIX cc -E doesn't show the absolute headerfile
100?X: locations but we'll cheat by using the -M flag.
101 echo 'cat >.$$.c; rm -f .$$.u; '"$cc"' ${1+"$@"} -M -c .$$.c 2>/dev/null; \
102 test -s .$$.u && \
103 awk '"'"'$2 ~ /\.h$/ { print "# 0 \""$2"\"" }'"'"' .$$.u; \
104 rm -f .$$.o .$$.u; '"$cc"' -E ${1+"$@"} .$$.c; rm .$$.c' >> cppstdin
105else
106 echo 'cat >.$$.c; '"$cc"' -E ${1+"$@"} .$$.c; rm .$$.c' >>cppstdin
107fi; else
108 echo "Keeping your $hint cppstdin wrapper."
109fi
110chmod 755 cppstdin
111$eunicefix cppstdin
112wrapper=`pwd`/cppstdin
113ok='false'
114cd UU
115
116?X:
117?X: We'll run the cpp tests again if we don't have any valid C preprocessor
118?X: yet or don't know how to proceed without a wrapper (in which case cpprun
119?X: is empty and that's really annoying...)
120?X:
121if $test "X$cppstdin" != "X" && \
122 $cppstdin $cppminus <testcpp.c >testcpp.out 2>&1 && \
123 $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1
124then
125 echo "You used to use $cppstdin $cppminus so we'll use that again."
126 case "$cpprun" in
127 '') echo "But let's see if we can live without a wrapper..." ;;
128 *)
129 if $cpprun $cpplast <testcpp.c >testcpp.out 2>&1 && \
130 $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1
131 then
132 echo "(And we'll use $cpprun $cpplast to preprocess directly.)"
133 ok='true'
134 else
135 echo "(However, $cpprun $cpplast does not work, let's see...)"
136 fi
137 ;;
138 esac
139else
140 case "$cppstdin" in
141 '') ;;
142 *)
143 echo "Good old $cppstdin $cppminus does not seem to be of any help..."
144 ;;
145 esac
146fi
147
148if $ok; then
149 : nothing
150elif echo 'Maybe "'"$cc"' -E" will work...'; \
151 $cc -E <testcpp.c >testcpp.out 2>&1; \
152 $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
153 echo "Yup, it does."
154 x_cpp="$cc -E"
155 x_minus='';
156elif echo 'Nope...maybe "'"$cc"' -E -" will work...'; \
157 $cc -E - <testcpp.c >testcpp.out 2>&1; \
158 $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
159 echo "Yup, it does."
160 x_cpp="$cc -E"
161 x_minus='-';
162elif echo 'Nope...maybe "'"$cc"' -P" will work...'; \
163 $cc -P <testcpp.c >testcpp.out 2>&1; \
164 $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
165 echo "Yipee, that works!"
166 x_cpp="$cc -P"
167 x_minus='';
168elif echo 'Nope...maybe "'"$cc"' -P -" will work...'; \
169 $cc -P - <testcpp.c >testcpp.out 2>&1; \
170 $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
171 echo "At long last!"
172 x_cpp="$cc -P"
173 x_minus='-';
174elif echo 'No such luck, maybe "'$cpp'" will work...'; \
175 $cpp <testcpp.c >testcpp.out 2>&1; \
176 $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
177 echo "It works!"
178 x_cpp="$cpp"
179 x_minus='';
180elif echo 'Nixed again...maybe "'$cpp' -" will work...'; \
181 $cpp - <testcpp.c >testcpp.out 2>&1; \
182 $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
183 echo "Hooray, it works! I was beginning to wonder."
184 x_cpp="$cpp"
185 x_minus='-';
186elif echo 'Uh-uh. Time to get fancy. Trying a wrapper...'; \
187 $wrapper <testcpp.c >testcpp.out 2>&1; \
188 $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
189 x_cpp="$wrapper"
190 x_minus=''
191 echo "Eureka!"
192else
193 dflt=''
194 rp="No dice. I can't find a C preprocessor. Name one:"
195 . ./myread
196 x_cpp="$ans"
197 x_minus=''
198 $x_cpp <testcpp.c >testcpp.out 2>&1
199 if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
200 echo "OK, that will do." >&4
201 else
202echo "Sorry, I can't get that to work. Go find one and rerun Configure." >&4
203 exit 1
204 fi
205fi
206
207case "$ok" in
208false)
209 cppstdin="$x_cpp"
210 cppminus="$x_minus"
211 cpprun="$x_cpp"
212 cpplast="$x_minus"
213?X:
214?X: If /lib/cpp is used, try using a wrapper to increase our chances to have
215?X: the C compiler and our $cppstdin agree on the same symbols... However,
216?X: since cpprun is guaranteed not to be a wrapper, we must clear it if the
217?X: only preprocessor we found was a wrapper, with all our luck...
218?X:
219 set X $x_cpp
220 shift
221 case "$1" in
222 "$cpp")
223 echo "Perhaps can we force $cc -E using a wrapper..."
224 if $wrapper <testcpp.c >testcpp.out 2>&1; \
225 $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1
226 then
227 echo "Yup, we can."
228 cppstdin="$wrapper"
229 cppminus='';
230 else
231 echo "Nope, we'll have to live without it..."
232 fi
233 ;;
234 esac
235 case "$cpprun" in
236 "$wrapper")
237 cpprun=''
238 cpplast=''
239 ;;
240 esac
241 ;;
242esac
243
244case "$cppstdin" in
245"$wrapper"|'cppstdin') ;;
246*) $rm -f $wrapper;;
247esac
248$rm -f testcpp.c testcpp.out
249