This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Populate metaconfig branch.
[metaconfig.git] / dist-3.0at70b / mcon / U / cppstdin.U
1 ?RCS: $Id: cppstdin.U,v 3.0.1.4 1994/10/29 16:08:34 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: 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
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 a minus
41 ?S:     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
86 ?T:wrapper x_cpp x_minus ok
87 : see how we invoke the C preprocessor
88 echo " "
89 echo "Now, how can we feed standard input to your C preprocessor..." >&4
90 cat <<'EOT' >testcpp.c
91 #define ABC abc
92 #define XYZ xyz
93 ABC.XYZ
94 EOT
95 cd ..
96 echo 'cat >.$$.c; '"$cc"' -E ${1+"$@"} .$$.c; rm .$$.c' >cppstdin
97 chmod 755 cppstdin
98 wrapper=`pwd`/cppstdin
99 ok='false'
100 cd UU
101
102 ?X:
103 ?X: We'll run the cpp tests again if we don't have any valid C preprocessor
104 ?X: yet or don't know how to proceed without a wrapper (in which case cpprun
105 ?X: is empty and that's really annoying...)
106 ?X:
107 if $test "X$cppstdin" != "X" && \
108         $cppstdin $cppminus <testcpp.c >testcpp.out 2>&1 && \
109         $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1
110 then
111         echo "You used to use $cppstdin $cppminus so we'll use that again."
112         case "$cpprun" in
113         '') echo "But let's see if we can live without a wrapper..." ;;
114         *)
115                 if $cpprun $cpplast <testcpp.c >testcpp.out 2>&1 && \
116                         $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1
117                 then
118                         echo "(And we'll use $cpprun $cpplast to preprocess directly.)"
119                         ok='true'
120                 else
121                         echo "(However, $cpprun $cpplast does not work, let's see...)"
122                 fi
123                 ;;
124         esac
125 else
126         case "$cppstdin" in
127         '') ;;
128         *)
129                 echo "Good old $cppstdin $cppminus does not seem to be of any help..."
130                 ;;
131         esac
132 fi
133
134 if $ok; then
135         : nothing
136 elif echo 'Maybe "'"$cc"' -E" will work...'; \
137         $cc -E <testcpp.c >testcpp.out 2>&1; \
138         $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
139         echo "Yup, it does."
140         x_cpp="$cc -E"
141         x_minus='';
142 elif echo 'Nope...maybe "'"$cc"' -E -" will work...'; \
143         $cc -E - <testcpp.c >testcpp.out 2>&1; \
144         $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
145         echo "Yup, it does."
146         x_cpp="$cc -E"
147         x_minus='-';
148 elif echo 'Nope...maybe "'"$cc"' -P" will work...'; \
149         $cc -P <testcpp.c >testcpp.out 2>&1; \
150         $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
151         echo "Yipee, that works!"
152         x_cpp="$cc -P"
153         x_minus='';
154 elif echo 'Nope...maybe "'"$cc"' -P -" will work...'; \
155         $cc -P - <testcpp.c >testcpp.out 2>&1; \
156         $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
157         echo "At long last!"
158         x_cpp="$cc -P"
159         x_minus='-';
160 elif echo 'No such luck, maybe "'$cpp'" will work...'; \
161         $cpp <testcpp.c >testcpp.out 2>&1; \
162         $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
163         echo "It works!"
164         x_cpp="$cpp"
165         x_minus='';
166 elif echo 'Nixed again...maybe "'$cpp' -" will work...'; \
167         $cpp - <testcpp.c >testcpp.out 2>&1; \
168         $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
169         echo "Hooray, it works!  I was beginning to wonder."
170         x_cpp="$cpp"
171         x_minus='-';
172 elif echo 'Uh-uh.  Time to get fancy.  Trying a wrapper...'; \
173         $wrapper <testcpp.c >testcpp.out 2>&1; \
174         $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
175         x_cpp="$wrapper"
176         x_minus=''
177         echo "Eureka!"
178 else
179         dflt=''
180         rp="No dice.  I can't find a C preprocessor.  Name one:"
181         . ./myread
182         x_cpp="$ans"
183         x_minus=''
184         $x_cpp <testcpp.c >testcpp.out 2>&1
185         if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 ; then
186                 echo "OK, that will do." >&4
187         else
188 echo "Sorry, I can't get that to work.  Go find one and rerun Configure." >&4
189                 exit 1
190         fi
191 fi
192
193 case "$ok" in
194 false)
195         cppstdin="$x_cpp"
196         cppminus="$x_minus"
197         cpprun="$x_cpp"
198         cpplast="$x_minus"
199 ?X:
200 ?X: If /lib/cpp is used, try using a wrapper to increase our chances to have
201 ?X: the C compiler and our $cppstdin agree on the same symbols... However,
202 ?X: since cpprun is guaranteed not to be a wrapper, we must clear it if the
203 ?X: only preprocessor we found was a wrapper, with all our luck...
204 ?X:
205         set X $x_cpp
206         shift
207         case "$1" in
208         "$cpp")
209                 echo "Perhaps can we force $cc -E using a wrapper..."
210                 if $wrapper <testcpp.c >testcpp.out 2>&1; \
211                         $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1
212                 then
213                         echo "Yup, we can."
214                         cppstdin="$wrapper"
215                         cppminus='';
216                 else
217                         echo "Nope, we'll have to live without it..."
218                 fi
219                 ;;
220         esac
221         case "$cpprun" in
222         "$wrapper")
223                 cpprun=''
224                 cpplast=''
225                 ;;
226         esac
227         ;;
228 esac
229
230 case "$cppstdin" in
231 "$wrapper") ;;
232 *) $rm -f $wrapper;;
233 esac
234 $rm -f testcpp.c testcpp.out
235