#!/bin/bash
cd /usr/src/flex-* ||exit

#flex-2.5.31 does not work with xc!!!, (modutils?), (wine?) without
#the following patch, 2.5.27 does without it:

#fixes a ton of things, stuff that Debian thought to be broken, makes flex not suck anymore:
patch -p 1 <../flex-2.5.31-debian_fixes-4.patch
#fix flex bug:
patch -p 1 <../flex-2.5.31-yytext_ptr-1.patch

#avoid rebuilding docs (help2man beeded) after debian patch:
touch doc/flex.1



./configure --prefix=/usr &&
make &&
#make bigcheck
make install &&
#gcc -shared libmain.o libyywrap.o -o libfl.so &&
gcc -shared libyywrap.o -o libfl.so &&
#remove symlink to prelfs, otherwise copy wont work:
rm -f /usr/lib/libfl.so &&
cp libfl.so /usr/lib &&
ln -sf libfl.a /usr/lib/libl.a


cat >/usr/bin/lex <<"EOF"
#!/bin/sh
# Begin /usr/bin/lex

exec /usr/bin/flex -l "$@"

# End /usr/bin/lex
EOF
chmod 755 /usr/bin/lex
