This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
evat => eval as found by Tom Hukins
[metaconfig.git] / U / modified / cpp_stuff.U
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 License,
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 License; 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.1  1994/10/29  16:08:24  ram
13 ?RCS: patch36: now uses cppstdin instead of plain cpp for consistency (ADO)
14 ?RCS: patch36: remove temporary files when done
15 ?RCS:
16 ?RCS: Revision 3.0  1993/08/18  12:05:36  ram
17 ?RCS: Baseline for dist 3.0 netwide release.
18 ?RCS:
19 ?MAKE:cpp_stuff: cat contains cppstdin cppflags cppminus rm
20 ?MAKE:  -pick add $@ %<
21 ?S:cpp_stuff:
22 ?S:     This variable contains an identification of the concatenation mechanism
23 ?S:     used by the C preprocessor.
24 ?S:.
25 ?C:CAT2:
26 ?C:     This macro concatenates 2 tokens together.
27 ?C:.
28 ?C:CAT3:
29 ?C:     This macro concatenates 3 tokens together.
30 ?C:.
31 ?C:CAT4:
32 ?C:     This macro concatenates 4 tokens together.
33 ?C:.
34 ?C:CAT5:
35 ?C:     This macro concatenates 5 tokens together.
36 ?C:.
37 ?C:STRINGIFY:
38 ?C:     This macro surrounds its token with double quotes.
39 ?C:.
40 ?C:SCAT2:
41 ?C:     This macro concatenates 2 tokens together and stringifies the result.
42 ?C:     It might not exist, so #ifdef it in your code!
43 ?C:.
44 ?C:SCAT3:
45 ?C:     This macro concatenates 3 tokens together and stringifies the result.
46 ?C:     It might not exist, so #ifdef it in your code!
47 ?C:.
48 ?C:SCAT4:
49 ?C:     This macro concatenates 4 tokens together and stringifies the result.
50 ?C:     It might not exist, so #ifdef it in your code!
51 ?C:.
52 ?C:SCAT5:
53 ?C:     This macro concatenates 5 tokens together and stringifies the result.
54 ?C:     It might not exist, so #ifdef it in your code!
55 ?C:.
56 ?X:     Dist pl70 included the following, but AIX's xlc compiler
57 ?X:     (which is ANSI-ish and has cpp_stuff == 42)) rejects
58 ?X:     The SQuoTe/EQuoTe stuff because the string literals are on
59 ?X:     separate lines.  Sigh.
60 ?X:             Andy Dougherty   24 Feb 1998
61 ?X:     ?H:?%<:#if $cpp_stuff == 1
62 ?X:     ?H:?CAT2:#define CAT2(a,b)a/**/b
63 ?X:     ?H:?CAT3:#define CAT3(a,b,c)a/**/b/**/c
64 ?X:     ?H:?CAT4:#define CAT4(a,b,c,d)a/**/b/**/c/**/d
65 ?X:     ?H:?CAT5:#define CAT5(a,b,c,d,e)a/**/b/**/c/**/d/**/e
66 ?X:     ?H:?STRINGIFY:#define STRINGIFY(a)"a"
67 ?X:     ?H:?%<:#define SQuoTe(a)"a
68 ?X:     ?H:?%<:#define EQuoTe(a)a"
69 ?X:     ?H:?SCAT2:#define SCAT2(a,b)EQuoTe(SQuoTe(a)b)
70 ?X:     ?H:?SCAT3:#define SCAT3(a,b,c)EQuoTe(SQuoTe(a)b/**/c)
71 ?X:     ?H:?SCAT4:#define SCAT4(a,b,c,d)EQuoTe(SQuoTe(a)b/**/c/**/d)
72 ?X:     ?H:?SCAT5:#define SCAT5(a,b,c,d,e)EQuoTe(SQuoTe(a)b/**/c/**/d/**/e)
73 ?X:     ?H:?%<:#endif
74 ?H:?%<:#if $cpp_stuff == 1
75 ?H:?CAT2:#define CAT2(a,b)      a/**/b
76 ?H:?CAT3:#define CAT3(a,b,c)    a/**/b/**/c
77 ?H:?CAT4:#define CAT4(a,b,c,d)  a/**/b/**/c/**/d
78 ?H:?CAT5:#define CAT5(a,b,c,d,e)        a/**/b/**/c/**/d/**/e
79 ?H:?STRINGIFY:#define STRINGIFY(a)      "a"
80 ?X:     If you can get stringification with catify, tell me how!
81 ?H:?%<:#endif
82 ?H:?%<:#if $cpp_stuff == 42
83 ?H:?%<:#define PeRl_CaTiFy(a, b)        a ## b
84 ?H:?%<:#define PeRl_StGiFy(a)   #a
85 ?X: The additional level of indirection enables these macros to be
86 ?X: used as arguments to other macros.  See K&R 2nd ed., page 231.
87 ?H:?CAT2:#define CAT2(a,b)      PeRl_CaTiFy(a,b)
88 ?H:?CAT3:#define CAT3(a,b,c)    CAT2(PeRl_CaTiFy(a,b),c)
89 ?H:?CAT4:#define CAT4(a,b,c,d)  CAT2(CAT3(a,b,c),d)
90 ?H:?CAT5:#define CAT5(a,b,c,d,e)        CAT2(CAT4(a,b,c,d),e)
91 ?H:?%<:#define StGiFy(a)        PeRl_StGiFy(a)
92 ?H:?STRINGIFY:#define STRINGIFY(a)      PeRl_StGiFy(a)
93 ?H:?SCAT2:#define SCAT2(a,b)    PeRl_StGiFy(a) PeRl_StGiFy(b)
94 ?H:?SCAT3:#define SCAT3(a,b,c)  PeRl_StGiFy(a) PeRl_StGiFy(b) PeRl_StGiFy(c)
95 ?H:?SCAT4:#define SCAT4(a,b,c,d)        PeRl_StGiFy(a) PeRl_StGiFy(b) PeRl_StGiFy(c) PeRl_StGiFy(d)
96 ?H:?SCAT5:#define SCAT5(a,b,c,d,e)      PeRl_StGiFy(a) PeRl_StGiFy(b) PeRl_StGiFy(c) PeRl_StGiFy(d) PeRl_StGiFy(e)
97 ?H:?%<:#endif
98 ?H:?%<:#if $cpp_stuff != 1 && $cpp_stuff != 42
99 ?H:?%<:#include "Bletch: How does this C preprocessor concatenate tokens?"
100 ?H:?%<:#endif
101 ?H:.
102 ?W:%<:CAT2 CAT3 CAT4 CAT5 STRINGIFY SCAT2 SCAT3 SCAT4 SCAT5
103 ?F:!cpp_stuff.c
104 ?LINT:known StGiFy
105 ?LINT:known PeRl_CaTiFy
106 ?LINT:known PeRl_StGiFy
107 : how do we concatenate cpp tokens here?
108 echo " "
109 echo "Checking to see how your cpp does stuff like concatenate tokens..." >&4
110 $cat >cpp_stuff.c <<'EOCP'
111 #define RCAT(a,b)a/**/b
112 #define ACAT(a,b)a ## b
113 RCAT(Rei,ser)
114 ACAT(Cir,cus)
115 EOCP
116 $cppstdin $cppflags $cppminus <cpp_stuff.c >cpp_stuff.out 2>&1
117 if $contains 'Circus' cpp_stuff.out >/dev/null 2>&1; then
118         echo "Oh!  Smells like ANSI's been here." >&4
119         echo "We can catify or stringify, separately or together!"
120         cpp_stuff=42
121 elif $contains 'Reiser' cpp_stuff.out >/dev/null 2>&1; then
122         echo "Ah, yes!  The good old days!" >&4
123         echo "However, in the good old days we don't know how to stringify and"
124         echo "catify at the same time."
125         cpp_stuff=1
126 else
127         $cat >&4 <<EOM
128 Hmm, I don't seem to be able to concatenate tokens with your cpp.
129 You're going to have to edit the values of CAT[2-5] in config.h...
130 EOM
131 ?X: It would be nice to have configure remind us at the end that some manual
132 ?X: intervention is needed -- FIXME
133         cpp_stuff="/* Help! How do we handle cpp_stuff? */*/"
134 fi
135 $rm -f cpp_stuff.*
136