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