refactor: silent rules handling (a little)
[platform/upstream/automake.git] / automake.in
index 8b00941..722a202 100644 (file)
@@ -42,8 +42,9 @@ BEGIN
   $ENV{'SHELL'} = '@SHELL@' if exists $ENV{'DJDIR'};
 }
 
-use Automake::Struct;
-struct (# Short name of the language (c, f77...).
+use Class::Struct ();
+Class::Struct::struct (
+       # Short name of the language (c, f77...).
        'name' => "\$",
        # Nice name of the language (C, Fortran 77...).
        'Name' => "\$",
@@ -149,7 +150,6 @@ use Automake::Location;
 use Automake::Condition qw/TRUE FALSE/;
 use Automake::DisjConditions;
 use Automake::Options;
-use Automake::Version;
 use Automake::Variable;
 use Automake::VarDef;
 use Automake::Rule;
@@ -252,9 +252,8 @@ my %standard_prefix =
 
 # Copyright on generated Makefile.ins.
 my $gen_copyright = "\
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
-# Foundation, Inc.
+# Copyright (C) 1994-$RELEASE_YEAR Free Software Foundation, Inc.
+
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
 # with or without modifications, as long as this notice is preserved.
@@ -287,7 +286,6 @@ use constant QUEUE_MESSAGE   => "msg";
 use constant QUEUE_CONF_FILE => "conf file";
 use constant QUEUE_LOCATION  => "location";
 use constant QUEUE_STRING    => "string";
-\f
 
 ## ---------------------------------- ##
 ## Variables related to the options.  ##
@@ -421,7 +419,7 @@ my %configure_cond = ();
 my %extension_map = ();
 
 # List of the DIST_COMMON files we discovered while reading
-# configure.in
+# configure.ac.
 my $configure_dist_common = '';
 
 # This maps languages names onto objects.
@@ -473,7 +471,6 @@ my $required_conf_file_queue;
 
 # The name of the Makefile currently being processed.
 my $am_file = 'BUG';
-\f
 
 ################################################################
 
@@ -593,7 +590,6 @@ my $must_handle_compiled_objects;
 
 # Record each file processed by make_paragraphs.
 my %transformed_files;
-\f
 
 ################################################################
 
@@ -763,6 +759,24 @@ register_language ('name' => 'objc',
                   'pure' => 1,
                   'extensions' => ['.m']);
 
+# Objective C++.
+register_language ('name' => 'objcxx',
+                  'Name' => 'Objective C++',
+                  'config_vars' => ['OBJCXX'],
+                  'linker' => 'OBJCXXLINK',
+                  'link' => '$(OBJCXXLD) $(AM_OBJCXXFLAGS) $(OBJCXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@',
+                  'autodep' => 'OBJCXX',
+                  'flags' => ['OBJCXXFLAGS', 'CPPFLAGS'],
+                  'compile' => '$(OBJCXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_OBJCXXFLAGS) $(OBJCXXFLAGS)',
+                  'ccer' => 'OBJCXX',
+                  'compiler' => 'OBJCXXCOMPILE',
+                  'compile_flag' => '-c',
+                  'output_flag' => '-o',
+                  'lder' => 'OBJCXXLD',
+                  'ld' => '$(OBJCXX)',
+                  'pure' => 1,
+                  'extensions' => ['.mm']);
+
 # Unified Parallel C.
 register_language ('name' => 'upc',
                   'Name' => 'Unified Parallel C',
@@ -957,8 +971,7 @@ register_language ('name' => 'ppfc',
 # passing "$(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS)
 # $(CPPFLAGS)" as additional flags to the Fortran 77 compiler, since
 # this is how GNU Make does it; see the "GNU Make Manual, Edition 0.51
-# for `make' Version 3.76 Beta" (specifically, from info file
-# for `make' Version 3.76 Beta" (specifically, from info file
+# for 'make' Version 3.76 Beta" (specifically, from info file
 # '(make)Catalogue of Rules').
 #
 # A better approach would be to write an Autoconf test
@@ -1125,15 +1138,19 @@ sub verbose_private_var ($)
     return 'am__v_' . $name;
 }
 
-# define_verbose_var (NAME, VAL)
-# ------------------------------
-# For 'silent-rules' mode, setup VAR and dispatcher, to expand to VAL if silent.
-sub define_verbose_var ($$)
+# define_verbose_var (NAME, VAL-IF-SILENT, [VAL-IF-VERBOSE])
+# ----------------------------------------------------------
+# For 'silent-rules' mode, setup VAR and dispatcher, to expand to
+# VAL-IF-SILENT if silent, to VAL-IF-VERBOSE (defaulting to empty)
+# if not.
+sub define_verbose_var ($$;$)
 {
-    my ($name, $val) = @_;
+    my ($name, $silent_val, $verbose_val) = @_;
+    $verbose_val = '' unless defined $verbose_val;
     my $var = verbose_var ($name);
     my $pvar = verbose_private_var ($name);
     my $silent_var = $pvar . '_0';
+    my $verbose_var = $pvar . '_1';
     if (option 'silent-rules')
       {
        # For typical 'make's, 'configure' replaces AM_V (inside @@) with $(V)
@@ -1142,10 +1159,13 @@ sub define_verbose_var ($$)
        # See AM_SILENT_RULES in m4/silent.m4.
        define_variable ($var, '$(' . $pvar . '_@'.'AM_V'.'@)', INTERNAL);
        define_variable ($pvar . '_', '$(' . $pvar . '_@'.'AM_DEFAULT_V'.'@)', INTERNAL);
-       Automake::Variable::define ($silent_var, VAR_AUTOMAKE, '', TRUE, $val,
-                                   '', INTERNAL, VAR_ASIS)
+        Automake::Variable::define ($silent_var, VAR_AUTOMAKE, '', TRUE,
+                                    $silent_val, '', INTERNAL, VAR_ASIS)
          if (! vardef ($silent_var, TRUE));
-      }
+        Automake::Variable::define ($verbose_var, VAR_AUTOMAKE, '', TRUE,
+                                    $verbose_val, '', INTERNAL, VAR_ASIS)
+         if (! vardef ($verbose_var, TRUE));
+}
 }
 
 # Above should not be needed in the general automake code.
@@ -1186,7 +1206,6 @@ sub define_verbose_tagvar ($)
     if (option 'silent-rules')
       {
        define_verbose_var ($name, '@echo "  '. $name . ' ' x (8 - length ($name)) . '" $@;');
-       define_verbose_var ('at', '@');
       }
 }
 
@@ -1213,6 +1232,14 @@ sub define_verbose_libtool ()
     return verbose_flag ('lt');
 }
 
