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 / cpp_stuff.U
CommitLineData
d8875586
MBT
1?RCS: $Id: cpp_stuff.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: cpp_stuff.U,v $
12?RCS: Revision 3.0.1.2 1997/02/28 15:30:48 ram
13?RCS: patch61: added cute quoting trick for wild stringify support
14?RCS:
15?RCS: Revision 3.0.1.1 1994/10/29 16:08:24 ram
16?RCS: patch36: now uses cppstdin instead of plain cpp for consistency (ADO)
17?RCS: patch36: remove temporary files when done
18?RCS:
19?RCS: Revision 3.0 1993/08/18 12:05:36 ram
20?RCS: Baseline for dist 3.0 netwide release.
21?RCS:
22?MAKE:cpp_stuff cpp_quote: cat contains cppstdin cppflags cppminus rm Warn \
23 package
24?MAKE: -pick add $@ %<
25?S:cpp_stuff:
26?S: This variable contains an identification of the catenation mechanism
27?S: used by the C preprocessor.
28?S:.
29?S:cpp_quote:
30?S: This variable is set to either '"' or '' depending on whether the
31?S: pre-processor pre-dates ANSI or not. It is used in the production of
32?S: the SQuoTe() and EQuoTe() macros, and was introduced to overcome a bug
33?S: in gcc 3.x whereby the pre-processor complained loudly about the
34?S: unterminated strings.
35?S:.
36?C:CAT2:
37?C: This macro catenates 2 tokens together.
38?C:.
39?C:CAT3:
40?C: This macro catenates 3 tokens together.
41?C:.
42?C:CAT4:
43?C: This macro catenates 4 tokens together.
44?C:.
45?C:CAT5:
46?C: This macro catenates 5 tokens together.
47?C:.
48?C:STRINGIFY:
49?C: This macro surrounds its token with double quotes.
50?C:.
51?C:SCAT2:
52?C: This macro catenates 2 tokens together and stringifies the result.
53?C:.
54?C:SCAT3:
55?C: This macro catenates 3 tokens together and stringifies the result.
56?C:.
57?C:SCAT4:
58?C: This macro catenates 4 tokens together and stringifies the result.
59?C:.
60?C:SCAT5:
61?C: This macro catenates 5 tokens together and stringifies the result.
62?C:.
63?H:?%<:#if $cpp_stuff == 1
64?H:?CAT2:#define CAT2(a,b)a/**/b
65?H:?CAT3:#define CAT3(a,b,c)a/**/b/**/c
66?H:?CAT4:#define CAT4(a,b,c,d)a/**/b/**/c/**/d
67?H:?CAT5:#define CAT5(a,b,c,d,e)a/**/b/**/c/**/d/**/e
68?H:?STRINGIFY:#define STRINGIFY(a)"a"
69?H:?%<:#define SQuoTe(a)${cpp_quote}a
70?H:?%<:#define EQuoTe(a)a${cpp_quote}
71?H:?SCAT2:#define SCAT2(a,b)EQuoTe(SQuoTe(a)b)
72?H:?SCAT3:#define SCAT3(a,b,c)EQuoTe(SQuoTe(a)b/**/c)
73?H:?SCAT4:#define SCAT4(a,b,c,d)EQuoTe(SQuoTe(a)b/**/c/**/d)
74?H:?SCAT5:#define SCAT5(a,b,c,d,e)EQuoTe(SQuoTe(a)b/**/c/**/d/**/e)
75?H:?%<:#endif
76?H:?%<:#if $cpp_stuff == 42
77?X: The additional level of indirection enables these macros to be
78?X: used as arguments to other macros. See K&R 2nd ed., page 231.
79?H:?%<:#define CaTiFy(a,b) a ## b
80?H:?%<:#define CAT2(a,b) CaTiFy(a,b)
81?H:?CAT3:#define CAT3(a,b,c) CAT2(CaTiFy(a,b),c)
82?H:?CAT4:#define CAT4(a,b,c,d) CAT2(CaTiFy(a,b), CaTiFy(c,d))
83?H:?CAT5:#define CAT5(a,b,c,d,e) CAT2(CAT2(CaTiFy(a,b), CaTiFy(c,d)), e)
84?H:?%<:#define StGiFy(a)# a
85?H:?STRINGIFY:#define STRINGIFY(a)StGiFy(a)
86?H:?SCAT2:#define SCAT2(a,b)StGiFy(a) StGiFy(b)
87?H:?SCAT3:#define SCAT3(a,b,c)StGiFy(a) StGiFy(b) StGiFy(c)
88?H:?SCAT4:#define SCAT4(a,b,c,d)StGiFy(a) StGiFy(b) StGiFy(c) StGiFy(d)
89?H:?SCAT5:#define SCAT5(a,b,c,d,e)StGiFy(a) StGiFy(b) StGiFy(c) StGiFy(d) StGiFy(e)
90?H:?%<:#endif
91?H:?%<:#if $cpp_stuff != 1 && $cpp_stuff != 42
92?H:?%<:#include "Bletch: How does this C preprocessor catenate tokens?"
93?H:?%<:#endif
94?H:.
95?W:%<:CAT2 CAT3 CAT4 CAT5 STRINGIFY SCAT2 SCAT3 SCAT4 SCAT5
96?F:!cpp_stuff.c
97?LINT:known StGiFy EQuoTe SQuoTe CaTiFy
98: how do we catenate cpp tokens here?
99echo " "
100echo "Checking to see how your cpp does stuff like catenate tokens..." >&4
101cpp_quote=''
102$cat >cpp_stuff.c <<'EOCP'
103#define RCAT(a,b)a/**/b
104#define ACAT(a,b)a ## b
105RCAT(Rei,ser)
106ACAT(Cir,cus)
107EOCP
108$cppstdin $cppflags $cppminus <cpp_stuff.c >cpp_stuff.out 2>&1
109if $contains 'Circus' cpp_stuff.out >/dev/null 2>&1; then
110 echo "Oh! Smells like ANSI's been here."
111 echo "We can catify or stringify, separately or together!"
112 cpp_stuff=42
113elif $contains 'Reiser' cpp_stuff.out >/dev/null 2>&1; then
114 echo "Ah, yes! The good old days!"
115 cpp_stuff=1
116 $cat >cpp_stuff.c <<'EOCP'
117#define SQuoTe(a)"a
118#define EQuoTe(a)a"
119#define CAT2(a,b)EQuoTe(SQuoTe(a)b)
120CAT2(Vic,tory)
121EOCP
122 $cppstdin $cppflags $cppminus <cpp_stuff.c >cpp_stuff.out 2>&1
123 if $contains '"Victory"' cpp_stuff.out >/dev/null 2>&1; then
124 echo "I'll resort to a cute trick to also be able to stringify."
125 cpp_quote='"'
126 else
127 $cat <<EOM
128However, in the good old days we don't know how to stringify and
129catify at the same time...
130@if SCAT2 || SCAT3 || SCAT4 || SCAT5
131You might have to edit the values of the SCAT[2-5] macros in config.h...
132@else
133Hopefully, $package does not need this feature.
134@end
135EOM
136 fi
137else
138 ./warn <<EOM
139I can't seem to be able to catenate tokens with your cpp.
140@if CAT2 || CAT3 || CAT4 || CAT5 || SCAT2 || SCAT3 || SCAT4 || SCAT5
141You're going to have to edit the values of the following
142macros in config.h:
143
144@if CAT2 || CAT3 || CAT4 || CAT5
145 CAT[2-5]
146@end
147@if SCAT2 || SCAT3 || SCAT4 || SCAT5
148 SCAT[2-5]
149@end
150
151in order to let me compile.
152@end
153EOM
154 cpp_stuff="/* Help! How do we handle cpp_stuff? */*/"
155fi
156$rm -f cpp_stuff.*
157