automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Patch: yacc5.test fix


From: Tom Tromey
Subject: Patch: yacc5.test fix
Date: 19 Jun 2001 23:31:38 -0600

This fixes yacc5.test.  Unfortunately it is somewhat ugly.
For one thing it replicates a bit of logic.  For another it still
leaves per-executable YFLAGS not working :-(

Fixing that will require more work.  I'm not sure the best way to
approach it.  One way would be to add a new attribute of a language
which is like `compile' but which is a function to call to do the
work.  (The yacc/lex code is too complex to put in the compile
attribute.)

Unfortunately this is hard since the yacc code needs to know if it
needs to run ylwrap, which is only known after we've processed all the
files (i.e., after the compile functions would be used).

Also, I think this code suffers from some srcdir/builddir confusion.

I'm not going to check this in as-is.  I'm just posting it in case
there are comments or whatnot.

This stuff is still way too complex.

2001-06-19  Tom Tromey  <address@hidden>

        Fix for yacc5.test:
        * lib/am/yacc.am: Rewrote to use new substitutions.
        * lib/am/lex.am: Likewise.
        * automake.in (handle_languages): Skip files whose language
        doesn't have a compiler.
        (lang_yacc_rewrite): Handle case where source is in subdir.
        (lang_yaccxx_rewrite): Likewise.
        (lang_lex_rewrite): Likewise.
        (lang_lexxx_rewrite): Likewise.
        (output_yacc_build_rule): Prototype.  Rewrote.
        (output_lex_build_rule): Likewise.
        (lang_yacc_finish): Handle subdir yacc files.
        (lang_lex_finish): Handle subdir lex files.

Tom

Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1141
diff -u -r1.1141 automake.in
--- automake.in 2001/06/18 01:08:34     1.1141
+++ automake.in 2001/06/20 05:04:45
@@ -1581,6 +1581,9 @@
            my $flags = $lang->flags || '';
            my $val = "${derived}_${flags}";
 
+           next
+               unless defined $lang->compile;
+
            (my $obj_compile = $lang->compile) =~ s/\(AM_$flags/\($val/;
            my $obj_ltcompile = '$(LIBTOOL) --mode=compile ' . $obj_compile;
 
@@ -1661,32 +1664,75 @@
        define_linker_variable ($languages{'c'});
       }
 }
-
-# Output a rule to build from a YACC source.  The output from YACC is
-# compiled with C or C++, depending on the extension of the YACC file.
-sub output_yacc_build_rule
-{
-    my ($yacc_suffix, $use_ylwrap) = @_;
 
-    (my $c_suffix = $yacc_suffix) =~ tr/y/c/;
+# output_yacc_build_rule ($SOURCE, $DEST, $USE_YLWRAP)
+# ----------------------------------------------------
+# Output a rule to build from a YACC source.  (The output from YACC is
+# compiled with C or C++, depending on the extension of the YACC
+# file.)  SOURCE is the name of the source file; it can be an
+# extension as well; in that case we'll generate a suffix rule.  #
+# DEST is the name of the output file.  It should be empty when a
+# suffix rule is desired.  USE_YLWRAP is a boolean which is true if
+# ylwrap will be used to compile the yacc file.
+sub output_yacc_build_rule ($$$)
+{
+    my ($source, $dest, $use_ylwrap) = @_;
+
+    my $destfile = $dest;
+    my $target;
+    if ($dest eq '')
+    {
+       # An empty $DEST means we are doing a suffix rule here.
+       ($dest = $source) =~ tr/y/c/;
+       # For a suffix rule, use (e.g.), `$*.c' as the destination
+       # file name.
+       $destfile = "\$*" . $dest;
+       $target = "${source}${dest}:";
+    }
+    else
+    {
+       $target = "${dest}: ${source}";
+    }
 
     # Generate rule for c/c++.
     $output_rules .= &file_contents ('yacc',
                                     ('YLWRAP'      => $use_ylwrap,
-                                     'YACC_SUFFIX' => $yacc_suffix,
-                                     'C_SUFFIX'    => $c_suffix));
+                                     'DESTFILE'    => $destfile,
+                                     'YTARGET'     => $target));
 }
 