+sub handle_silent ()
+{
+    return unless option 'silent-rules';
+    # *Always* provide the user with 'AM_V_GEN' for 'silent-rules' mode.
+    define_verbose_tagvar ('GEN');
+    define_verbose_var ('at', '@');
+}
+
 
 ################################################################
 
@@ -1570,9 +1597,6 @@ sub handle_languages
          unless defined $done{$languages{'c'}};
        define_linker_variable ($languages{'c'});
       }
-
-    # Always provide the user with 'AM_V_GEN' for 'silent-rules' mode.
-    define_verbose_tagvar ('GEN');
 }
 
 
@@ -3618,7 +3642,7 @@ sub handle_tags
     if (var ('SUBDIRS'))
     {
        $output_rules .= ("tags-recursive:\n"
-                         . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
+                         . "\tlist='\$(SUBDIRS)'; for subdir in \$\$list; do \\\n"
                          # Never fail here if a subdir fails; it
                          # isn't important.
                          . "\t  test \"\$\$subdir\" = . || (\$(am__cd) \$\$subdir"
@@ -3629,7 +3653,7 @@ sub handle_tags
        &depend ('.MAKE', 'tags-recursive');
 
        $output_rules .= ("ctags-recursive:\n"
-                         . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
+                         . "\tlist='\$(SUBDIRS)'; for subdir in \$\$list; do \\\n"
                          # Never fail here if a subdir fails; it
                          # isn't important.
                          . "\t  test \"\$\$subdir\" = . || (\$(am__cd) \$\$subdir"
@@ -3640,7 +3664,7 @@ sub handle_tags
        &depend ('.MAKE', 'ctags-recursive');
 
        $output_rules .= ("cscopelist-recursive:\n"
-                         . "\tlist=\'\$(SUBDIRS)\'; for subdir in \$\$list; do \\\n"
+                         . "\tlist='\$(SUBDIRS)'; for subdir in \$\$list; do \\\n"
                          # Never fail here if a subdir fails; it
                          # isn't important.
                          . "\t  test \"\$\$subdir\" = . || (\$(am__cd) \$\$subdir"
@@ -5210,6 +5234,7 @@ sub scan_autoconf_traces ($)
                AC_REQUIRE_AUX_FILE => 1,
                AC_SUBST_TRACE => 1,
                AM_AUTOMAKE_VERSION => 1,
+                AM_PROG_MKDIR_P => 0, # FIXME: to be removed in 1.13
                AM_CONDITIONAL => 2,
                AM_GNU_GETTEXT => 0,
                AM_GNU_GETTEXT_INTL_SUBDIR => 0,
@@ -5368,6 +5393,14 @@ sub scan_autoconf_traces ($)
 
          $seen_automake_version = 1;
        }
+      elsif ($macro eq 'AM_PROG_MKDIR_P') # FIXME: to be removed in 1.13
+       {
+         msg 'obsolete', $where, <<'EOF';
+The 'AM_PROG_MKDIR_P' macro is deprecated, and will soon be removed.
+You should use the Autoconf-provided 'AC_PROG_MKDIR_P' macro instead,
+and use '$(MKDIR_P)' instead of '$(mkdir_p)'in your Makefile.am files.
+EOF
+       }
       elsif ($macro eq 'AM_CONDITIONAL')
        {
          $configure_cond{$args[1]} = $where;
@@ -5387,6 +5420,10 @@ sub scan_autoconf_traces ($)
          $seen_init_automake = $where;
          if (defined $args[2])
            {
+              msg 'obsolete', $where, <<'EOF';
+AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
+http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_INIT_AUTOMAKE-invocation
+EOF
              $package_version = $args[2];
              $package_version_location = $where;
            }
@@ -5575,6 +5612,11 @@ sub check_cygnus
   my $cygnus = option 'cygnus';
   return unless $cygnus;
 
+  # This feature is deprecated, will be removed in the next
+  # Automake major release.
+  msg 'obsolete', $cygnus->get,
+      "support for Cygnus-style trees is deprecated";
+
   set_strictness ('foreign');
   set_option ('no-installinfo', $cygnus);
   set_option ('no-dependencies', $cygnus);
@@ -5797,6 +5839,12 @@ sub lang_objc_rewrite
     return &lang_sub_obj;
 }
 
+# Rewrite a single Objective C++ file.
+sub lang_objcxx_rewrite
+{
+    return &lang_sub_obj;
+}
+
 # Rewrite a single Unified Parallel C file.
 sub lang_upc_rewrite
 {
@@ -5819,19 +5867,26 @@ sub lang_vala_finish_target ($$)
   my ($self, $name) = @_;
 
   my $derived = canonicalize ($name);
-  my $varname = $derived . '_SOURCES';
-  my $var = var ($varname);
+  my $var = var "${derived}_SOURCES";
+  return unless $var;
 
-  if ($var)
+  my @vala_sources = grep { /\.(vala|vapi)$/ } ($var->value_as_list_recursive);
+
+  # For automake bug#11229.
+  return unless @vala_sources;
+
+  foreach my $vala_file (@vala_sources)
     {
-      foreach my $file ($var->value_as_list_recursive)
+      my $c_file = $vala_file;
+      if ($c_file =~ s/(.*)\.vala$/$1.c/)
         {
-          $output_rules .= "\$(srcdir)/$file: \$(srcdir)/${derived}_vala.stamp\n"
+          $c_file = "\$(srcdir)/$c_file";
+          $output_rules .= "$c_file: \$(srcdir)/${derived}_vala.stamp\n"
             . "\t\@if test -f \$@; then :; else rm -f \$(srcdir)/${derived}_vala.stamp; fi\n"
             . "\t\@if test -f \$@; then :; else \\\n"
             . "\t  \$(MAKE) \$(AM_MAKEFLAGS) \$(srcdir)/${derived}_vala.stamp; \\\n"
-           . "\tfi\n"
-            if $file =~ s/(.*)\.vala$/$1.c/;
+            . "\tfi\n";
+         $clean_files{$c_file} = MAINTAINER_CLEAN;
         }
     }
 
@@ -5845,8 +5900,8 @@ sub lang_vala_finish_target ($$)
          if (grep (/$lastflag/, ('-H', '-h', '--header', '--internal-header',
                                  '--vapi', '--internal-vapi', '--gir')))
            {
-             my $headerfile = $flag;
-             $output_rules .= "\$(srcdir)/$headerfile: \$(srcdir)/${derived}_vala.stamp\n"
+             my $headerfile = "\$(srcdir)/$flag";
+             $output_rules .= "$headerfile: \$(srcdir)/${derived}_vala.stamp\n"
                . "\t\@if test -f \$@; then :; else rm -f \$(srcdir)/${derived}_vala.stamp; fi\n"
                . "\t\@if test -f \$@; then :; else \\\n"
                . "\t  \$(MAKE) \$(AM_MAKEFLAGS) \$(srcdir)/${derived}_vala.stamp; \\\n"
@@ -5871,7 +5926,7 @@ sub lang_vala_finish_target ($$)
 
   # VALAFLAGS is a user variable (per GNU Standards),
   # it should not be overridden in the Makefile...
-  check_user_variables ['VALAFLAGS'];
+  check_user_variables 'VALAFLAGS';
 
   my $dirname = dirname ($name);
 
@@ -5880,9 +5935,10 @@ sub lang_vala_finish_target ($$)
 
   my $verbose = verbose_flag ('VALAC');
   my $silent = silent_flag ();
+  my $stampfile = "\$(srcdir)/${derived}_vala.stamp";
 
   $output_rules .=
-    "\$(srcdir)/${derived}_vala.stamp: \$(${derived}_SOURCES)\n".
+    "\$(srcdir)/${derived}_vala.stamp: @vala_sources\n".
 # Since the C files generated from the vala sources depend on the
 # ${derived}_vala.stamp file, we must ensure its timestamp is older than
 # those of the C files generated by the valac invocation below (this is
@@ -5890,12 +5946,12 @@ sub lang_vala_finish_target ($$)
 # Thus we need to create the stamp file *before* invoking valac, and to
 # move it to its final location only after valac has been invoked.
     "\t${silent}rm -f \$\@ && echo stamp > \$\@-t\n".
-    "\t${verbose}\$(am__cd) \$(srcdir) && ${compile} \$(${derived}_SOURCES)\n".
+    "\t${verbose}\$(am__cd) \$(srcdir) && $compile @vala_sources\n".
     "\t${silent}mv -f \$\@-t \$\@\n";
 
-  push_dist_common ("${derived}_vala.stamp");
+  push_dist_common ($stampfile);
 
-  $clean_files{"${derived}_vala.stamp"} = MAINTAINER_CLEAN;
+  $clean_files{$stampfile} = MAINTAINER_CLEAN;
 }
 
 # Add output rules to invoke valac and create stamp file as a witness
@@ -6053,7 +6109,7 @@ sub resolve_linker
 {
     my (%linkers) = @_;
 
-    foreach my $l (qw(GCJLINK CXXLINK F77LINK FCLINK OBJCLINK UPCLINK))
+    foreach my $l (qw(GCJLINK OBJCXXLINK CXXLINK F77LINK FCLINK OBJCLINK UPCLINK))
     {
        return $l if defined $linkers{$l};
     }
@@ -6241,13 +6297,14 @@ sub make_conditional_string ($$)
 my %_am_macro_for_cond =
   (
   AMDEP => "one of the compiler tests\n"
-          . "    AC_PROG_CC, AC_PROG_CXX, AC_PROG_CXX, AC_PROG_OBJC,\n"
+          . "    AC_PROG_CC, AC_PROG_CXX, AC_PROG_OBJC, AC_PROG_OBJCXX,\n"
           . "    AM_PROG_AS, AM_PROG_GCJ, AM_PROG_UPC",
   am__fastdepCC => 'AC_PROG_CC',
   am__fastdepCCAS => 'AM_PROG_AS',
   am__fastdepCXX => 'AC_PROG_CXX',
   am__fastdepGCJ => 'AM_PROG_GCJ',
   am__fastdepOBJC => 'AC_PROG_OBJC',
+  am__fastdepOBJCXX => 'AC_PROG_OBJCXX',
   am__fastdepUPC => 'AM_PROG_UPC'
   );
 
@@ -6934,13 +6991,13 @@ sub transform ($$)
     }
 }
 
-
-# @PARAGRAPHS
-# &make_paragraphs ($MAKEFILE, [%TRANSFORM])
-# ------------------------------------------
-# Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
-# paragraphs.
-sub make_paragraphs ($%)
+# $TEXT
+# preprocess_file ($MAKEFILE, [%TRANSFORM])
+# -----------------------------------------
+# Load a $MAKEFILE, apply the %TRANSFORM, and return the result.
+# No extra parsing of post-processing is done (i.e., recognition of
+# rules declaration or of make variables definitions).
+sub preprocess_file ($%)
 {
   my ($file, %transform) = @_;
 
@@ -6973,13 +7030,9 @@ sub make_paragraphs ($%)
 
                 'LIBTOOL'      => !! var ('LIBTOOL'),
                 'NONLIBTOOL'   => 1,
-                'FIRST'        => ! $transformed_files{$file},
                %transform);
 
-  $transformed_files{$file} = 1;
-  $_ = $am_file_cache{$file};
-
-  if (! defined $_)
+  if (! defined ($_ = $am_file_cache{$file}))
     {
       verb "reading $file";
       # Swallow the whole file.
@@ -6989,11 +7042,10 @@ sub make_paragraphs ($%)
       $_ = $fc_file->getline;
       $/ = $saved_dollar_slash;
       $fc_file->close;
-
       # Remove ##-comments.
       # Besides we don't need more than two consecutive new-lines.
       s/(?:$IGNORE_PATTERN|(?<=\n\n)\n+)//gom;
-
+      # Remember the contents of the just-read file.
       $am_file_cache{$file} = $_;
     }
 
@@ -7007,8 +7059,22 @@ sub make_paragraphs ($%)
   # ####### and do not remove the latter.)
   s/^[ \t]*(?:##%)+.*\n//gm;
 
-  # Split at unescaped new lines.
-  my @lines = split (/(?<!\\)\n/, $_);
+  return $_;
+}
+
+
+# @PARAGRAPHS
+# &make_paragraphs ($MAKEFILE, [%TRANSFORM])
+# ------------------------------------------
+# Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of
+# paragraphs.
+sub make_paragraphs ($%)
+{
+  my ($file, %transform) = @_;
+  $transform{FIRST} = !$transformed_files{$file};
+  $transformed_files{$file} = 1;
+
+  my @lines = split /(?<!\\)\n/, preprocess_file ($file, %transform);
   my @res;
 
   while (defined ($_ = shift @lines))
@@ -8091,6 +8157,8 @@ sub generate_makefile ($$)
   handle_programs;
   handle_scripts;
 
+  handle_silent;
+
   # These must be run after all the sources are scanned.  They
   # use variables defined by &handle_libraries, &handle_ltlibraries,
   # or &handle_programs.
@@ -8302,7 +8370,7 @@ sub version ()
 {
   print <<EOF;
 automake (GNU $PACKAGE) $VERSION
-Copyright (C) 2011 Free Software Foundation, Inc.
+Copyright (C) $RELEASE_YEAR Free Software Foundation, Inc.
 License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.