1#!/bin/sh
2# Usage: gentvals.sh target type dir files pattern cpp
3
4target=$1
5type=$2
6dir=$3
7# FIXME: Would be nice to process #include's in these files.
8files=$4
9pattern=$5
10cpp=$6
11
12# FIXME: need trap to remove tmp files.
13
14rm -f tmpvals.list tmpvals.uniq
15for f in $files
16do
17	if test -f $dir/$f ; then
18		grep "#define[ 	]$pattern" $dir/$f | sed -e "s/^.*#define[ 	]\($pattern\)[ 	]*\([^ 	][^ 	]*\).*$/\1/" >> tmpvals.list
19	fi
20done
21
22sort <tmpvals.list | uniq >tmpvals.uniq
23
24rm -f tmpvals.h
25for f in $files
26do
27	if test -f $dir/$f ; then
28		echo "#include <$f>" >>tmpvals.h
29	fi
30done
31
32cat tmpvals.uniq |
33while read sym
34do
35	echo "#ifdef $sym" >>tmpvals.h
36	echo 'DEFVAL { "'$sym'", '$sym ' },' >>tmpvals.h
37	echo "#endif" >>tmpvals.h
38done
39
40if test -z "$target"
41then
42	echo "#ifdef ${type}_defs"
43else
44	echo "#ifdef NL_TARGET_$target"
45	echo "#ifdef ${type}_defs"
46fi
47
48for f in $files
49do
50	if test -f $dir/$f ; then
51		echo "/* from $f */"
52	fi
53done
54
55if test -z "$target"
56then
57	echo "/* begin $type target macros */"
58else
59	echo "/* begin $target $type target macros */"
60fi
61
62$cpp -I$dir tmpvals.h | grep DEFVAL | sed -e 's/DEFVAL//' -e 's/  / /'
63
64if test -z "$target"
65then
66	echo "/* end $type target macros */"
67	echo "#endif"
68else
69	echo "/* end $target $type target macros */"
70	echo "#endif"
71	echo "#endif"
72fi
73
74rm -f tmpvals.list tmpvals.uniq tmpvals.h
75