This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Some more cppsymbols to scan.
[metaconfig.git] / U / modified / Cppsym.U
CommitLineData
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:
65a32477 5?RCS: You may redistribute only under the terms of the Artistic License,
959f3c4c
JH
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
65a32477 8?RCS: that same Artistic License; a copy of which may be found at the root
959f3c4c
JH
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
65a32477 13?RCS: patch54: split awk command onto two lines for older awk's (ADO)
959f3c4c
JH
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 80echo " "
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 85$cat <<'EOSH' > Cppsym.know
370c94cc
MBT
86a29k aarch64 ABI64 aegis AES_SOURCE AIX AIX32 AIX370 AIX41 AIX42
87AIX43 aixpc AIX_SOURCE alliant ALL_SOURCE alpha AM29000 am29000
88AMD64 amd64 amiga AMIGAOS AMIX ansi ANSI_C_SOURCE apollo arch_ppc
89arch_pwr ardent ARM ARM32 atarist att386 att3b
c213126d
MBT
90BeOS BIG_ENDIAN BIT_MSF BSD bsd bsd43 bsd4_2 BSD4_3 bsd4_3 bsd4_4
91BSDCOMPAT bsdi BSD_4_3 BSD_4_4 BSD_NET2 BSD_TIME BSD_TYPES bull
370c94cc
MBT
92byteorder byte_order
93c cadmus clang clipper CMU COFF COMPILER_VERSION concurrent
94convex cpu CRAY cray CRAYMPP ctix CX_UX CYGWIN
c213126d
MBT
95DECC DGUX DGUX_SOURCE DJGPP dmert DOLPHIN DPX2 DSO Dynix DynixPTX
96ELF encore EPI EXTENSIONS
eb4c4ab2 97FAVOR_BSD FILE_OFFSET_BITS FORTIFY_SOURCE FreeBSD
c213126d
MBT
98GCC_NEW_VARARGS gcos gcx gimpel GLIBC GLIBC_MINOR GNUC GNUC_MINOR
99GNU_LIBRARY GNU_SOURCE GO32 gould GOULD_PN
100H3050R H3050RX hbullx20 hcx host_mips hp200 hp300 HP700 hp700
101hp800 hp9000 hp9000s200 hp9000s300 hp9000s400 hp9000s500
102hp9000s700 hp9000s800 hp9k8 hppa hpux HPUX_SOURCE hp_osf
370c94cc
MBT
103i186 i286 i386 i486 i586 i686 i8086 i80960 i860 I960 IA32 IA64
104iAPX286 ibm ibm032 ibmesa IBMR2 ibmrt ILP32 ILP64
105INLINE_INTRINSICS INT64 INTEL interdata INTRINSICS is68k itanium
c213126d
MBT
106ksr1
107LANGUAGE_C LARGEFILE64_SOURCE LARGEFILE_SOURCE LARGE_FILE_API
108LFS64_LARGEFILE LFS_LARGEFILE LIBCATAMOUNT Linux LITTLE_ENDIAN
109LONG64 LONGDOUBLE LONGLONG LONG_DOUBLE LONG_LONG LP64 luna
110luna88k Lynx
111M68000 m68k m88100 m88k M88KBCS_TARGET MACH machine MachTen
112MATH_HAS_NO_SIDE_EFFECTS mc300 mc500 mc68000 mc68010 mc68020
113mc68030 mc68040 mc68060 mc68k mc68k32 mc700 mc88000 mc88100
114merlin mert MiNT mips MIPSEB MIPSEL MIPS_FPSET MIPS_ISA MIPS_SIM
115MIPS_SZINT MIPS_SZLONG MIPS_SZPTR MODERN_C motorola mpeix MSDOS
370c94cc
MBT
116MTXINU MULTIMAX MVS mvs M_AMD64 M_ARM M_ARMT M_COFF M_I186 M_I286
117M_I386 M_I8086 M_I86 M_I86SM M_IA64 M_IX86 M_PPC M_SYS3 M_SYS5
118M_SYSIII M_SYSV M_UNIX M_X86 M_XENIX
c213126d
MBT
119n16 ncl_el ncl_mr NetBSD news1500 news1700 news1800 news1900
120news3700 news700 news800 news900 NeXT NLS nonstopux ns16000
121ns32000 ns32016 ns32332 ns32k nsc32000
762256f8 122OCS88 OEMVS OpenBSD os OS2 OS390 osf OSF1 OSF_SOURCE
c213126d
MBT
123PARAGON parisc pa_risc PA_RISC1_1 PA_RISC2_0 pc532 pdp11 PGC PIC
124plexus PORTAR posix POSIX1B_SOURCE POSIX2_SOURCE POSIX4_SOURCE
370c94cc 125POSIX_C_SOURCE POSIX_SOURCE POWER powerpc ppc PROTOTYPES PWB pyr
c213126d
MBT
126QK_USER QNX
127R3000 REENTRANT RES Rhapsody RISC6000 riscix riscos RT
370c94cc
MBT
128S390 S390x SA110 SCO scs sequent sgi SGI_SOURCE SH SH3 sinix
129SIZE_INT SIZE_LONG SIZE_PTR SOCKETS_SOURCE SOCKET_SOURCE sony
130sonyrisc sony_news sparc sparclite sparcv8 sparcv9 spectrum
131stardent stdc STDC_EXT stratos sun sun3 sun386 Sun386i svr3 svr4
132SVR4_2 SVR4_SOURCE svr5 SX system SYSTYPE_BSD SYSTYPE_BSD43
133SYSTYPE_BSD44 SYSTYPE_SVR4 SYSTYPE_SVR5 SYSTYPE_SYSV SYSV SYSV3
134SYSV4 SYSV5 sysV68 sysV88
135Tek4132 Tek4300 thumb thw_370 thw_intel thw_rs6000 titan TM3200
136TM5400 TM5600 tower tower32 tower32_200 tower32_600 tower32_700
137tower32_800 tower32_850 tss
c213126d
MBT
138u370 u3b u3b2 u3b20 u3b200 u3b20d u3b5 ultrix UMAXV UnicomPBB
139UnicomPBD UNICOS UNICOSMK unix UNIX95 UNIX99 unixpc unos USE_BSD
140USE_FILE_OFFSET64 USE_GNU USE_ISOC9X USE_LARGEFILE
141USE_LARGEFILE64 USE_MISC USE_POSIX USE_POSIX199309
142USE_POSIX199506 USE_POSIX2 USE_REENTRANT USE_SVID USE_UNIX98
143USE_XOPEN USE_XOPEN_EXTENDED USGr4 USGr4_2 UTek Utek UTS UWIN
144uxpm uxps
145vax venix VMESA vms
146x86_64 xenix Xenix286 XOPEN_SOURCE XOPEN_SOURCE_EXTENDED XPG2
147XPG2_EXTENDED XPG3 XPG3_EXTENDED XPG4 XPG4_EXTENDED
370c94cc 148z8000 zarch
762256f8
JH
149EOSH
150# Maybe put other stuff here too.
151cat <<EOSH >>Cppsym.know
152$osname
153EOSH
8a77dbe2
JH
154./tr '[a-z]' '[A-Z]' < Cppsym.know > Cppsym.a
155./tr '[A-Z]' '[a-z]' < Cppsym.know > Cppsym.b
d7daf0d3 156$cat Cppsym.know > Cppsym.c
a3e4b67c 157$cat Cppsym.a Cppsym.b Cppsym.c | $tr ' ' $trnl | $sort | $uniq > Cppsym.know
d7daf0d3 158$rm -f Cppsym.a Cppsym.b Cppsym.c
86b170fb
JH
159cat <<EOSH > Cppsym
160$startsh
161if $test \$# -gt 0; then
d088635c
JH
162 echo \$* | $tr " " "$trnl" | ./Cppsym.try > Cppsym.got
163 if $test -s Cppsym.got; then
eb4c4ab2
MBT
164 $rm -f Cppsym.got
165 exit 0
d088635c
JH
166 fi
167 $rm -f Cppsym.got
168 exit 1
86b170fb 169else
d088635c
JH
170 $tr " " "$trnl" | ./Cppsym.try
171 exit 0
86b170fb 172fi
86b170fb
JH
173EOSH
174chmod +x Cppsym
175$eunicefix Cppsym
d088635c
JH
176?X: The below awk script will die a horrible death if
177?X: some of the tested symbols are not long ints.
178?X: Also, we do not make difference between just defined and defined zero.
86b170fb 179cat <<EOSH > Cppsym.try
d088635c 180$startsh
4ca3dd4c
JH
181cat <<'EOCP' > try.c
182#include <stdio.h>
75ef64fe
YST
183#if cpp_stuff == 1
184#define STRINGIFY(a) "a"
185#endif
186#if cpp_stuff == 42
187#define StGiFy(a) #a
188#define STRINGIFY(a) StGiFy(a)
189#endif
190#if $cpp_stuff != 1 && $cpp_stuff != 42
191# include "Bletch: How does this C preprocessor stringify macros?"
192#endif
4ca3dd4c
JH
193int main() {
194EOCP
762256f8 195?X: The length($1) command guards against possible empty entries.
d7daf0d3 196?X: The awk snippet is know to give heartburn to UNICOS/mk awk.
86b170fb
JH
197$awk \\
198EOSH
199cat <<'EOSH' >> Cppsym.try
200'length($1) > 0 {
75ef64fe
YST
201 printf "#ifdef %s\nprintf(\"%s=%%s\\n\", STRINGIFY(%s));\n#endif\n", $1, $1, $1
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
d088635c 205}' >> try.c
7857a0f2 206echo 'return 0;}' >> try.c
86b170fb 207EOSH
d088635c 208cat <<EOSH >> Cppsym.try
d088635c 209ccflags="$ccflags"
d1467975
JH
210case "$osname-$gccversion" in
211irix-) ccflags="\$ccflags -woff 1178" ;;
d7daf0d3 212os2-*) ccflags="\$ccflags -Zlinker /PM:VIO" ;;
d1467975 213esac
75ef64fe 214$cc -o try -Dcpp_stuff=$cpp_stuff $optimize \$ccflags $ldflags try.c $libs && $run ./try | $sed 's/ /\\\\ /g'
86b170fb
JH
215EOSH
216chmod +x Cppsym.try
217$eunicefix Cppsym.try
bd71dcc4 218./Cppsym < Cppsym.know | $sort | $uniq > Cppsym.true
ed5d019e 219: Add in any Linux cpp "predefined macros":
f35fd5db 220case "$osname::$gccversion" in
35385b28 221 *linux*::*.*|*gnukfreebsd*::*.*|gnu::*.*)
f35fd5db
MB
222 tHdrH=_tmpHdr
223 rm -f $tHdrH'.h' $tHdrH
224 touch $tHdrH'.h'
395c24d9 225 # Filter out macro arguments, such as Linux's __INT8_C(c)
78e210bb 226 if $cpp -dM $tHdrH'.h' > $tHdrH'_cppsym.h' && [ -s $tHdrH'_cppsym.h' ]; then
395c24d9 227 sed -e 's/#define[\ \ ]*//;s/[\ \ ].*$//' -e 's/(.*//' <$tHdrH'_cppsym.h' >$tHdrH'_cppsym.real'
f35fd5db
MB
228 if [ -s $tHdrH'_cppsym.real' ]; then
229 cat $tHdrH'_cppsym.real' Cppsym.know | sort | uniq | ./Cppsym | sort | uniq > Cppsym.true
230 fi
231 fi
232 rm -f $tHdrH'.h' $tHdrH'_cppsym.h' $tHdrH'_cppsym.real'
233 ;;
234esac
959f3c4c
JH
235: now check the C compiler for additional symbols
236?X: suggested by Jarkko Hietaniemi <jhi@snakemail.hut.fi>, thanks!
237postprocess_cc_v=''
238case "$osname" in
239aix) postprocess_cc_v="|$tr , ' '" ;;
240esac
241$cat >ccsym <<EOS
242$startsh
243$cat >tmp.c <<EOF
244extern int foo;
245EOF
246for i in \`$cc -v -c tmp.c 2>&1 $postprocess_cc_v\`
247do
248 case "\$i" in
249 -D*) echo "\$i" | $sed 's/^-D//';;
9a944a00 250 -A*) $test "$gccversion" && echo "\$i" | $sed 's/^-A//' | $sed 's/\(.*\)(\(.*\))/\1=\2/';;
959f3c4c
JH
251 esac
252done
2cb64bf6 253$rm_try
959f3c4c
JH
254EOS
255postprocess_cc_v=''
256chmod +x ccsym
257$eunicefix ccsym
258./ccsym > ccsym1.raw
259?X: AIX complains if $uniq is passed an empty file. ($sort apparently
260?X: doesn't care.) --AD 14 July 1998
261if $test -s ccsym1.raw; then
eb4c4ab2 262 $sort ccsym1.raw | $uniq >ccsym.raw
959f3c4c 263else
eb4c4ab2 264 mv ccsym1.raw ccsym.raw
959f3c4c
JH
265fi
266
267?X: canonicalize symbols for easier sort/uniq/comm usage: append =1 if no = sign
268?X: the awk script must be on two lines for older awk programs, sigh! -- ADO
269$awk '/\=/ { print $0; next }
270 { print $0"=1" }' ccsym.raw >ccsym.list
75ef64fe
YST
271$comm -13 Cppsym.true ccsym.list >ccsym.own
272$comm -12 Cppsym.true ccsym.list >ccsym.com
273$comm -23 Cppsym.true ccsym.list >ccsym.cpp
959f3c4c
JH
274also=''
275if $test -z ccsym.raw; then
276 echo "Your C compiler doesn't seem to define any symbols!" >&4
277 echo " "
278 echo "However, your C preprocessor defines the following symbols:"
279 $cat Cppsym.true
eb4c4ab2 280 ccsymbols=''
959f3c4c 281 cppsymbols=`$cat Cppsym.true`
eb4c4ab2 282 cppsymbols=`echo $cppsymbols`
959f3c4c
JH
283 cppccsymbols="$cppsymbols"
284else
285 if $test -s ccsym.com; then
286 echo "Your C compiler and pre-processor define these symbols:"
d7daf0d3 287 $sed -e 's/\(..*\)=.*/\1/' ccsym.com
959f3c4c
JH
288 also='also '
289 symbols='ones'
290 cppccsymbols=`$cat ccsym.com`
291 cppccsymbols=`echo $cppccsymbols`
292 $test "$silent" || sleep 1
293 fi
294 if $test -s ccsym.cpp; then
295 $test "$also" && echo " "
296 echo "Your C pre-processor ${also}defines the following symbols:"
d7daf0d3 297 $sed -e 's/\(..*\)=.*/\1/' ccsym.cpp
959f3c4c
JH
298 also='further '
299 cppsymbols=`$cat ccsym.cpp`
300 cppsymbols=`echo $cppsymbols`
301 $test "$silent" || sleep 1
302 fi
303 if $test -s ccsym.own; then
304 $test "$also" && echo " "
305 echo "Your C compiler ${also}defines the following cpp symbols:"
d7daf0d3
YST
306 $sed -e 's/\(..*\)=1/\1/' ccsym.own
307 $sed -e 's/\(..*\)=.*/\1/' ccsym.own | $uniq >>Cppsym.true
eb4c4ab2
MBT
308 ccsymbols=`$cat ccsym.own`
309 ccsymbols=`echo $ccsymbols`
959f3c4c
JH
310 $test "$silent" || sleep 1
311 fi
312fi
959f3c4c 313
eb4c4ab2
MBT
314: add -D_FORTIFY_SOURCE if feasible and not already there
315case "$gccversion" in
3164.*) case "$optimize$ccflags" in
317 *-O*) case "$ccflags$cppsymbols" in
318 *_FORTIFY_SOURCE=*) # Don't add it again.
319 echo "You seem to have -D_FORTIFY_SOURCE already, not adding it." >&4
320 ;;
321 *) echo "Adding -D_FORTIFY_SOURCE=2 to ccflags..." >&4
322 ccflags="$ccflags -D_FORTIFY_SOURCE=2"
323 ;;
324 esac
325 ;;
326 *) echo "You have gcc 4.* but not optimizing, not adding -D_FORTIFY_SOURCE." >&4
327 ;;
328 esac
329 ;;
330*) echo "You seem not to have gcc 4.*, not adding -D_FORTIFY_SOURCE." >&4
331 ;;
332esac
333