1 ?RCS: $Id: cppfilecom.U 1 2006-08-24 12:32:52Z rmanfredi $
3 ?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
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.
11 ?RCS: Orginal Author: Graham Stoney <greyham@research.canon.oz.au>
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.
17 ?MAKE:cppfilecom cppstdinflags d_cppignhdrs d_cppcanstdin: \
18 contains package test Myread Oldconfig Loc Setvar cpp cc cat rm
19 ?MAKE: -pick add $@ %<
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".
26 ?S: This variable contains any flags necessary to get cppfilecom to read
27 ?S: from the standard input.
30 ?S: This symbol conditionally defines CPP_IGN_HDRS if CPP_FILE_COM ignores
34 ?S: This symbol conditionally defines CPP_CAN_STDIN if CPP_FILE_COM can
35 ?S: read standard input directly.
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".
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.
46 ?C:CPP_IGN_HDRS (CPPIGNHDRS):
47 ?C: This symbol is defined if CPP_FILE_COM ignores *.h files.
49 ?C:CPP_CAN_STDIN (CPPCANSTDIN):
50 ?C: This symbol is defined if CPP_FILE_COM can read standard input
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? */
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
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.
73 $cat <<'EOT' >testcpp.c
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
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
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
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
110 I can't find a C preprocessor that will preserve comments. Please name one.
116 while $test "$cont" ; do
118 rp="How should $package run your preprocessor preserving comments?"
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
125 echo "OK, that will do."
128 echo "Sorry, I can't get that to work."
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
139 echo "Terrific; it processes .h files passed on the command line too."
142 echo "It ignores .h files on the command line; pity."
149 @if CPP_STDIN_FLAGS || CPP_CAN_STDIN || cppstdinflags || d_cppcanstdin
150 : Now see how to send stdin to it.
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
157 echo "Great; and it will read stdin if passed no arguments."
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
165 echo "Great; and it can read stdin by passing it '-'."
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'.
176 while $test "$val" = "dunno"; do
177 rp='Flags to get preprocessor to read stdin?'
180 if $test $ans = 'none'; then
181 echo "Oh well, if $package wants it done, it will do it for itself."
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
188 echo "Good; that works fine."
192 echo "Sorry, I couldn't get that to work."
202 : cleanup cpp test files anyway