-sub output_lex_build_rule
-{
-    my ($lex_suffix, $use_ylwrap) = @_;
-
-    (my $c_suffix = $lex_suffix) =~ tr/l/c/;
+# output_lex_build_rule ($SOURCE, $DEST, $USE_YLWRAP)
+# ---------------------------------------------------
+# Output a rule to build from a LEX source.  (The output from LEX is
+# compiled with C or C++, depending on the extension of the LEX file.)
+# SOURCE is the name of the source file; it can be an extension as
+# well; in that case we'll generate a suffix rule.  # DEST is the name
+# of the output file.  It should be empty when a suffix rule is
+# desired.  USE_YLWRAP is a boolean which is true if ylwrap will be
+# used to compile the yacc file.
+sub output_lex_build_rule ($$$)
+{
+    my ($source, $dest, $use_ylwrap) = @_;
+
+    my $destfile = $dest;
+    my $target;
+    if ($dest eq '')
+    {
+       # An empty $DEST means we are doing a suffix rule here.
+       ($dest = $source) =~ tr/l/c/;
+       $destfile = "\$\@";
+       $target = "${source}${dest}:";
+    }
+    else
+    {
+       $target = "${dest}: ${source}";
+    }
 
+    # Generate rule for c/c++.
     $output_rules .= &file_contents ('lex',
-                                    ('YLWRAP'     => $use_ylwrap,
-                                     'LEX_SUFFIX' => $lex_suffix,
-                                     'C_SUFFIX'   => $c_suffix));
+                                    ('YLWRAP'      => $use_ylwrap,
+                                     'DESTFILE'    => $destfile,
+                                     'LTARGET'     => $target));
 }
 
 # Check to make sure a source defined in LIBOBJS is not explicitly
@@ -4872,11 +4918,14 @@
     {
        $pfx = $directory . '/';
     }
-    $yacc_sources{$pfx . $base . '.' . $ext} = 1;
-    $ext =~ tr/y/c/;
-    &saw_extension ('c');
+    # The key is the full path of the source file; the value is where
+    # we place the output file.
+    (my $newext = $ext) =~ tr/y/c/;
+    $yacc_sources{$directory . '/' . $base . '.' . $ext} =
+       $pfx . $base . '.' . $newext;
+    &saw_extension ($newext);
     # FIXME: nodist.
-    &push_dist_common ($pfx . $base . '.' . $ext);
+    &push_dist_common ($pfx . $base . '.' . $newext);
     return $r;
 }
 
@@ -4892,11 +4941,14 @@
        $pfx = $directory . '/';
        $r = $LANG_SUBDIR;
     }
-    $yacc_sources{$pfx . $base . '.' . $ext} = 1;
-    $ext =~ tr/y/c/;
-    &saw_extension ($ext);
+    # The key is the full path of the source file; the value is where
+    # we place the output file.
+    (my $newext = $ext) =~ tr/y/c/;
+    $yacc_sources{$directory . '/' . $base . '.' . $ext} =
+       $pfx . $base . '.' . $newext;
+    &saw_extension ($newext);
     # FIXME: nodist.
-    &push_dist_common ($pfx . $base . '.' . $ext);
+    &push_dist_common ($pfx . $base . '.' . $newext);
     return $r;
 }
 
@@ -4911,11 +4963,14 @@
     {
        $pfx = $directory . '/';
     }
-    $lex_sources{$pfx . $base . '.' . $ext} = 1;
-    $ext =~ tr/l/c/;
-    &saw_extension ('c');
+    # The key is the full path of the source file; the value is where
+    # we place the output file.
+    (my $newext = $ext) =~ tr/y/c/;
+    $lex_sources{$directory . '/' . $base . '.' . $ext} =
+       $pfx . $base . '.' . $newext;
+    &saw_extension ($newext);
     # FIXME: nodist.
-    &push_dist_common ($pfx . $base . '.' . $ext);
+    &push_dist_common ($pfx . $base . '.' . $newext);
     return $r;
 }
 
@@ -4931,11 +4986,14 @@
        $pfx = $directory . '/';
        $r = $LANG_SUBDIR;
     }
-    $lex_sources{$pfx . $base . '.' . $ext} = 1;
-    $ext =~ tr/l/c/;
-    &saw_extension ($ext);
+    # The key is the full path of the source file; the value is where
+    # we place the output file.
+    (my $newext = $ext) =~ tr/y/c/;
+    $lex_sources{$directory . '/' . $base . '.' . $ext} =
+       $pfx . $base . '.' . $newext;
+    &saw_extension ($newext);
     # FIXME: nodist.
-    &push_dist_common ($pfx . $base . '.' . $ext);
+    &push_dist_common ($pfx . $base . '.' . $newext);
     return $r;
 }
 
