2f9498e5ac8535daa3bc905bb001bb675e6e811f
[bbaumbach/samba-autobuild/.git] / source4 / script / lex_compile.sh
1 #!/bin/sh
2
3 LEX="$1"
4 SRC="$2"
5 DEST="$3"
6
7 dir=`dirname $SRC`
8 file=`basename $SRC`
9 base=`basename $SRC .l`
10 if [ -z "$LEX" ]; then
11         # if $DEST is more recent than $SRC, we can just touch
12         # otherwise we touch but print out warnings
13         if [ -r $DEST ]; then
14                 if [ x`find $SRC -newer $DEST -print` = x$SRC ]; then
15                         echo "warning: lex not found - cannot generate $SRC => $DEST" >&2
16                         echo "warning: lex not found - only updating the timestamp of $DEST" >&2
17                 fi
18                 touch $DEST;
19                 exit;
20         fi
21         echo "error: lex not found - cannot generate $SRC => $DEST" >&2
22         exit 1;
23 fi
24 # if $DEST is more recent than $SRC, we can just touch
25 if [ -r $DEST ]; then
26         if [ x`find $SRC -newer $DEST -print` != x$SRC ]; then
27                 touch $DEST;
28                 exit;
29         fi
30 fi
31 TOP=`pwd`
32 if cd $dir && $LEX $file; then
33         if [ -r $base.yy.c ];then
34                 # we must guarantee that config.h comes first
35                 echo "#include \"config.h\"" > $base.c
36                 sed '/^#/ s|$base.yy\.c|$DEST|' $base.yy.c >> $base.c
37                 rm -f $base.yy.c
38         fi
39 fi
40 cd $TOP