On Fri, Aug 30, 2002 at 03:49:07PM -0400, Andy Dougherty wrote: > By default, traditional yacc puts its output files in y.tab.[ch]. Thus > my imcc/Makefile currently has > > $(YACC) -d -v imcc.y > mv y.tab.c imcparser.c > mv y.tab.h imcparser.h > > That's no problem, and works with YACC='yacc', 'bison -y', or 'byacc'. > However, the intermediate filename 'y.tab.c' isn't necessarily portable, > if I remember my Windows and VMS lore correctly. However, those platforms > probably have bison, which understands the simpler -o imcparser.c output > option. > > Thus what I'd really like to do here is generate two different makefile > fragments, depending on whether or not the user is using bison or (yacc or > byacc). With the current substitution-driven makefile.in system, it's not > obvious to me how best to do that. Anyone have any suggestions?
Well, you could extend the current system with something like the attached patch. (NOTE: The patch doesn't actually apply, because it collided with another pending patch and I'm too lazy to fix it since I'm unsure if this approach helps. But if you like the approach, then it's easy to hand-apply the Step.pm part.) It beefs up the ${subst} syntax by adding a new form ${subst(arg1,arg2,...)} that does the same thing but substitutes in numbered parameters as in the example in the patch. To make this useful to you, you'd have to fetch the whole command out of %Config instead of hardwiring it.
Index: config/gen/makefiles/imcc.in =================================================================== RCS file: /cvs/public/parrot/config/gen/makefiles/imcc.in,v retrieving revision 1.1 diff -p -u -r1.1 imcc.in --- config/gen/makefiles/imcc.in 27 Aug 2002 05:02:28 -0000 1.1 +++ config/gen/makefiles/imcc.in 31 Aug 2002 01:57:42 -0000 @@ -34,7 +34,7 @@ all : imcc cd ../.. && $(MAKE) shared && $(RM_F) parrot${exe} && $(MAKE) imcparser.c imcparser.h : imcc.y - $(YACC) -d -o imcparser.c imcc.y + ${yacc(imcc.y,imcparser.h,imcparser.c,-d)} imclexer.c : imcc.l $(HEADERS) $(LEX) imcc.l Index: config/init/data.pl =================================================================== RCS file: /cvs/public/parrot/config/init/data.pl,v retrieving revision 1.6 diff -p -u -r1.6 data.pl --- config/init/data.pl 29 Aug 2002 06:02:59 -0000 1.6 +++ config/init/data.pl 31 Aug 2002 01:57:45 -0000 @@ -24,6 +24,8 @@ sub runstep { ldflags => $Config{ldflags}, libs => $Config{libs}, + + yacc => 'bison -v -y $4 -o $3 $1', cc_inc => "-I./include", cc_debug => '-g', Index: lib/Parrot/Configure/Step.pm =================================================================== RCS file: /cvs/public/parrot/lib/Parrot/Configure/Step.pm,v retrieving revision 1.5 diff -p -u -r1.5 Step.pm --- lib/Parrot/Configure/Step.pm 3 Aug 2002 16:27:42 -0000 1.5 +++ lib/Parrot/Configure/Step.pm 31 Aug 2002 01:57:45 -0000 @@ -45,12 +46,27 @@ sub prompt { return $value; } + +sub substitute { + local $_ = shift; + if (/^(\w+)$/) { + return Configure::Data->get($1); + } else { + my ($command, $args) = /^(\w+)\((.*)\)$/ + or die "unrecognized substitution: \${$_}"; + my @args = split(/,/, $args); + $command = Configure::Data->get($command); + $command =~ s/\$(\d+)/$args[$1-1]/g; + return $command; + } +} + while(<IN>) { s{ - \$\{(\w+)\} - }{Configure::Data->get($1)}egx; + \$\{(.*?)\} + }{substitute($1)}egx; print OUT; } close IN or die "Can't close $source: $!"; close OUT or die "Can't close $target: $!";