1# -*-perl-*- hey - emacs - this is a perl file 2 3# src/tools/msvc/pgbison.pl 4 5use strict; 6use File::Basename; 7 8# assume we are in the postgres source root 9 10do './src/tools/msvc/buildenv.pl' if -e 'src/tools/msvc/buildenv.pl'; 11 12my ($bisonver) = `bison -V`; # grab first line 13$bisonver = (split(/\s+/, $bisonver))[3]; # grab version number 14 15unless ($bisonver eq '1.875' || $bisonver ge '2.2') 16{ 17 print "WARNING! Bison install not found, or unsupported Bison version.\n"; 18 print "echo Attempting to build without.\n"; 19 exit 0; 20} 21 22my $input = shift; 23if ($input !~ /\.y$/) 24{ 25 print "Input must be a .y file\n"; 26 exit 1; 27} 28elsif (!-e $input) 29{ 30 print "Input file $input not found\n"; 31 exit 1; 32} 33 34(my $output = $input) =~ s/\.y$/.c/; 35 36# plpgsql just has to be different 37$output =~ s/gram\.c$/pl_gram.c/ if $input =~ /src.pl.plpgsql.src.gram\.y$/; 38 39my $makefile = dirname($input) . "/Makefile"; 40my ($mf, $make); 41open($mf, $makefile); 42local $/ = undef; 43$make = <$mf>; 44close($mf); 45my $basetarg = basename($output); 46my $headerflag = ($make =~ /^$basetarg:\s+BISONFLAGS\b.*-d/m ? '-d' : ''); 47 48my $nodep = $bisonver ge '3.0' ? "-Wno-deprecated" : ""; 49 50system("bison $nodep $headerflag $input -o $output"); 51exit $? >> 8; 52