@@ -5059,9 +5117,29 @@
     foreach my $file (@yacc_files)
     {
        $file =~ /(\..*)$/;
-       &output_yacc_build_rule ($1, $yacc_count > 1)
-           if ! defined $seen_suffix{$1};
-       $seen_suffix{$1} = 1;
+       my $suffix = $1;
+
+       # FIXME: logic replication.  Instead yacc ought to have a
+       # `compile' rule of some kind.
+       my ($src, $dest);
+       my $ok = 1;
+       if ($file =~ /\//)
+       {
+           # Needs a special rule.  FIXME: ought to handle per-object
+           # flags here too.
+           $src = $file;
+           $dest = $yacc_sources{$src};
+       }
+       else
+       {
+           # Nothing special.
+           $src = $suffix;
+           $dest = '';
+           $ok = ! defined $seen_suffix{$suffix};
+           $seen_suffix{$suffix} = 1;
+       }
+       &output_yacc_build_rule ($src, $dest, $yacc_count > 1)
+           if $ok;
 
        $file =~ /^(.*)\.(y|yy|y\+\+|yxx|ypp)$/;
        my $base = $1;
@@ -5114,9 +5192,30 @@
     foreach my $file (sort keys %lex_sources)
     {
        $file =~ /(\..*)$/;
-       &output_lex_build_rule ($1, $lex_count > 1)
-           if (! defined $seen_suffix{$1});
-       $seen_suffix{$1} = 1;
+       my $suffix = $1;
+
+       # FIXME: logic replication.  Instead yacc ought to have a
+       # `compile' rule of some kind.
+       my ($src, $dest);
+       my $ok = 1;
+       if ($file =~ /\//)
+       {
+           # Needs a special rule.  FIXME: ought to handle per-object
+           # flags here too.
+           $src = $file;
+           $dest = $lex_sources{$src};
+       }
+       else
+       {
+           # Nothing special.
+           $src = $suffix;
+           $dest = '';
+           $ok = ! defined $seen_suffix{$suffix};
+           $seen_suffix{$suffix} = 1;
+       }
+
+       &output_lex_build_rule ($src, $dest, $lex_count > 1)
+           if $ok;
 
        # If the files are built in the build directory, then we want
        # to remove them with `make clean'.  If they are in srcdir
Index: lib/am/lex.am
===================================================================
RCS file: /cvs/automake/automake/lib/am/lex.am,v
retrieving revision 1.2
diff -u -r1.2 lex.am
--- lex.am      2001/05/08 10:58:49     1.2
+++ lex.am      2001/06/20 05:04:45
@@ -20,9 +20,9 @@
 LEXLIB = @LEXLIB@
 
 ## Generate rule for c/c++.
-%LEX_SUFFIX%%C_SUFFIX%:
+%LTARGET%
 if %?YLWRAP%
-       $(SHELL) $(YLWRAP) $(LEX) $< $(LEX_OUTPUT_ROOT).c $@ -- $(AM_LFLAGS) 
$(LFLAGS)
+       $(SHELL) $(YLWRAP) $(LEX) $< $(LEX_OUTPUT_ROOT).c %DESTFILE% -- 
$(AM_LFLAGS) $(LFLAGS)
 else !%?YLWRAP%
-       $(LEX) $(AM_LFLAGS) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@
+       $(LEX) $(AM_LFLAGS) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c %DESTFILE%
 endif !%?YLWRAP%
Index: lib/am/yacc.am
===================================================================
RCS file: /cvs/automake/automake/lib/am/yacc.am,v
retrieving revision 1.4
diff -u -r1.4 yacc.am
--- yacc.am     2001/05/15 02:21:53     1.4
+++ yacc.am     2001/06/20 05:04:45
@@ -17,11 +17,11 @@
 ## 02111-1307, USA.
 
 ## Generate rule for c/c++.
-%YACC_SUFFIX%%C_SUFFIX%:
+%YTARGET%
 if %?YLWRAP%
-       $(SHELL) $(YLWRAP) $(YACC) $< y.tab.c $*%C_SUFFIX% y.tab.h $*.h -- 
$(AM_YFLAGS) $(YFLAGS)
+       $(SHELL) $(YLWRAP) $(YACC) $< y.tab.c %DESTFILE% y.tab.h $*.h -- 
$(AM_YFLAGS) $(YFLAGS)
 else !%?YLWRAP%
-       $(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*%C_SUFFIX%
+       $(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c %DESTFILE%
        if test -f y.tab.h; then \
          if cmp -s y.tab.h $*.h; then \
            rm -f y.tab.h; \



reply via email to

[Prev in Thread] Current Thread [Next in Thread]