#!/bin/sh
#
# file "find-predefines-gcc"
#
# This is a script to automatically figure out which pre-processing
# tokens are pre-defined by the gcc compiler and list them in header
# file format.  It is known to work with gcc 2.6.3; it may or may not
# work with later versions.
#
#       --Chris Wilson <cwilson@CS.Stanford.EDU>
#
# usage: find-predefines-gcc <outfile_name>
#

if test ${1}"" = "" ; then
    echo "no output file given" 1>&2
    exit 1
fi

touch temp-predefines.c

gcc -c -v temp-predefines.c 2>&1 | sed -n /.cpp/p | sed s/' [^-][^ ]*'//g | sed s/' -[^D][^ ]*'//g | sed s/'>'.*// | sed s/'[^ ]*cpp'// > ${1}
RESULT=${?}

rm -f temp-predefines.c temp-predefines.o

exit $RESULT
