1 ?RCS: $Id: Cppsym.U,v 3.0.1.5 1995/05/12 11:59:11 ram Exp $
3 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
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 3.0.
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 awk's (ADO)
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)
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)
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
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
30 ?RCS: Revision 3.0 1993/08/18 12:04:50 ram
31 ?RCS: Baseline for dist 3.0 netwide release.
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
39 ?MAKE:Cppsym ccsymbols cppsymbols cppccsymbols: run \
40 eunicefix Guess awk cat tr sed sort rm rm_try startsh osname \
41 +cc +gccversion test comm uniq echo Options trnl \
42 optimize ccflags ldflags libs cpp_stuff cpp
43 ?MAKE: -pick add $@ %<
44 ?T:also symbols i postprocess_cc_v tHdrH
46 ?X: The symbol list is in alpha order for ease of maintenance...
48 ?X: Lots of new symbols (mostly rummaged from gcc), courtesy of
49 ?X: Jarkko Hietaniemi <jhi@snakemail.hut.fi> -- RAM, 06/06/94
52 ?S: The variable contains the symbols defined by the C compiler alone.
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.
55 ?S: The list is a space-separated list of symbol=value tokens.
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.
61 ?S: The list is a space-separated list of symbol=value tokens.
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.
67 ?S: The list is a space-separated list of symbol=value tokens.
79 : Preprocessor symbols
81 $echo "Guessing which symbols your C compiler and preprocessor define..." >&4
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.
85 $cat <<'EOSH' > Cppsym.know
86 a29k aarch64 ABI64 aegis AES_SOURCE AIX AIX32 AIX370 AIX41 AIX42
87 AIX43 aixpc AIX_SOURCE alliant ALL_SOURCE alpha AM29000 am29000
88 AMD64 amd64 amiga AMIGAOS AMIX ansi ANSI_C_SOURCE apollo arch_ppc
89 arch_pwr ardent ARM ARM32 atarist att386 att3b
90 BeOS BIG_ENDIAN BIT_MSF BSD bsd bsd43 bsd4_2 BSD4_3 bsd4_3 bsd4_4
91 BSDCOMPAT bsdi BSD_4_3 BSD_4_4 BSD_NET2 BSD_TIME BSD_TYPES bull
93 c cadmus clang clipper CMU COFF COMPILER_VERSION concurrent
94 convex cpu CRAY cray CRAYMPP ctix CX_UX CYGWIN
95 DECC DGUX DGUX_SOURCE DJGPP dmert DOLPHIN DPX2 DSO Dynix DynixPTX
96 ELF encore EPI EXTENSIONS
97 FAVOR_BSD FILE_OFFSET_BITS FORTIFY_SOURCE FreeBSD
98 GCC_NEW_VARARGS gcos gcx gimpel GLIBC GLIBC_MINOR GNUC GNUC_MINOR
99 GNU_LIBRARY GNU_SOURCE GO32 gould GOULD_PN
100 H3050R H3050RX hbullx20 hcx host_mips hp200 hp300 HP700 hp700
101 hp800 hp9000 hp9000s200 hp9000s300 hp9000s400
102 hp9000s700 hp9000s800 hp9k8 hppa hpux HPUX_SOURCE hp_osf
103 i186 i286 i386 i486 i586 i686 i8086 i80960 i860 I960 IA32 IA64
104 iAPX286 ibm ibm032 ibmesa IBMR2 ibmrt ILP32 ILP64
105 INLINE_INTRINSICS INT64 INTEL interdata INTRINSICS is68k itanium
107 LANGUAGE_C LARGEFILE64_SOURCE LARGEFILE_SOURCE LARGE_FILE_API
108 LFS64_LARGEFILE LFS_LARGEFILE LIBCATAMOUNT Linux LITTLE_ENDIAN
109 LONG64 LONGDOUBLE LONGLONG LONG_DOUBLE LONG_LONG LP64 luna
111 M68000 m68k m88100 m88k M88KBCS_TARGET MACH machine MachTen
112 MATH_HAS_NO_SIDE_EFFECTS mc300 mc500 mc68000 mc68010 mc68020
113 mc68030 mc68040 mc68060 mc68k mc68k32 mc700 mc88000 mc88100
114 merlin mert MiNT mips MIPSEB MIPSEL MIPS_FPSET MIPS_ISA MIPS_SIM
115 MIPS_SZINT MIPS_SZLONG MIPS_SZPTR MODERN_C motorola mpeix MSDOS
116 MTXINU MULTIMAX MVS mvs M_AMD64 M_ARM M_ARMT M_COFF M_I186 M_I286
117 M_I386 M_I8086 M_I86 M_I86SM M_IA64 M_IX86 M_PPC M_SYS3 M_SYS5
118 M_SYSIII M_SYSV M_UNIX M_X86 M_XENIX
119 n16 ncl_el ncl_mr NetBSD news1500 news1700 news1800 news1900
120 news3700 news700 news800 news900 NeXT NLS nonstopux ns16000
121 ns32000 ns32016 ns32332 ns32k nsc32000
122 OCS88 OEMVS OpenBSD os OS2 OS390 osf OSF1 OSF_SOURCE
123 PARAGON parisc pa_risc PA_RISC1_1 PA_RISC2_0 pc532 pdp11 PGC PIC
124 plexus PORTAR posix POSIX1B_SOURCE POSIX2_SOURCE POSIX4_SOURCE
125 POSIX_C_SOURCE POSIX_SOURCE POWER powerpc ppc PROTOTYPES PWB pyr
127 R3000 REENTRANT RES Rhapsody RISC6000 riscix riscos RT
128 S390 S390x SA110 SCO scs sequent sgi SGI_SOURCE SH SH3 sinix
129 SIZE_INT SIZE_LONG SIZE_PTR SOCKETS_SOURCE SOCKET_SOURCE sony
130 sonyrisc sony_news sparc sparclite sparcv8 sparcv9 spectrum
131 stardent stdc STDC_EXT stratos sun sun3 sun386 Sun386i svr3 svr4
132 SVR4_2 SVR4_SOURCE svr5 SX system SYSTYPE_BSD SYSTYPE_BSD43
133 SYSTYPE_BSD44 SYSTYPE_SVR4 SYSTYPE_SVR5 SYSTYPE_SYSV SYSV SYSV3
134 SYSV4 SYSV5 sysV68 sysV88
135 Tek4132 Tek4300 thumb thw_370 thw_intel thw_rs6000 titan TM3200
136 TM5400 TM5600 tower tower32 tower32_200 tower32_600 tower32_700
137 tower32_800 tower32_850 tss
138 u370 u3b u3b2 u3b20 u3b200 u3b20d u3b5 ultrix UMAXV UnicomPBB
139 UnicomPBD UNICOS UNICOSMK unix UNIX95 UNIX99 unixpc unos USE_BSD
140 USE_FILE_OFFSET64 USE_GNU USE_ISOC9X USE_LARGEFILE
141 USE_LARGEFILE64 USE_MISC USE_POSIX USE_POSIX199309
142 USE_POSIX199506 USE_POSIX2 USE_REENTRANT USE_SVID USE_UNIX98
143 USE_XOPEN USE_XOPEN_EXTENDED USGr4 USGr4_2 UTek Utek UTS UWIN
146 x86_64 xenix Xenix286 XOPEN_SOURCE XOPEN_SOURCE_EXTENDED XPG2
147 XPG2_EXTENDED XPG3 XPG3_EXTENDED XPG4 XPG4_EXTENDED
150 # Maybe put other stuff here too.
151 ?X:Some OS's will have a dash in their $osname
152 ?X:e.g. Android is known as linux-android
153 ?X:The preprocessor will interpret the dash as a minus
154 ./tr '-' '_' <<EOSH >>Cppsym.know
157 ./tr '[a-z]' '[A-Z]' < Cppsym.know > Cppsym.a
158 ./tr '[A-Z]' '[a-z]' < Cppsym.know > Cppsym.b
159 $cat Cppsym.know > Cppsym.c
160 $cat Cppsym.a Cppsym.b Cppsym.c | $tr ' ' $trnl | $sort | $uniq > Cppsym.know
161 $rm -f Cppsym.a Cppsym.b Cppsym.c
164 if $test \$# -gt 0; then
165 echo \$* | $tr " " "$trnl" | ./Cppsym.try > Cppsym.got
166 if $test -s Cppsym.got; then
173 $tr " " "$trnl" | ./Cppsym.try
179 ?X: The below awk script will die a horrible death if
180 ?X: some of the tested symbols are not long ints.
181 ?X: Also, we do not make difference between just defined and defined zero.
182 cat <<EOSH > Cppsym.try
187 #define STRINGIFY(a) "a"
191 #define STRINGIFY(a) StGiFy(a)
193 #if $cpp_stuff != 1 && $cpp_stuff != 42
194 # include "Bletch: How does this C preprocessor stringify macros?"
198 ?X: The length($1) command guards against possible empty entries.
199 ?X: The awk snippet is know to give heartburn to UNICOS/mk awk.
202 cat <<'EOSH' >> Cppsym.try
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
206 printf "#ifdef __%s\nprintf(\"__%s=%%s\\n\", STRINGIFY(__%s));\n#endif\n", $1, $1, $1
207 printf "#ifdef __%s__\nprintf(\"__%s__=%%s\\n\", STRINGIFY(__%s__));\n#endif\n", $1, $1, $1
209 echo 'return 0;}' >> try.c
211 cat <<EOSH >> Cppsym.try
213 case "$osname-$gccversion" in
214 irix-) ccflags="\$ccflags -woff 1178" ;;
215 os2-*) ccflags="\$ccflags -Zlinker /PM:VIO" ;;
217 $cc -o try -Dcpp_stuff=$cpp_stuff $optimize \$ccflags $ldflags try.c $libs 2>/dev/null && $run ./try | $sed 's/ /\\\\ /g'
220 $eunicefix Cppsym.try
221 ./Cppsym < Cppsym.know | $sort | $uniq > Cppsym.true
222 : Add in any Linux cpp "predefined macros":
223 case "$osname::$gccversion" in
224 *linux*::*.*|*gnukfreebsd*::*.*|gnu::*.*)
226 rm -f $tHdrH'.h' $tHdrH
228 # Filter out macro arguments, such as Linux's __INT8_C(c)
229 if $cpp -dM $tHdrH'.h' > $tHdrH'_cppsym.h' && [ -s $tHdrH'_cppsym.h' ]; then
230 sed -e 's/#define[\ \ ]*//;s/[\ \ ].*$//' -e 's/(.*//' <$tHdrH'_cppsym.h' >$tHdrH'_cppsym.real'
231 if [ -s $tHdrH'_cppsym.real' ]; then
232 cat $tHdrH'_cppsym.real' Cppsym.know | sort | uniq | ./Cppsym | sort | uniq > Cppsym.true
235 rm -f $tHdrH'.h' $tHdrH'_cppsym.h' $tHdrH'_cppsym.real'
238 : now check the C compiler for additional symbols
239 ?X: suggested by Jarkko Hietaniemi <jhi@snakemail.hut.fi>, thanks!
242 aix) postprocess_cc_v="|$tr , ' '" ;;
249 for i in \`$cc -v -c tmp.c 2>&1 $postprocess_cc_v\`
252 -D*) echo "\$i" | $sed 's/^-D//';;
253 -A*) $test "$gccversion" && echo "\$i" | $sed 's/^-A//' | $sed 's/\(.*\)(\(.*\))/\1=\2/';;
262 ?X: AIX complains if $uniq is passed an empty file. ($sort apparently
263 ?X: doesn't care.) --AD 14 July 1998
264 if $test -s ccsym1.raw; then
265 $sort ccsym1.raw | $uniq >ccsym.raw
267 mv ccsym1.raw ccsym.raw
270 ?X: canonicalize symbols for easier sort/uniq/comm usage: append =1 if no = sign
271 ?X: the awk script must be on two lines for older awk programs, sigh! -- ADO
272 $awk '/\=/ { print $0; next }
273 { print $0"=1" }' ccsym.raw >ccsym.list
274 $comm -13 Cppsym.true ccsym.list >ccsym.own
275 $comm -12 Cppsym.true ccsym.list >ccsym.com
276 $comm -23 Cppsym.true ccsym.list >ccsym.cpp
278 if $test -z ccsym.raw; then
279 echo "Your C compiler doesn't seem to define any symbols!" >&4
281 echo "However, your C preprocessor defines the following symbols:"
284 cppsymbols=`$cat Cppsym.true`
285 cppsymbols=`echo $cppsymbols`
286 cppccsymbols="$cppsymbols"
288 if $test -s ccsym.com; then
289 echo "Your C compiler and pre-processor define these symbols:"
290 $sed -e 's/\(..*\)=.*/\1/' ccsym.com
293 cppccsymbols=`$cat ccsym.com`
294 cppccsymbols=`echo $cppccsymbols`
295 $test "$silent" || sleep 1
297 if $test -s ccsym.cpp; then
298 $test "$also" && echo " "
299 echo "Your C pre-processor ${also}defines the following symbols:"
300 $sed -e 's/\(..*\)=.*/\1/' ccsym.cpp
302 cppsymbols=`$cat ccsym.cpp`
303 cppsymbols=`echo $cppsymbols`
304 $test "$silent" || sleep 1
306 if $test -s ccsym.own; then
307 $test "$also" && echo " "
308 echo "Your C compiler ${also}defines the following cpp symbols:"
309 $sed -e 's/\(..*\)=1/\1/' ccsym.own
310 $sed -e 's/\(..*\)=.*/\1/' ccsym.own | $uniq >>Cppsym.true
311 ccsymbols=`$cat ccsym.own`
312 ccsymbols=`echo $ccsymbols`
313 $test "$silent" || sleep 1
317 : add -D_FORTIFY_SOURCE if feasible and not already there
318 case "$gccversion" in
319 [456789].*) case "$optimize$ccflags" in
320 *-O*) case "$ccflags$cppsymbols" in
321 *_FORTIFY_SOURCE=*) # Don't add it again.
322 echo "You seem to have -D_FORTIFY_SOURCE already, not adding it." >&4
324 *) echo "Adding -D_FORTIFY_SOURCE=2 to ccflags..." >&4
325 ccflags="$ccflags -D_FORTIFY_SOURCE=2"
329 *) echo "You have gcc 4.* or later but not optimizing, not adding -D_FORTIFY_SOURCE." >&4
333 *) echo "You seem not to have gcc 4.* or later, not adding -D_FORTIFY_SOURCE." >&4