2005-08-04 05:23:07 +00:00
#!/bin/sh
LEX = " $1 "
SRC = " $2 "
DEST = " $3 "
2007-08-26 15:16:40 +00:00
shift 3
ARGS = " $* "
2005-08-04 05:23:07 +00:00
dir = ` dirname $SRC `
file = ` basename $SRC `
base = ` basename $SRC .l`
if [ -z " $LEX " ] ; then
2007-04-17 13:48:12 +00:00
# if $DEST is more recent than $SRC, we can just touch
# otherwise we touch but print out warnings
if [ -r $DEST ] ; then
if [ x` find $SRC -newer $DEST -print` = x$SRC ] ; then
echo " warning: lex not found - cannot generate $SRC => $DEST " >& 2
echo " warning: lex not found - only updating the timestamp of $DEST " >& 2
fi
touch $DEST ;
exit;
fi
echo " error: lex not found - cannot generate $SRC => $DEST " >& 2
exit 1;
2005-08-04 05:23:07 +00:00
fi
2007-04-17 13:48:12 +00:00
# if $DEST is more recent than $SRC, we can just touch
2005-08-04 05:23:07 +00:00
if [ -r $DEST ] ; then
2005-08-12 09:20:32 +00:00
if [ x` find $SRC -newer $DEST -print` != x$SRC ] ; then
2007-04-17 13:48:12 +00:00
touch $DEST ;
2005-08-12 09:20:32 +00:00
exit;
fi
2005-08-04 05:23:07 +00:00
fi
TOP = ` pwd `
2008-08-01 11:16:14 +02:00
echo " info: running $LEX $ARGS $file "
2007-08-26 15:16:40 +00:00
if cd $dir && $LEX $ARGS $file ; then
2008-08-01 11:16:14 +02:00
if [ -r lex.yy.c ] ; then
2006-09-10 10:02:10 +00:00
# we must guarantee that config.h comes first
2008-08-01 11:16:14 +02:00
echo " info: move lex.yy.c to $base .c "
echo "#include \"config.h\"" > $base .c
sed -e " s|lex\.yy\.c| $DEST | " lex.yy.c >> $base .c
rm -f $base .yy.c
elif [ -r $base .yy.c ] ; then
# we must guarantee that config.h comes first
echo " info: move $base .yy.c to $base .c "
2006-09-10 10:02:10 +00:00
echo "#include \"config.h\"" > $base .c
2007-09-22 09:42:38 +00:00
sed -e " s| $base \.yy\.c| $DEST | " $base .yy.c >> $base .c
2005-08-12 09:51:40 +00:00
rm -f $base .yy.c
2007-09-22 09:42:38 +00:00
elif [ -r $base .c ] ; then
# we must guarantee that config.h comes first
2008-08-01 11:16:14 +02:00
echo " info: add #include \"config.h\" to $base .c "
2007-09-22 09:42:38 +00:00
mv $base .c $base .c.tmp
echo "#include \"config.h\"" > $base .c
sed -e " s| $base \.yy\.c| $DEST | " $base .c.tmp >> $base .c
rm -f $base .c.tmp
2007-08-26 15:16:40 +00:00
elif [ ! -r base.c ] ; then
2008-08-01 11:16:14 +02:00
echo " $base .c nor $base .yy.c nor lex.yy.c generated. "
2007-08-26 15:16:40 +00:00
exit 1
2005-08-12 09:51:40 +00:00
fi
2005-08-04 05:23:07 +00:00
fi
cd $TOP