1#!/bin/sh
2cd /tmp
3umask 022
4
5CC=cc
6CPP=cpp
7PATH="$PATH:/lib"
8
9TEMP=def$$
10trap 'rm -f ${TEMP}*; trap 0; exit' 0 1 2 3 15
11
12set `type $CC`
13q=$#
14set x `type $CC`
15shift $q
16cc=$1
17
18set `type $CPP`
19q=$#
20set x `type $CPP`
21shift $q
22cpp=$1
23
24strings - "$cc" 2>/dev/null | tr ' ' '\012' > ${TEMP}.x
25
26if test -x "$cpp"; then
27strings - "$cpp" 2>/dev/null | tr ' ' '\012' >> ${TEMP}.x
28else
29echo "Warning: cpp not found."
30fi
31
32sort < ${TEMP}.x | uniq | awk '
33/^-D[A-Za-z_][A-Za-z_0-9]*$/ {
34		printf("#ifdef %s\n", substr($0,3))
35		printf("\"%s\": %s\n", substr($0,3), substr($0,3))
36		print "#endif"
37	}
38/^[A-Za-z_][A-Za-z_0-9]*$/ {
39		printf("#ifdef %s\n", $0)
40		printf("\"%s\": %s\n", $0, $0)
41		print "#endif"
42	}
43' > ${TEMP}.c
44
45echo "Defines in cc are:"
46cc -E ${TEMP}.c | sed -n -e 's/"\([^:]*\)":/\1:/p' | sort | uniq
47