automake-patches
[Top][All Lists]
Advanced

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

[PATCH 03/11] cleanup: having subdir-objects mandatory allow us some sim


From: Stefano Lattarini
Subject: [PATCH 03/11] cleanup: having subdir-objects mandatory allow us some simplifications
Date: Sat, 12 Jan 2013 13:51:56 +0100

Few minor cleanups made possible by earlier changes, plus other minor
cleanups triggered in cascade.  No semantic change is intended.

This is a follow-up on previous commit 'XXX', and an adjusted backport
of Automake-NG commit 'v1.12.1-315-gc97d41b' of 2012-06-08, "[ng] cleanup:
after enabling of subdir-objects unconditionally".

* automake.in (LANG_IGNORE, LANG_SUBDIR): Remove.
(handle_languages): Drop the '%DEPBASE%' transform when processing
the '$rule_file'.
(register_language ('name' => 'vala', ...)): Add '.vapi' to the entry
'extensions', and simplify the entry 'output_extensions' to point to
a dummy subroutine (since it wasn't really used anyway).
(handle_single_transform): No longer expect the 'lang_*_rewrite'
subroutines to return a 'LANG_*' constant, but only a transformed
extension, if required.  To decide whether further processing of the
source file should be stopped, rely on a new set of 'lang_*_ignore'
subroutines, defaulting to a subroutine that returns false.
Accordingly, don't special case the handling of '.vapi' files anymore,
instead rely on ...
(lang_vala_ignore, lang_header_ignore): ... these new subroutines to
avoid extra processing of C/C++ headers and Vala '.vapi' headers.
(lang_java_rewrite): Remove.
Remove an outdated comment.
* lib/am/depend2.am: Partial rewrite to reduce code duplication and
drop use of the '%DEPBASE%' transform.
* t/compile_f_c_cxx.sh: Adjust.

Signed-off-by: Stefano Lattarini <address@hidden>
---
 automake.in          | 128 ++++++++++++++++++---------------------------------
 lib/am/depend2.am    |  33 +++++++------
 t/compile_f_c_cxx.sh |   7 +--
 3 files changed, 68 insertions(+), 100 deletions(-)

diff --git a/automake.in b/automake.in
index 71a7feb..407dd76 100644
--- a/automake.in
+++ b/automake.in
@@ -265,13 +265,6 @@ my $gen_copyright = "\
 # PARTICULAR PURPOSE.
 ";
 
-# These constants are returned by the lang_*_rewrite functions.
-# LANG_SUBDIR means that the resulting object file should be in a
-# subdir if the source file is.  In this case the file name cannot
-# have '..' components.
-use constant LANG_IGNORE  => 0;
-use constant LANG_SUBDIR  => 2;
-
 # These are used when keeping track of whether an object can be built
 # by two different paths.
 use constant COMPILE_LIBTOOL  => 1;
@@ -792,7 +785,7 @@ register_language ('name' => 'header',
                   # Nothing to do.
                   '_finish' => sub { });
 
-# Vala
+# Vala.
 register_language ('name' => 'vala',
                   'Name' => 'Vala',
                   'config_vars' => ['VALAC'],
@@ -800,9 +793,10 @@ register_language ('name' => 'vala',
                   'compile' => '$(VALAC) $(AM_VALAFLAGS) $(VALAFLAGS)',
                   'ccer' => 'VALAC',
                   'compiler' => 'VALACOMPILE',
-                  'extensions' => ['.vala'],
-                  'output_extensions' => sub { (my $ext = $_[0]) =~ s/vala$/c/;
-                                               return ($ext,) },
+                  'extensions' => ['.vala', '.vapi'],
+                   # Vala compilation must be handled in a special way, so
+                   # nothing to do or return here.
+                  'output_extensions' => sub { },
                   'rule_file' => 'vala',
                   '_finish' => \&lang_vala_finish,
                   '_target_hook' => \&lang_vala_target_hook,
@@ -1402,26 +1396,13 @@ sub handle_languages
            # This is not used by depend2.am.
            my $der_ext = (&{$lang->output_extensions} ($ext))[0];
 
-           # When we output an inference rule like '.c.o:' we
-           # have two cases to consider: either subdir-objects
-           # is used, or it is not.
-           #
-           # In the latter case the rule is used to build objects
-           # in the current directory, and dependencies always
-           # go into './$(DEPDIR)/'.  We can hard-code this value.
-           #
-           # In the former case the rule can be used to build
-           # objects in sub-directories too.  Dependencies should
-           # go into the appropriate sub-directories, e.g.,
-           # 'sub/$(DEPDIR)/'.  The value of this directory
-           # needs to be computed on-the-fly.
-           #
-           # DEPBASE holds the name of this directory, plus the
-           # basename part of the object file (extensions Po, TPo,
-           # Plo, TPlo will be added later as appropriate).  It is
-           # either hardcoded, or a shell variable ('$depbase') that
-           # will be computed by the rule.
-           my $depbase = '$$depbase';
+            # Even when subdir sources are present, an inference rule
+            # like '.c.o:' can be used to build corresponding objects
+            # in the sane subdirectory too.  We should be careful to also
+            # place dependency files into the appropriate subdirectory,
+            # e.g., 'sub/$(DEPDIR)/'.  The value of this directory needs
+            # to be computed on-the-fly (that is done by our makefile
+            # recipes in 'depend2.am').
            $output_rules .=
              file_contents ($rule_file,
                             new Automake::Location,
@@ -1430,7 +1411,6 @@ sub handle_languages
 
                             'DERIVED-EXT' => $der_ext,
 
-                            DEPBASE   => $depbase,
                             BASE      => '$*',
                             SOURCE    => '$<',
                             SOURCEFLAG => $sourceflags{$ext} || '',
@@ -1487,20 +1467,12 @@ sub handle_languages
            # We _need_ '-o' for per object rules.
            my $output_flag = $lang->output_flag || '-o';
 
-           my $depbase = dirname ($obj);
-           $depbase = ''
-               if $depbase eq '.';
-           $depbase .= '/'
-               unless $depbase eq '';
-           $depbase .= '$(DEPDIR)/' . basename ($obj);
-
            $output_rules .=
              file_contents ($rule_file,
                             new Automake::Location,
                             %transform,
                             GENERIC   => 0,
 
-                            DEPBASE   => $depbase,
                             BASE      => $obj,
                             SOURCE    => $source,
                             SOURCEFLAG => $sourceflags{$srcext} || '',
@@ -1720,20 +1692,24 @@ sub handle_single_transform ($$$$$%)
                  }
              }
 
-           # Note: computed subr call.  The language rewrite function
-           # should return one of the LANG_* constants.  It could
-           # also return a list whose first value is such a constant
-           # and whose second value is a new source extension which
-           # should be applied.  This means this particular language
-           # generates another source file which we must then process
-           # further.
-           my $subr = \&{'lang_' . $lang->name . '_rewrite'};
-            defined &$subr or $subr = sub { return LANG_SUBDIR; };
-           my ($r, $source_extension)
-               = &$subr ($directory, $base, $extension,
-                         $obj, $have_per_exec_flags, $var);
-           # Skip this entry if we were asked not to process it.
-           next if $r == LANG_IGNORE;
+            # NOTE: computed subr calls here.
+
+            # The language ignore function can ask not to preprocess
+            # a source file further.
+            my $subr_ignore = \&{'lang_' . $lang->name . '_ignore'};
+            next if defined &$subr_ignore
+                    and &$subr_ignore ($directory, $base, $extension);
+            # The language rewrite function can return a new source
+            # extension which should be applied.  This means this
+            # particular language generates another source file which
+            # we must then process further.  This happens, for example,
+            # with yacc and lex.
+            my $subr_rewrite = \&{'lang_' . $lang->name . '_rewrite'};
+            $subr_rewrite = sub { } unless defined &$subr_rewrite;
+            my $source_extension = &$subr_rewrite ($directory, $base,
+                                                   $extension, $obj,
+                                                   $have_per_exec_flags,
+                                                   $var);
 
            # Now extract linker and other info.
            $linker = $lang->linker;
@@ -1783,10 +1759,8 @@ sub handle_single_transform ($$$$$%)
 
            # If rewrite said it was ok, put the object into a
            # subdir.
-           if ($r == LANG_SUBDIR && $directory ne '')
-           {
-               $object = $directory . '/' . $object;
-           }
+           $object = $directory . '/' . $object
+             unless $directory eq '';
 
            # If the object file has been renamed (because per-target
            # flags are used) we cannot compile the file with an
@@ -5560,40 +5534,37 @@ sub check_gnits_standards
 #
 # Functions to handle files of each language.
 
-# Each 'lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a
-# simple formula: Return value is LANG_SUBDIR if the resulting object
-# file should be in a subdir if the source file is, LANG_PROCESS if
-# file is to be dealt with, LANG_IGNORE otherwise.
-
 # Much of the actual processing is handled in
 # handle_single_transform.  These functions exist so that
 # auxiliary information can be recorded for a later cleanup pass.
 # Note that the calls to these functions are computed, so don't bother
 # searching for their precise names in the source.
 
-# Rewrite a single header file.
-sub lang_header_rewrite
+# Header files are simply ignored.
+sub lang_header_ignore { 1; }
+
+# Vala '.vapi' are a kind of header files as well, and should
+# not be processed into compilation rules.
+ sub lang_vala_ignore
 {
-    # Header files are simply ignored.
-    return LANG_IGNORE;
+    my ($directory, $base, $ext) = @_;
+    return ($ext =~ m/\.vapi$/ ? 1 : 0);
 }
 
 # Rewrite a single Vala source file.
 sub lang_vala_rewrite
 {
     my ($directory, $base, $ext) = @_;
-
-    (my $newext = $ext) =~ s/vala$/c/;
-    return (LANG_SUBDIR, $newext);
+    $ext =~ s/vala$/c/;
+    return $ext;
 }
 
 # Rewrite a single yacc/yacc++ file.
 sub lang_yacc_rewrite
 {
     my ($directory, $base, $ext) = @_;
-
-    (my $newext = $ext) =~ tr/y/c/;
-    return (LANG_SUBDIR, $newext);
+    $ext =~ tr/y/c/;
+    return $ext;
 }
 sub lang_yaccxx_rewrite { lang_yacc_rewrite (@_); };
 
@@ -5601,18 +5572,11 @@ sub lang_yaccxx_rewrite { lang_yacc_rewrite (@_); };
 sub lang_lex_rewrite
 {
     my ($directory, $base, $ext) = @_;
-
-    (my $newext = $ext) =~ tr/l/c/;
-    return (LANG_SUBDIR, $newext);
+    $ext =~ tr/l/c/;
+    return $ext;
 }
 sub lang_lexxx_rewrite { lang_lex_rewrite (@_); };
 
-# Rewrite a single Java file.
-sub lang_java_rewrite
-{
-    return LANG_SUBDIR;
-}
-
 # The lang_X_finish functions are called after all source file
 # processing is done.  Each should handle defining rules for the
 # language, etc.  A finish function is only called if a source file of
diff --git a/lib/am/depend2.am b/lib/am/depend2.am
index a13379a..c727bd8 100644
--- a/lib/am/depend2.am
+++ b/lib/am/depend2.am
@@ -38,11 +38,12 @@ if %?NONLIBTOOL%
 if %FASTDEP%
 ## In fast-dep mode, we can always use -o.
 ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%.
-?!GENERIC?     %VERBOSE%%COMPILE% -MT %OBJ% -MD -MP -MF %DEPBASE%.Tpo %-c% -o 
%OBJ% %SOURCEFLAG%`test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE%
-?!GENERIC?     %SILENT%$(am__mv) %DEPBASE%.Tpo %DEPBASE%.Po
-?GENERIC?      %VERBOSE%depbase=`echo %OBJ% | sed 
's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
-?GENERIC?      %COMPILE% -MT %OBJ% -MD -MP -MF %DEPBASE%.Tpo %-c% -o %OBJ% 
%SOURCEFLAG%%SOURCE% &&\
-?GENERIC?      $(am__mv) %DEPBASE%.Tpo %DEPBASE%.Po
+## TODO: rewrite this to avoid extra forks once we can assume a POSIX
+## TODO: shell.
+       %VERBOSE%depbase=`echo %OBJ% | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'` \
+?!GENERIC?     && %COMPILE% -MT %OBJ% -MD -MP -MF $$depbase.Tpo %-c% -o %OBJ% 
%SOURCEFLAG%`test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% \
+?GENERIC?      && %COMPILE% -MT %OBJ% -MD -MP -MF $$depbase.Tpo %-c% -o %OBJ% 
%SOURCEFLAG%%SOURCE% \
+       && $(am__mv) $$depbase.Tpo $$depbase.Po
 else !%FASTDEP%
 if %AMDEP%
        %VERBOSE%source='%SOURCE%' object='%OBJ%' libtool=no @AMDEPBACKSLASH@
@@ -63,11 +64,12 @@ endif !%FASTDEP%
 if %FASTDEP%
 ## In fast-dep mode, we can always use -o.
 ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%.
-?!GENERIC?     %VERBOSE%%COMPILE% -MT %OBJOBJ% -MD -MP -MF %DEPBASE%.Tpo %-c% 
-o %OBJOBJ% %SOURCEFLAG%`if test -f '%SOURCE%'; then $(CYGPATH_W) '%SOURCE%'; 
else $(CYGPATH_W) '$(srcdir)/%SOURCE%'; fi`
-?!GENERIC?     %SILENT%$(am__mv) %DEPBASE%.Tpo %DEPBASE%.Po
-?GENERIC?      %VERBOSE%depbase=`echo %OBJ% | sed 
's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
-?GENERIC?      %COMPILE% -MT %OBJOBJ% -MD -MP -MF %DEPBASE%.Tpo %-c% -o 
%OBJOBJ% %SOURCEFLAG%`$(CYGPATH_W) '%SOURCE%'` &&\
-?GENERIC?      $(am__mv) %DEPBASE%.Tpo %DEPBASE%.Po
+## TODO: rewrite this to avoid extra forks once we can assume a POSIX
+## TODO: shell.
+       %VERBOSE%depbase=`echo %OBJ% | sed 
's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'` \
+?!GENERIC?     && %COMPILE% -MT %OBJOBJ% -MD -MP -MF $$depbase.Tpo %-c% -o 
%OBJOBJ% %SOURCEFLAG%`if test -f '%SOURCE%'; then $(CYGPATH_W) '%SOURCE%'; else 
$(CYGPATH_W) '$(srcdir)/%SOURCE%'; fi` \
+?GENERIC?      && %COMPILE% -MT %OBJOBJ% -MD -MP -MF $$depbase.Tpo %-c% -o 
%OBJOBJ% %SOURCEFLAG%`$(CYGPATH_W) '%SOURCE%'` \
+       && $(am__mv) $$depbase.Tpo $$depbase.Po
 else !%FASTDEP%
 if %AMDEP%
        %VERBOSE%source='%SOURCE%' object='%OBJOBJ%' libtool=no @AMDEPBACKSLASH@
@@ -90,11 +92,12 @@ if %?LIBTOOL%
 if %FASTDEP%
 ## In fast-dep mode, we can always use -o.
 ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%.
-?!GENERIC?     %VERBOSE%%LTCOMPILE% -MT %LTOBJ% -MD -MP -MF %DEPBASE%.Tpo %-c% 
-o %LTOBJ% %SOURCEFLAG%`test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE%
-?!GENERIC?     %SILENT%$(am__mv) %DEPBASE%.Tpo %DEPBASE%.Plo
-?GENERIC?      %VERBOSE%depbase=`echo %OBJ% | sed 
's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
-?GENERIC?      %LTCOMPILE% -MT %LTOBJ% -MD -MP -MF %DEPBASE%.Tpo %-c% -o 
%LTOBJ% %SOURCEFLAG%%SOURCE% &&\
-?GENERIC?      $(am__mv) %DEPBASE%.Tpo %DEPBASE%.Plo
+## TODO: rewrite this to avoid extra forks once we can assume a POSIX
+## TODO: shell.
+       %VERBOSE%depbase=`echo %OBJ% | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'` 
\
+?!GENERIC?     && %LTCOMPILE% -MT %LTOBJ% -MD -MP -MF $$depbase.Tpo %-c% -o 
%LTOBJ% %SOURCEFLAG%`test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% \
+?GENERIC?      && %LTCOMPILE% -MT %LTOBJ% -MD -MP -MF $$depbase.Tpo %-c% -o 
%LTOBJ% %SOURCEFLAG%%SOURCE% \
+       && $(am__mv) $$depbase.Tpo $$depbase.Plo
 else !%FASTDEP%
 if %AMDEP%
        %VERBOSE%source='%SOURCE%' object='%LTOBJ%' libtool=yes @AMDEPBACKSLASH@
diff --git a/t/compile_f_c_cxx.sh b/t/compile_f_c_cxx.sh
index 2562d7d..4b9189d 100755
--- a/t/compile_f_c_cxx.sh
+++ b/t/compile_f_c_cxx.sh
@@ -41,12 +41,13 @@ $AUTOMAKE
 $FGREP COMPILE Makefile.in # For debugging.
 
 # Look for the macros at the beginning of rules.
-sed < Makefile.in > mk \
+
+sed -e "s|$tab *&& *|$tab|" \
     -e 's|$(AM_V_CC)||g' \
     -e 's|$(AM_V_CXX)||g' \
-    -e 's|$(AM_V_F77)||g'
+    -e 's|$(AM_V_F77)||g' \
+  Makefile.in >mk
 diff -u Makefile.in mk || : # For debugging.
-
 $FGREP "$tab\$(COMPILE)"    mk
 $FGREP "$tab\$(CXXCOMPILE)" mk
 $FGREP "$tab\$(F77COMPILE)" mk
-- 
1.8.1.rc3.192.g2d0029e




reply via email to

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