Commit | Line | Data |
---|---|---|
d8875586 MBT |
1 | ?RCS: $Id: cppfilecom.U 1 2006-08-24 12:32:52Z rmanfredi $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi | |
cf39bd7e | 4 | ?RCS: |
d8875586 MBT |
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: Orginal Author: Graham Stoney <greyham@research.canon.oz.au> | |
12 | ?RCS: | |
13 | ?RCS: $Log: cppfilecom.U,v $ | |
14 | ?RCS: Revision 3.0 1993/08/18 12:05:37 ram | |
15 | ?RCS: Baseline for dist 3.0 netwide release. | |
16 | ?RCS: | |
17 | ?MAKE:cppfilecom cppstdinflags d_cppignhdrs d_cppcanstdin: \ | |
18 | contains package test Myread Oldconfig Loc Setvar cpp cc cat rm | |
19 | ?MAKE: -pick add $@ %< | |
20 | ?S:cppfilecom: | |
21 | ?S: This variable contains the first part of the string which will invoke | |
22 | ?S: the C preprocessor a file and produce to standard output, preserving | |
23 | ?S: comments. Typical value of "cc -E -C" or "/lib/cpp -C". | |
24 | ?S:. | |
25 | ?S:cppstdinflags: | |
26 | ?S: This variable contains any flags necessary to get cppfilecom to read | |
27 | ?S: from the standard input. | |
28 | ?S:. | |
29 | ?S:d_cppignhdrs: | |
30 | ?S: This symbol conditionally defines CPP_IGN_HDRS if CPP_FILE_COM ignores | |
31 | ?S: *.h files. | |
32 | ?S:. | |
33 | ?S:d_cppcanstdin: | |
34 | ?S: This symbol conditionally defines CPP_CAN_STDIN if CPP_FILE_COM can | |
35 | ?S: read standard input directly. | |
36 | ?S:. | |
37 | ?C:CPP_FILE_COM (CPPFILECOM): | |
38 | ?C: This symbol contains the first part of the string which will invoke | |
39 | ?C: the C preprocessor a file and produce to standard output, preserving | |
40 | ?C: comments. Typical value of "cc -E -C" or "/lib/cpp -C". | |
41 | ?C:. | |
42 | ?C:CPP_STDIN_FLAGS (CPPSTDINFLAGS): | |
43 | ?C: This variable contains any flags necessary to get CPP_FILE_COM to | |
44 | ?C: read from the standard input. | |
45 | ?C:. | |
46 | ?C:CPP_IGN_HDRS (CPPIGNHDRS): | |
47 | ?C: This symbol is defined if CPP_FILE_COM ignores *.h files. | |
48 | ?C:. | |
49 | ?C:CPP_CAN_STDIN (CPPCANSTDIN): | |
50 | ?C: This symbol is defined if CPP_FILE_COM can read standard input | |
51 | ?C: directly. | |
52 | ?C:. | |
53 | ?H:#define CPP_FILE_COM "$cppfilecom" | |
54 | ?H:#define CPP_STDIN_FLAGS "$cppstdinflags" | |
55 | ?H:#$d_cppignhdrs CPP_IGN_HDRS /* does CPP ignore .h files? */ | |
56 | ?H:#$d_cppcanstdin CPP_CAN_STDIN /* can CPP read stdin directly? */ | |
57 | ?H:. | |
58 | ?T:cont | |
59 | ?F:!testcpp.c !testcpp.h !testcpp.out | |
60 | ?LINT:set d_cppcanstdin d_cppignhdrs | |
61 | ?LINT:usefile testcpp.c testcpp.out | |
62 | : see how we invoke the C preprocessor | |
63 | $cat <<EOM | |
64 | ||
65 | $package needs to be able to preprocess its input files in a mode which | |
66 | preserves comments, which is often not the default behaviour. It should run | |
67 | the C preprocessor you will use when compiling your own source code, which | |
68 | should be ISO/ANSI C compliant if you want $package to handle the latest | |
69 | standard C. I will try to guess, but I might guess wrongly because it is not | |
70 | necessarily the same preprocessor used to build $package. | |
71 | ||
72 | EOM | |
73 | $cat <<'EOT' >testcpp.c | |
74 | #define ABC abc | |
75 | #define XYZ xyz | |
76 | ABC.XYZ | |
77 | /* comment */ | |
78 | EOT | |
79 | : | |
80 | if $test "X$cppfilecom" != "X" && \ | |
81 | $cppfilecom testcpp.c </dev/null >testcpp.out 2>/dev/null && \ | |
82 | $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 && \ | |
83 | $contains comment testcpp.out >/dev/null 2>&1 | |
84 | then | |
85 | echo "You used to use $cppfilecom so we'll use that again." | |
86 | elif echo 'Maybe "'$cc' -E -C" will work...' && \ | |
87 | $cc -E -C testcpp.c </dev/null >testcpp.out 2>/dev/null && \ | |
88 | $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 && \ | |
89 | $contains comment testcpp.out >/dev/null 2>&1 | |
90 | then | |
91 | echo "It works!" | |
92 | cppfilecom="$cc -E -C" | |
93 | elif echo 'Nope...maybe "'"$cc"' -P -C" will work...' && \ | |
94 | $cc -P -C testcpp.c </dev/null >testcpp.out 2>/dev/null && \ | |
95 | $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 && \ | |
96 | $contains comment testcpp.out >/dev/null 2>&1 | |
97 | then | |
98 | echo "Yup, that does." | |
99 | cppfilecom="$cc -P -C" | |
100 | elif echo 'No such luck, maybe "'"$cpp"' -C" will work...' && \ | |
101 | $cpp -C testcpp.c </dev/null >testcpp.out 2>/dev/null && \ | |
102 | $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 && \ | |
103 | $contains comment testcpp.out >/dev/null 2>&1 | |
104 | then | |
105 | echo "Yup, it does." | |
106 | cppfilecom="$cpp -C" | |
107 | else | |
108 | cppfilecom='' | |
109 | $cat <<'EOM' | |
110 | I can't find a C preprocessor that will preserve comments. Please name one. | |
111 | EOM | |
112 | fi | |
113 | : | |
114 | dflt="$cppfilecom" | |
115 | cont=true | |
116 | while $test "$cont" ; do | |
117 | echo " " | |
118 | rp="How should $package run your preprocessor preserving comments?" | |
119 | . ./myread | |
120 | cppfilecom="$ans" | |
121 | $cppfilecom testcpp.c >testcpp.out 2>&1 | |
122 | if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 && \ | |
123 | $contains comment testcpp.out >/dev/null 2>&1 | |
124 | then | |
125 | echo "OK, that will do." | |
126 | cont='' | |
127 | else | |
128 | echo "Sorry, I can't get that to work." | |
129 | fi | |
130 | done | |
131 | ||
132 | @if CPP_IGN_HDRS || d_cppignhdrs | |
133 | : Now see if it ignores header files. | |
134 | cp testcpp.c testcpp.h | |
135 | $cppfilecom testcpp.h >testcpp.out 2>&1 | |
136 | if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 && \ | |
137 | $contains comment testcpp.out >/dev/null 2>&1 | |
138 | then | |
139 | echo "Terrific; it processes .h files passed on the command line too." | |
140 | val="$undef" | |
141 | else | |
142 | echo "It ignores .h files on the command line; pity." | |
143 | val="$define" | |
144 | fi | |
145 | set d_cppignhdrs | |
146 | eval $setvar | |
147 | ||
148 | @end | |
149 | @if CPP_STDIN_FLAGS || CPP_CAN_STDIN || cppstdinflags || d_cppcanstdin | |
150 | : Now see how to send stdin to it. | |
151 | echo " " | |
152 | cp testcpp.c testcpp.h | |
153 | $cppfilecom <testcpp.h >testcpp.out 2>&1 | |
154 | if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 && \ | |
155 | $contains comment testcpp.out >/dev/null 2>&1 | |
156 | then | |
157 | echo "Great; and it will read stdin if passed no arguments." | |
158 | val="$define" | |
159 | cppstdinflags='' | |
160 | else | |
161 | $cppfilecom - <testcpp.h >testcpp.out 2>&1 | |
162 | if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 && \ | |
163 | $contains comment testcpp.out >/dev/null 2>&1 | |
164 | then | |
165 | echo "Great; and it can read stdin by passing it '-'." | |
166 | val="$define" | |
167 | cppstdinflags='-' | |
168 | else | |
169 | $cat <<FOO | |
170 | Unfortunately, I can't find an easy way to get that preprocessor to read from | |
171 | standard input. Do you know any flags I can pass it to get it to do so? | |
172 | If that preprocessor can't read directly form standard input, answer 'none'. | |
173 | ||
174 | FOO | |
175 | val='dunno' | |
176 | while $test "$val" = "dunno"; do | |
177 | rp='Flags to get preprocessor to read stdin?' | |
178 | dflt='none' | |
179 | . ./myread | |
180 | if $test $ans = 'none'; then | |
181 | echo "Oh well, if $package wants it done, it will do it for itself." | |
182 | val="$undef" | |
183 | else | |
184 | $cppfilecom $ans <testcpp.h >testcpp.out 2>&1 | |
185 | if $contains 'abc.*xyz' testcpp.out >/dev/null 2>&1 && \ | |
186 | $contains comment testcpp.out >/dev/null 2>&1 | |
187 | then | |
188 | echo "Good; that works fine." | |
189 | val="$define" | |
190 | cppstdinflags="$ans" | |
191 | else | |
192 | echo "Sorry, I couldn't get that to work." | |
193 | fi | |
194 | fi | |
195 | done | |
196 | fi | |
197 | fi | |
198 | set d_cppcanstdin | |
199 | eval $setvar | |
200 | ||
201 | @end | |
202 | : cleanup cpp test files anyway | |
203 | $rm -f testcpp.* | |
204 |