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