xref: /minix3/usr.bin/unifdef/unifdefall.sh (revision b6f0c436268cdf3df867d9382f2423f5a36f7a4d)
1*b6f0c436SThomas Cort#!/bin/sh
2*b6f0c436SThomas Cort#
3*b6f0c436SThomas Cort# remove all the #if's from a source file
4*b6f0c436SThomas Cort#
5*b6f0c436SThomas Cort#	$dotat: things/unifdefall.sh,v 1.10 2002/09/24 19:52:11 fanf2 Exp $
6*b6f0c436SThomas Cort# $FreeBSD: src/usr.bin/unifdef/unifdefall.sh,v 1.2 2002/09/24 19:50:03 fanf Exp $
7*b6f0c436SThomas Cort
8*b6f0c436SThomas Cortset -e
9*b6f0c436SThomas Cort
10*b6f0c436SThomas Cortbasename=`basename $0`
11*b6f0c436SThomas Corttmp=`mktemp -d -t $basename` || exit 2
12*b6f0c436SThomas Cort
13*b6f0c436SThomas Cortunifdef -s "$@" | sort | uniq > $tmp/ctrl
14*b6f0c436SThomas Cortcpp -dM "$@" | sort |
15*b6f0c436SThomas Cort	sed -Ee 's/^#define[ 	]+(.*[^	 ])[ 	]*$/\1/' > $tmp/hashdefs
16*b6f0c436SThomas Cortsed -Ee 's/^([A-Za-z0-9_]+).*$/\1/' $tmp/hashdefs > $tmp/alldef
17*b6f0c436SThomas Cortcomm -23 $tmp/ctrl $tmp/alldef > $tmp/undef
18*b6f0c436SThomas Cortcomm -12 $tmp/ctrl $tmp/alldef > $tmp/def
19*b6f0c436SThomas Cort
20*b6f0c436SThomas Cortecho unifdef -k \\ > $tmp/cmd
21*b6f0c436SThomas Cortsed -Ee 's/^(.*)$/-U\1 \\/' $tmp/undef >> $tmp/cmd
22*b6f0c436SThomas Cortwhile read sym
23*b6f0c436SThomas Cortdo	sed -Ee '/^('"$sym"')([(][^)]*[)])?([ 	]+(.*))?$/!d;s//-D\1=\4/' $tmp/hashdefs
24*b6f0c436SThomas Cortdone < $tmp/def |
25*b6f0c436SThomas Cort	sed -Ee 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/" \\/' >> $tmp/cmd
26*b6f0c436SThomas Cortecho '"$@"' >> $tmp/cmd
27*b6f0c436SThomas Cortsh $tmp/cmd "$@"
28*b6f0c436SThomas Cort
29*b6f0c436SThomas Cortrm -r $tmp
30