1 # -*-perl-*- hey - emacs - this is a perl file
3 # src/tools/msvc/pgflex.pl
5 # silence flex bleatings about file path style
6 $ENV{CYGWIN} = 'nodosfilewarning';
11 # assume we are in the postgres source root
13 require 'src/tools/msvc/buildenv.pl' if -e 'src/tools/msvc/buildenv.pl';
15 my ($flexver) = `flex -V`; # grab first line
16 $flexver = (split(/\s+/, $flexver))[1];
17 $flexver =~ s/[^0-9.]//g;
18 my @verparts = split(/\./, $flexver);
19 unless ($verparts[0] == 2 &&
20 ($verparts[1] > 5 || ($verparts[1] == 5 && $verparts[2] >= 31)))
22 print "WARNING! Flex install not found, or unsupported Flex version.\n";
23 print "echo Attempting to build without.\n";
30 print "Input must be a .l file\n";
35 print "Input file $input not found\n";
39 (my $output = $input) =~ s/\.l$/.c/;
41 # get flex flags from make file
42 my $makefile = dirname($input) . "/Makefile";
48 my $basetarg = basename($output);
49 my $flexflags = ($make =~ /^$basetarg:\s*FLEXFLAGS\s*=\s*(\S.*)/m ? $1 : '');
51 system("flex $flexflags -o$output $input");
55 # For non-reentrant scanners we need to fix up the yywrap macro definition
56 # to keep the MS compiler happy.
57 # For reentrant scanners (like the core scanner) we do not
58 # need to (and must not) change the yywrap definition.
60 open($lfile, $input) || die "opening $input for reading: $!";
63 if ($lcode !~ /\%option\sreentrant/)
66 open($cfile, $output) || die "opening $output for reading: $!";
69 $ccode =~ s/yywrap\(n\)/yywrap()/;
70 open($cfile, ">$output") || die "opening $output for reading: $!";
74 if ($flexflags =~ /\s-b\s/)
76 my $lexback = "lex.backup";
77 open($lfile, $lexback) || die "opening $lexback for reading: $!";
78 my $lexbacklines = <$lfile>;
80 my $linecount = $lexbacklines =~ tr /\n/\n/;
83 print "Scanner requires backup, see lex.backup.\n";