WHATSNEW: Add changes since 3.6.13.
[Samba.git] / source4 / heimdal_build / lexyacc.sh
blobeb6314ad96c301ce84e1ca107930eb6297f536f3
1 #!/bin/bash
3 # rebuild our heimdal lex/yacc files. Run this manually if you update heimdal
5 lexfiles="heimdal/lib/asn1/lex.l heimdal/lib/hx509/sel-lex.l heimdal/lib/com_err/lex.l"
6 yaccfiles="heimdal/lib/asn1/asn1parse.y heimdal/lib/hx509/sel-gram.y heimdal/lib/com_err/parse.y"
8 set -e
10 LEX="lex"
11 YACC="yacc"
13 top=$PWD
15 call_lex() {
16 lfile="$1"
18 echo "Calling $LEX on $lfile"
20 dir=$(dirname $lfile)
21 base=$(basename $lfile .l)
22 cfile=$base".c"
23 lfile=$base".l"
25 cd $dir
27 $LEX $lfile || exit 1
29 if [ -r lex.yy.c ]; then
30 echo "#include \"config.h\"" > $base.c
31 sed -e "s|lex\.yy\.c|$cfile|" lex.yy.c >> $base.c
32 rm -f $base.yy.c
33 elif [ -r $base.yy.c ]; then
34 echo "#include \"config.h\"" > $base.c
35 sed -e "s|$base\.yy\.c|$cfile|" $base.yy.c >> $base.c
36 rm -f $base.yy.c
37 elif [ -r $base.c ]; then
38 mv $base.c $base.c.tmp
39 echo "#include \"config.h\"" > $base.c
40 sed -e "s|$base\.yy\.c|$cfile|" $base.c.tmp >> $base.c
41 rm -f $base.c.tmp
42 elif [ ! -r base.c ]; then
43 echo "$base.c nor $base.yy.c nor lex.yy.c generated."
44 exit 1
46 cd $top
50 call_yacc() {
51 yfile="$1"
53 echo "Calling $YACC on $yfile"
55 dir=$(dirname $yfile)
56 base=$(basename $yfile .y)
57 cfile=$base".c"
58 yfile=$base".y"
60 cd $dir
62 $YACC -d $yfile || exit 1
63 if [ -r y.tab.h -a -r y.tab.c ];then
64 sed -e "/^#/!b" -e "s|y\.tab\.h|$cfile|" -e "s|\"$base.y|\"$cfile|" y.tab.h > $base.h
65 sed -e "s|y\.tab\.c|$cfile|" -e "s|\"$base.y|\"$cfile|" y.tab.c > $base.c
66 rm -f y.tab.c y.tab.h
67 elif [ ! -r $base.h -a ! -r $base.c]; then
68 echo "$base.h nor $base.c generated."
69 exit 1
71 cd $top
76 for lfile in $lexfiles; do
77 call_lex $lfile
78 done
80 for yfile in $yaccfiles; do
81 call_yacc $yfile
82 done