Commit | Line | Data |
---|---|---|
959f3c4c JH |
1 | ?RCS: $Id: Cppsym.U,v 3.0.1.5 1995/05/12 11:59:11 ram Exp $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1993, Raphael Manfredi | |
4c42341b | 4 | ?RCS: |
959f3c4c JH |
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: Cppsym.U,v $ | |
12 | ?RCS: Revision 3.0.1.5 1995/05/12 11:59:11 ram | |
13 | ?RCS: patch54: split awk command onto two lines for older awks (ADO) | |
14 | ?RCS: | |
15 | ?RCS: Revision 3.0.1.4 1995/01/11 14:55:57 ram | |
16 | ?RCS: patch45: new cc vs. cpp symbol checking suggested by JHI | |
17 | ?RCS: patch45: added more cpp symbols (JHI) | |
18 | ?RCS: | |
19 | ?RCS: Revision 3.0.1.3 1994/10/29 15:51:32 ram | |
20 | ?RCS: patch36: added ?F: line for metalint file checking | |
21 | ?RCS: patch36: new symbols ardent and titan (ADO) | |
22 | ?RCS: | |
23 | ?RCS: Revision 3.0.1.2 1994/06/20 06:53:32 ram | |
24 | ?RCS: patch30: extended cpp symbol lookup list (JHI) | |
25 | ?RCS: patch30: renamed attrlist symbol into al for brevity | |
26 | ?RCS: | |
27 | ?RCS: Revision 3.0.1.1 1993/12/15 08:14:14 ram | |
28 | ?RCS: patch15: added new cpp symbols __bsdi__ and BSD_NET2 | |
29 | ?RCS: | |
30 | ?RCS: Revision 3.0 1993/08/18 12:04:50 ram | |
31 | ?RCS: Baseline for dist 3.0 netwide release. | |
32 | ?RCS: | |
959f3c4c JH |
33 | ?X: This unit produces a shell script called Cppsym, which can be used to |
34 | ?X: determine whether any in a list of symbols is defined by the C compilation | |
35 | ?X: chain (C preprocessor symbols plus C compiler native ones). | |
36 | ?X: It can determine the status of any symbol, though the symbols in $al | |
37 | ?X: are more easily determined. If you want to add to $al you can do | |
38 | ?X: it in Myinit.U. | |
0f00356b | 39 | ?MAKE:Cppsym ccsymbols cppsymbols cppccsymbols: run \ |
2cb64bf6 | 40 | eunicefix Guess awk cat tr sed sort rm rm_try startsh osname \ |
d088635c | 41 | +cc +gccversion test comm uniq echo Options trnl \ |
78e210bb | 42 | optimize ccflags ldflags libs cpp_stuff cpp |
959f3c4c | 43 | ?MAKE: -pick add $@ %< |
51c6a14b | 44 | ?T:also symbols i postprocess_cc_v tHdrH |
959f3c4c JH |
45 | ?X: |
46 | ?X: The symbol list is in alpha order for ease of maintenance... | |
47 | ?X: | |
48 | ?X: Lots of new symbols (mostly rummaged from gcc), courtesy of | |
49 | ?X: Jarkko Hietaniemi <jhi@snakemail.hut.fi> -- RAM, 06/06/94 | |
50 | ?X: | |
959f3c4c JH |
51 | ?S:ccsymbols: |
52 | ?S: The variable contains the symbols defined by the C compiler alone. | |
d7daf0d3 YST |
53 | ?S: The symbols defined by cpp or by cc when it calls cpp are not in |
54 | ?S: this list, see cppsymbols and cppccsymbols. | |
959f3c4c JH |
55 | ?S: The list is a space-separated list of symbol=value tokens. |
56 | ?S:. | |
57 | ?S:cppsymbols: | |
d7daf0d3 YST |
58 | ?S: The variable contains the symbols defined by the C preprocessor |
59 | ?S: alone. The symbols defined by cc or by cc when it calls cpp are | |
60 | ?S: not in this list, see ccsymbols and cppccsymbols. | |
959f3c4c JH |
61 | ?S: The list is a space-separated list of symbol=value tokens. |
62 | ?S:. | |
63 | ?S:cppccsymbols: | |
d7daf0d3 YST |
64 | ?S: The variable contains the symbols defined by the C compiler |
65 | ?S: when it calls cpp. The symbols defined by the cc alone or cpp | |
66 | ?S: alone are not in this list, see ccsymbols and cppsymbols. | |
959f3c4c JH |
67 | ?S: The list is a space-separated list of symbol=value tokens. |
68 | ?S:. | |
86b170fb | 69 | ?F:./Cppsym |
4c42341b | 70 | ?F:./Cppsym.know |
959f3c4c JH |
71 | ?F:!Cppsym.true |
72 | ?F:!ccsym.com | |
73 | ?F:!ccsym.cpp | |
74 | ?F:!ccsym.own | |
d088635c | 75 | ?X: fake LINT hints |
d088635c | 76 | ?LINT:change ccflags |
d088635c | 77 | ?LINT:extern s |
d088635c | 78 | ?LINT:extern s__ |
4c42341b | 79 | : Preprocessor symbols |
959f3c4c | 80 | echo " " |
51c6a14b | 81 | $echo "Guessing which symbols your C compiler and preprocessor define..." >&4 |
86b170fb JH |
82 | ?X: If your symbol is mixed case, just add it as-is. |
83 | ?X: All symbols will be transformed to both all-lower and all-upper. | |
84 | ?X: Also drop any leading/trailing underscores, the scan will try all those. | |
762256f8 JH |
85 | $cat <<'EOSH' > Cppsym.know |
86 | a29k ABI64 aegis AES_SOURCE AIX AIX32 AIX370 | |
87 | AIX41 AIX42 AIX43 AIX_SOURCE aixpc ALL_SOURCE | |
0ec577e1 | 88 | alliant alpha am29000 AM29000 AMD64 amd64 amiga AMIGAOS AMIX |
56542514 JH |
89 | ansi ANSI_C_SOURCE apollo ardent ARM32 atarist att386 att3b |
90 | BeOS BIG_ENDIAN BIT_MSF bsd BSD bsd43 bsd4_2 bsd4_3 BSD4_3 bsd4_4 | |
762256f8 JH |
91 | BSD_4_3 BSD_4_4 BSD_NET2 BSD_TIME BSD_TYPES BSDCOMPAT bsdi |
92 | bull c cadmus clipper CMU COFF COMPILER_VERSION | |
93 | concurrent convex cpu cray CRAY CRAYMPP ctix CX_UX | |
4ff149d0 | 94 | CYGWIN DECC DGUX DGUX_SOURCE DJGPP dmert DOLPHIN DPX2 DSO |
ccf2d453 JH |
95 | Dynix DynixPTX ELF encore EPI EXTENSIONS FAVOR_BSD |
96 | FILE_OFFSET_BITS FreeBSD GCC_NEW_VARARGS gcos gcx gimpel | |
97 | GLIBC GLIBC_MINOR | |
98 | GNU_SOURCE GNUC GNUC_MINOR GNU_LIBRARY GO32 gould GOULD_PN | |
762256f8 JH |
99 | H3050R H3050RX hbullx20 hcx host_mips |
100 | hp200 hp300 hp700 HP700 hp800 hp9000 | |
101 | hp9000s200 hp9000s300 hp9000s400 hp9000s500 | |
102 | hp9000s700 hp9000s800 hp9k8 hp_osf hppa hpux HPUX_SOURCE | |
103 | i186 i286 i386 i486 i586 i686 i8086 i80960 i860 I960 | |
56542514 | 104 | IA64 iAPX286 ibm ibm032 ibmesa IBMR2 ibmrt ILP32 ILP64 |
762256f8 JH |
105 | INLINE_INTRINSICS INTRINSICS INT64 interdata is68k ksr1 |
106 | LANGUAGE_C LARGE_FILE_API LARGEFILE64_SOURCE | |
107 | LARGEFILE_SOURCE LFS64_LARGEFILE LFS_LARGEFILE | |
a9e6d282 | 108 | LIBCATAMOUNT Linux LITTLE_ENDIAN LONG64 LONG_DOUBLE LONG_LONG |
762256f8 JH |
109 | LONGDOUBLE LONGLONG LP64 luna luna88k Lynx |
110 | M68000 m68k m88100 m88k M88KBCS_TARGET M_COFF | |
111 | M_I186 M_I286 M_I386 M_I8086 M_I86 M_I86SM M_SYS3 | |
112 | M_SYS5 M_SYSIII M_SYSV M_UNIX M_XENIX MACH machine MachTen | |
113 | MATH_HAS_NO_SIDE_EFFECTS | |
114 | mc300 mc500 mc68000 mc68010 mc68020 mc68030 mc68040 | |
115 | mc68060 mc68k mc68k32 mc700 mc88000 mc88100 merlin | |
116 | mert MiNT mips MIPS_FPSET MIPS_ISA MIPS_SIM MIPS_SZINT | |
117 | MIPS_SZLONG MIPS_SZPTR MIPSEB MIPSEL MODERN_C motorola | |
118 | mpeix MSDOS MTXINU MULTIMAX mvs MVS n16 ncl_el ncl_mr | |
119 | NetBSD news1500 news1700 news1800 news1900 news3700 | |
5bcf820f | 120 | news700 news800 news900 NeXT NLS nonstopux ns16000 ns32000 |
762256f8 JH |
121 | ns32016 ns32332 ns32k nsc32000 |
122 | OCS88 OEMVS OpenBSD os OS2 OS390 osf OSF1 OSF_SOURCE | |
123 | pa_risc PA_RISC1_1 PA_RISC2_0 PARAGON parisc | |
124 | pc532 pdp11 PGC PIC plexus PORTAR posix | |
125 | POSIX1B_SOURCE POSIX2_SOURCE POSIX4_SOURCE | |
126 | POSIX_C_SOURCE POSIX_SOURCE POWER | |
a9e6d282 | 127 | PROTOTYPES PWB pyr QNX QK_USER R3000 REENTRANT RES Rhapsody RISC6000 |
56542514 | 128 | riscix riscos RT S390 SA110 scs SCO sequent sgi SGI_SOURCE SH3 sinix |
762256f8 JH |
129 | SIZE_INT SIZE_LONG SIZE_PTR SOCKET_SOURCE SOCKETS_SOURCE |
130 | sony sony_news sonyrisc sparc sparclite spectrum | |
131 | stardent stdc STDC_EXT stratos sun sun3 sun386 | |
132 | Sun386i svr3 svr4 SVR4_2 SVR4_SOURCE svr5 | |
133 | SX system SYSTYPE_BSD SYSTYPE_BSD43 SYSTYPE_BSD44 | |
134 | SYSTYPE_SVR4 SYSTYPE_SVR5 SYSTYPE_SYSV SYSV SYSV3 SYSV4 SYSV5 | |
135 | sysV68 sysV88 Tek4132 Tek4300 titan | |
56542514 | 136 | TM3200 TM5400 TM5600 |
762256f8 JH |
137 | tower tower32 tower32_200 tower32_600 tower32_700 |
138 | tower32_800 tower32_850 tss | |
139 | u370 u3b u3b2 u3b20 u3b200 u3b20d u3b5 | |
140 | ultrix UMAXV UnicomPBB UnicomPBD UNICOS UNICOSMK | |
ccf2d453 JH |
141 | unix UNIX95 UNIX99 unixpc unos |
142 | USE_BSD USE_FILE_OFFSET64 USE_GNU USE_ISOC9X USE_LARGEFILE USE_LARGEFILE64 | |
143 | USE_MISC USE_POSIX USE_POSIX199309 USE_POSIX199506 USE_POSIX2 | |
144 | USE_REENTRANT USE_SVID USE_UNIX98 USE_XOPEN USE_XOPEN_EXTENDED | |
145 | USGr4 USGr4_2 | |
0ec577e1 | 146 | Utek UTek UTS UWIN uxpm uxps vax venix VMESA vms x86_64 xenix Xenix286 |
762256f8 JH |
147 | XOPEN_SOURCE XOPEN_SOURCE_EXTENDED XPG2 XPG2_EXTENDED |
148 | XPG3 XPG3_EXTENDED XPG4 XPG4_EXTENDED | |
149 | z8000 | |
150 | EOSH | |
151 | # Maybe put other stuff here too. | |
152 | cat <<EOSH >>Cppsym.know | |
153 | $osname | |
154 | EOSH | |
8a77dbe2 JH |
155 | ./tr '[a-z]' '[A-Z]' < Cppsym.know > Cppsym.a |
156 | ./tr '[A-Z]' '[a-z]' < Cppsym.know > Cppsym.b | |
d7daf0d3 | 157 | $cat Cppsym.know > Cppsym.c |
a3e4b67c | 158 | $cat Cppsym.a Cppsym.b Cppsym.c | $tr ' ' $trnl | $sort | $uniq > Cppsym.know |
d7daf0d3 | 159 | $rm -f Cppsym.a Cppsym.b Cppsym.c |
86b170fb JH |
160 | cat <<EOSH > Cppsym |
161 | $startsh | |
162 | if $test \$# -gt 0; then | |
d088635c JH |
163 | echo \$* | $tr " " "$trnl" | ./Cppsym.try > Cppsym.got |
164 | if $test -s Cppsym.got; then | |
165 | $rm -f Cppsym.got | |
166 | exit 0 | |
167 | fi | |
168 | $rm -f Cppsym.got | |
169 | exit 1 | |
86b170fb | 170 | else |
d088635c JH |
171 | $tr " " "$trnl" | ./Cppsym.try |
172 | exit 0 | |
86b170fb | 173 | fi |
86b170fb JH |
174 | EOSH |
175 | chmod +x Cppsym | |
176 | $eunicefix Cppsym | |
d088635c JH |
177 | ?X: The below awk script will die a horrible death if |
178 | ?X: some of the tested symbols are not long ints. | |
179 | ?X: Also, we do not make difference between just defined and defined zero. | |
86b170fb | 180 | cat <<EOSH > Cppsym.try |
d088635c | 181 | $startsh |
4ca3dd4c JH |
182 | cat <<'EOCP' > try.c |
183 | #include <stdio.h> | |
75ef64fe YST |
184 | #if cpp_stuff == 1 |
185 | #define STRINGIFY(a) "a" | |
186 | #endif | |
187 | #if cpp_stuff == 42 | |
188 | #define StGiFy(a) #a | |
189 | #define STRINGIFY(a) StGiFy(a) | |
190 | #endif | |
191 | #if $cpp_stuff != 1 && $cpp_stuff != 42 | |
192 | # include "Bletch: How does this C preprocessor stringify macros?" | |
193 | #endif | |
4ca3dd4c JH |
194 | int main() { |
195 | EOCP | |
762256f8 | 196 | ?X: The length($1) command guards against possible empty entries. |
d7daf0d3 | 197 | ?X: The awk snippet is know to give heartburn to UNICOS/mk awk. |
86b170fb JH |
198 | $awk \\ |
199 | EOSH | |
200 | cat <<'EOSH' >> Cppsym.try | |
201 | 'length($1) > 0 { | |
75ef64fe YST |
202 | printf "#ifdef %s\nprintf(\"%s=%%s\\n\", STRINGIFY(%s));\n#endif\n", $1, $1, $1 |
203 | printf "#ifdef _%s\nprintf(\"_%s=%%s\\n\", STRINGIFY(_%s));\n#endif\n", $1, $1, $1 | |
204 | printf "#ifdef __%s\nprintf(\"__%s=%%s\\n\", STRINGIFY(__%s));\n#endif\n", $1, $1, $1 | |
205 | printf "#ifdef __%s__\nprintf(\"__%s__=%%s\\n\", STRINGIFY(__%s__));\n#endif\n", $1, $1, $1 | |
d088635c | 206 | }' >> try.c |
7857a0f2 | 207 | echo 'return 0;}' >> try.c |
86b170fb | 208 | EOSH |
d088635c | 209 | cat <<EOSH >> Cppsym.try |
d088635c | 210 | ccflags="$ccflags" |
d1467975 JH |
211 | case "$osname-$gccversion" in |
212 | irix-) ccflags="\$ccflags -woff 1178" ;; | |
d7daf0d3 | 213 | os2-*) ccflags="\$ccflags -Zlinker /PM:VIO" ;; |
d1467975 | 214 | esac |
75ef64fe | 215 | $cc -o try -Dcpp_stuff=$cpp_stuff $optimize \$ccflags $ldflags try.c $libs && $run ./try | $sed 's/ /\\\\ /g' |
86b170fb JH |
216 | EOSH |
217 | chmod +x Cppsym.try | |
218 | $eunicefix Cppsym.try | |
219 | ./Cppsym < Cppsym.know > Cppsym.true | |
51c6a14b | 220 | : Add in any linux cpp "predefined macros": |
f35fd5db | 221 | case "$osname::$gccversion" in |
35385b28 | 222 | *linux*::*.*|*gnukfreebsd*::*.*|gnu::*.*) |
f35fd5db MB |
223 | tHdrH=_tmpHdr |
224 | rm -f $tHdrH'.h' $tHdrH | |
225 | touch $tHdrH'.h' | |
395c24d9 | 226 | # Filter out macro arguments, such as Linux's __INT8_C(c) |
78e210bb | 227 | if $cpp -dM $tHdrH'.h' > $tHdrH'_cppsym.h' && [ -s $tHdrH'_cppsym.h' ]; then |
395c24d9 | 228 | sed -e 's/#define[\ \ ]*//;s/[\ \ ].*$//' -e 's/(.*//' <$tHdrH'_cppsym.h' >$tHdrH'_cppsym.real' |
f35fd5db MB |
229 | if [ -s $tHdrH'_cppsym.real' ]; then |
230 | cat $tHdrH'_cppsym.real' Cppsym.know | sort | uniq | ./Cppsym | sort | uniq > Cppsym.true | |
231 | fi | |
232 | fi | |
233 | rm -f $tHdrH'.h' $tHdrH'_cppsym.h' $tHdrH'_cppsym.real' | |
234 | ;; | |
235 | esac | |
959f3c4c JH |
236 | : now check the C compiler for additional symbols |
237 | ?X: suggested by Jarkko Hietaniemi <jhi@snakemail.hut.fi>, thanks! | |
238 | postprocess_cc_v='' | |
239 | case "$osname" in | |
240 | aix) postprocess_cc_v="|$tr , ' '" ;; | |
241 | esac | |
242 | $cat >ccsym <<EOS | |
243 | $startsh | |
244 | $cat >tmp.c <<EOF | |
245 | extern int foo; | |
246 | EOF | |
247 | for i in \`$cc -v -c tmp.c 2>&1 $postprocess_cc_v\` | |
248 | do | |
249 | case "\$i" in | |
250 | -D*) echo "\$i" | $sed 's/^-D//';; | |
9a944a00 | 251 | -A*) $test "$gccversion" && echo "\$i" | $sed 's/^-A//' | $sed 's/\(.*\)(\(.*\))/\1=\2/';; |
959f3c4c JH |
252 | esac |
253 | done | |
2cb64bf6 | 254 | $rm_try |
959f3c4c JH |
255 | EOS |
256 | postprocess_cc_v='' | |
257 | chmod +x ccsym | |
258 | $eunicefix ccsym | |
259 | ./ccsym > ccsym1.raw | |
260 | ?X: AIX complains if $uniq is passed an empty file. ($sort apparently | |
261 | ?X: doesn't care.) --AD 14 July 1998 | |
262 | if $test -s ccsym1.raw; then | |
263 | $sort ccsym1.raw | $uniq >ccsym.raw | |
264 | else | |
265 | mv ccsym1.raw ccsym.raw | |
266 | fi | |
267 | ||
268 | ?X: canonicalize symbols for easier sort/uniq/comm usage: append =1 if no = sign | |
269 | ?X: the awk script must be on two lines for older awk programs, sigh! -- ADO | |
270 | $awk '/\=/ { print $0; next } | |
271 | { print $0"=1" }' ccsym.raw >ccsym.list | |
75ef64fe YST |
272 | $comm -13 Cppsym.true ccsym.list >ccsym.own |
273 | $comm -12 Cppsym.true ccsym.list >ccsym.com | |
274 | $comm -23 Cppsym.true ccsym.list >ccsym.cpp | |
959f3c4c JH |
275 | also='' |
276 | if $test -z ccsym.raw; then | |
277 | echo "Your C compiler doesn't seem to define any symbols!" >&4 | |
278 | echo " " | |
279 | echo "However, your C preprocessor defines the following symbols:" | |
280 | $cat Cppsym.true | |
281 | ccsymbols='' | |
282 | cppsymbols=`$cat Cppsym.true` | |
283 | cppsymbols=`echo $cppsymbols` | |
284 | cppccsymbols="$cppsymbols" | |
285 | else | |
286 | if $test -s ccsym.com; then | |
287 | echo "Your C compiler and pre-processor define these symbols:" | |
d7daf0d3 | 288 | $sed -e 's/\(..*\)=.*/\1/' ccsym.com |
959f3c4c JH |
289 | also='also ' |
290 | symbols='ones' | |
291 | cppccsymbols=`$cat ccsym.com` | |
292 | cppccsymbols=`echo $cppccsymbols` | |
293 | $test "$silent" || sleep 1 | |
294 | fi | |
295 | if $test -s ccsym.cpp; then | |
296 | $test "$also" && echo " " | |
297 | echo "Your C pre-processor ${also}defines the following symbols:" | |
d7daf0d3 | 298 | $sed -e 's/\(..*\)=.*/\1/' ccsym.cpp |
959f3c4c JH |
299 | also='further ' |
300 | cppsymbols=`$cat ccsym.cpp` | |
301 | cppsymbols=`echo $cppsymbols` | |
302 | $test "$silent" || sleep 1 | |
303 | fi | |
304 | if $test -s ccsym.own; then | |
305 | $test "$also" && echo " " | |
306 | echo "Your C compiler ${also}defines the following cpp symbols:" | |
d7daf0d3 YST |
307 | $sed -e 's/\(..*\)=1/\1/' ccsym.own |
308 | $sed -e 's/\(..*\)=.*/\1/' ccsym.own | $uniq >>Cppsym.true | |
959f3c4c JH |
309 | ccsymbols=`$cat ccsym.own` |
310 | ccsymbols=`echo $ccsymbols` | |
311 | $test "$silent" || sleep 1 | |
312 | fi | |
313 | fi | |
959f3c4c | 314 |