lang, suffix rules: don't require C stuff needlessly
[platform/upstream/automake.git] / automake.in
index 48ece7f..835d3bd 100644 (file)
@@ -6,7 +6,7 @@ eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
     if 0;
 
 # automake - create Makefile.in from Makefile.am
-# Copyright (C) 1994-2012 Free Software Foundation, Inc.
+# Copyright (C) 1994-2013 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -29,8 +29,9 @@ package Language;
 
 BEGIN
 {
-  my $perllibdir = $ENV{'perllibdir'} || '@datadir@/@PACKAGE@-@APIVERSION@';
-  unshift @INC, (split '@PATH_SEPARATOR@', $perllibdir);
+  @Automake::perl_libdirs = ('@datadir@/@PACKAGE@-@APIVERSION@')
+    unless @Automake::perl_libdirs;
+  unshift @INC, @Automake::perl_libdirs;
 
   # Override SHELL.  This is required on DJGPP so that system() uses
   # bash, not COMMAND.COM which doesn't quote arguments properly.
@@ -231,7 +232,7 @@ my @common_files =
     (qw(ABOUT-GNU ABOUT-NLS AUTHORS BACKLOG COPYING COPYING.DOC COPYING.LIB
        COPYING.LESSER ChangeLog INSTALL NEWS README THANKS TODO
        ar-lib compile config.guess config.rpath
-       config.sub depcomp elisp-comp install-sh libversion.in mdate-sh
+       config.sub depcomp install-sh libversion.in mdate-sh
        missing mkinstalldirs py-compile texinfo.tex ylwrap),
      @libtool_files, @libtool_sometimes);
 
@@ -317,7 +318,7 @@ my $configure_ac;
 # Files found by scanning configure.ac for LIBOBJS.
 my %libsources = ();
 
-# Names used in AC_CONFIG_HEADER call.
+# Names used in AC_CONFIG_HEADERS call.
 my @config_headers = ();
 
 # Names used in AC_CONFIG_LINKS call.
@@ -333,8 +334,8 @@ my @configure_input_files = ();
 # List of files in AC_CONFIG_FILES/AC_OUTPUT without Makefile.am's,
 # and their outputs.
 my @other_input_files = ();
-# Where each AC_CONFIG_FILES/AC_OUTPUT/AC_CONFIG_LINK/AC_CONFIG_HEADER appears.
-# The keys are the files created by these macros.
+# Where each AC_CONFIG_FILES/AC_OUTPUT/AC_CONFIG_LINK/AC_CONFIG_HEADERS
+# appears.  The keys are the files created by these macros.
 my %ac_config_files_location = ();
 # The condition under which AC_CONFIG_FOOS appears.
 my %ac_config_files_condition = ();
@@ -373,8 +374,6 @@ my $libtool_new_api = 0;
 
 # Most important AC_CANONICAL_* macro seen so far.
 my $seen_canonical = 0;
-# Location of that macro.
-my $canonical_location;
 
 # Where AM_MAINTAINER_MODE appears.
 my $seen_maint_mode;
@@ -483,17 +482,9 @@ my $am_file = 'BUG';
 ## Variables reset by &initialize_per_input.  ##
 ## ------------------------------------------ ##
 
-# Basename and relative dir of the input file.
-my $am_file_name;
-my $am_relative_dir;
-
-# Same but wrt Makefile.in.
-my $in_file_name;
+# Relative dir of the output makefile.
 my $relative_dir;
 
-# Relative path to the top directory.
-my $topsrcdir;
-
 # Greatest timestamp of the output's dependencies (excluding
 # configure's dependencies).
 my $output_deps_greatest_timestamp;
@@ -642,12 +633,7 @@ sub initialize_per_input ()
 {
     reset_local_duplicates ();
 
-    $am_file_name = undef;
-    $am_relative_dir = undef;
-
-    $in_file_name = undef;
     $relative_dir = undef;
-    $topsrcdir = undef;
 
     $output_deps_greatest_timestamp = 0;
 
@@ -1586,10 +1572,11 @@ sub handle_languages
     # If the project is entirely C++ or entirely Fortran 77 (i.e., 1
     # suffix rule was learned), don't bother with the C stuff.  But if
     # anything else creeps in, then use it.
-    $needs_c = 1
-      if $need_link || suffix_rules_count > 1;
-
-    if ($needs_c)
+    my @languages_seen = map { $languages{$extension_map{$_}}->name }
+                             (keys %extension_seen);
+    @languages_seen = uniq (@languages_seen);
+    $needs_c = 1 if @languages_seen > 1;
+    if ($need_link || $needs_c)
       {
        &define_compiler_variable ($languages{'c'})
          unless defined $done{$languages{'c'}};
@@ -1755,6 +1742,7 @@ sub handle_single_transform ($$$$$%)
            # generates another source file which we must then process
            # further.
            my $subr = \&{'lang_' . $lang->name . '_rewrite'};
+           defined &$subr or $subr = \&lang_sub_obj;
            my ($r, $source_extension)
                = &$subr ($directory, $base, $extension,
                          $obj, $have_per_exec_flags, $var);
@@ -2144,6 +2132,7 @@ sub handle_source_transform ($$$$%)
        msg_var ('unsupported', $ext_var, $ext_var->name . " can assume at most one value")
          if $default_source_ext =~ /[\t ]/;
        (my $default_source = $unxformed) =~ s,(\.[^./\\]*)?$,$default_source_ext,;
+       # TODO: Remove this backward-compatibility hack in Automake 2.0.
        if ($old_default_source ne $default_source
            && !$ext_var
            && (rule $old_default_source
@@ -2302,8 +2291,10 @@ sub handle_LIBOBJS_or_ALLOCA ($)
          # we are already there, and since the targets are built without
          # a $(top_builddir), it helps BSD Make to match them with
          # dependencies.
-         $dir = "$config_libobj_dir/" if $config_libobj_dir ne '.';
-         $dir = "$topsrcdir/$dir" if $relative_dir ne '.';
+         $dir = "$config_libobj_dir/"
+           if $config_libobj_dir ne '.';
+         $dir = backname ($relative_dir) . "/$dir"
+           if $relative_dir ne '.';
          define_variable ('LIBOBJDIR', "$dir", INTERNAL);
          $clean_files{"\$($var)"} = MOSTLY_CLEAN;
          # If LTLIBOBJS is used, we must also clear LIBOBJS (which might
@@ -2547,8 +2538,8 @@ sub handle_programs
       my($xlink, $vlink) = &define_per_target_linker_variable ($linker, $xname);
       $vlink = verbose_flag ($vlink || 'GEN');
 
-      # If the resulting program lies into a subdirectory,
-      # make sure this directory will exist.
+      # If the resulting program lies in a subdirectory,
+      # ensure that the directory exists before we need it.
       my $dirstamp = require_build_directory_maybe ($one_file);
 
       $libtool_clean_directories{dirname ($one_file)} = 1;
@@ -2658,7 +2649,7 @@ sub handle_libraries
       &handle_source_transform ($xlib, $onelib, $obj, $where,
                                NONLIBTOOL => 1, LIBTOOL => 0);
 
-      # If the resulting library lies into a subdirectory,
+      # If the resulting library lies in a subdirectory,
       # make sure this directory will exist.
       my $dirstamp = require_build_directory_maybe ($onelib);
       my $verbose = verbose_flag ('AR');
@@ -2902,7 +2893,7 @@ sub handle_ltlibraries
            }
        }
 
-      # If the resulting library lies into a subdirectory,
+      # If the resulting library lies in a subdirectory,
       # make sure this directory will exist.
       my $dirstamp = require_build_directory_maybe ($onelib);
 
@@ -3003,7 +2994,12 @@ sub scan_texinfo_file ($)
          next if $outfile;
 
          $outfile = $1;
-         if ($outfile =~ /\.([^.]+)$/ && $1 ne 'info')
+         if (index ($outfile, '.') < 0)
+           {
+             msg 'obsolete', "$filename:$.",
+                 "use of suffix-less info files is discouraged"
+           }
+         elsif ($outfile !~ /\.info$/)
            {
              error ("$filename:$.",
                     "output '$outfile' has unrecognized extension");
@@ -3024,8 +3020,6 @@ sub scan_texinfo_file ($)
       return;
     }
 
-  my $infobase = basename ($filename);
-  $infobase =~ s/\.te?xi(nfo)?$//;
   return ($outfile, $vfile);
 }
 
@@ -3094,7 +3088,7 @@ sub output_texinfo_build_rules ($$$@)
   # extension).
   my $generic_info = ($generic && $dsfx) ? 1 : 0;
 
-  # If the resulting file lie into a subdirectory,
+  # If the resulting file lies in a subdirectory,
   # make sure this directory will exist.
   my $dirstamp = require_build_directory_maybe ($dest);
 
@@ -3153,9 +3147,17 @@ sub handle_texinfo_helper ($)
       ($info_texinfos->value_as_list_recursive (inner_expand => 1))
     {
       my $infobase = $texi;
-      $infobase =~ s/\.(txi|texinfo|texi)$//;
-
-      if ($infobase eq $texi)
+      if ($infobase =~ s/\.texi$//)
+        {
+          1; # Nothing more to do.
+        }
+      elsif ($infobase =~ s/\.(txi|texinfo)$//)
+        {
+         msg_var 'obsolete', $info_texinfos,
+                 "suffix '.$1' for Texinfo files is discouraged;" .
+                  " use '.texi' instead";
+        }
+      else
        {
          # FIXME: report line number.
          err_am "texinfo file '$texi' has unrecognized extension";
@@ -3713,7 +3715,7 @@ sub handle_dist ()
     {
       my $archive_defined = option 'no-dist-gzip' ? 0 : 1;
       $archive_defined ||=
-       grep { option "dist-$_" } qw(shar zip tarZ bzip2 lzip lzma xz);
+       grep { option "dist-$_" } qw(shar zip tarZ bzip2 lzip xz);
       error (option 'no-dist-gzip',
             "no-dist-gzip specified but no dist-* specified,\n"
             . "at least one archive format must be enabled")
@@ -3781,12 +3783,6 @@ sub handle_dist ()
   # to set it.
   $handle_dist_run = 1;
 
-  # Scan EXTRA_DIST to see if we need to distribute anything from a
-  # subdir.  If so, add it to the list.  I didn't want to do this
-  # originally, but there were so many requests that I finally
-  # relented.
-  my $extra_dist = var ('EXTRA_DIST');
-
   $transform{'DISTCHECK-HOOK'} = !! rule 'distcheck-hook';
   $transform{'GETTEXT'} = $seen_gettext && !$seen_gettext_external;
 
@@ -4132,6 +4128,7 @@ sub handle_configure ($$$@)
            file_contents ('remake-hdr',
                           new Automake::Location,
                           FILES            => "@files",
+                          'FIRST-HDR'      => ($hdr_index == 1),
                           CONFIG_H         => $cn_sans_dir,
                           CONFIG_HIN       => $ins[0],
                           CONFIG_H_DEPS    => "@ins",
@@ -4150,6 +4147,9 @@ sub handle_configure ($$$@)
   # Distribute and define mkinstalldirs only if it is already present
   # in the package, for backward compatibility (some people may still
   # use $(mkinstalldirs)).
+  # TODO: start warning about this in Automake 1.14, and have
+  # TODO: Automake 2.0 drop it (and the mkinstalldirs script
+  # TODO: as well).
   my $mkidpath = "$config_aux_dir/mkinstalldirs";
   if (-f $mkidpath)
     {
@@ -4955,8 +4955,6 @@ sub handle_emacs_lisp
 
   require_variables ($elfiles[0][0], "Emacs Lisp sources seen", TRUE,
                     'EMACS', 'lispdir');
-  require_conf_file ($elfiles[0][0], FOREIGN, 'elisp-comp');
-  &define_variable ('elisp_comp', "$am_config_aux_dir/elisp-comp", INTERNAL);
 }
 
 # Handle Python
@@ -5097,7 +5095,7 @@ sub scan_autoconf_config_files ($$)
       # Handle $local:$input syntax.
       my ($local, @rest) = split (/:/);
       @rest = ("$local.in",) unless @rest;
-      # Keep in sync with 'conffile-leading-dot.test'.
+      # Keep in sync with test 'conffile-leading-dot.sh'.
       msg ('unsupported', $where,
            "omit leading './' from config file names such as '$local';"
            . "\nremake rules might be subtly broken otherwise")
@@ -5147,8 +5145,9 @@ sub scan_autoconf_traces ($)
                AC_REQUIRE_AUX_FILE => 1,
                AC_SUBST_TRACE => 1,
                AM_AUTOMAKE_VERSION => 1,
+                AM_PROG_MKDIR_P => 0,
                AM_CONDITIONAL => 2,
-               _AM_EXTRA_RECURSIVE_TARGETS => 1,
+               AM_EXTRA_RECURSIVE_TARGETS => 1,
                AM_GNU_GETTEXT => 0,
                AM_GNU_GETTEXT_INTL_SUBDIR => 0,
                AM_INIT_AUTOMAKE => 0,
@@ -5203,7 +5202,6 @@ sub scan_autoconf_traces ($)
          if ($seen_canonical <= AC_CANONICAL_BUILD)
            {
              $seen_canonical = AC_CANONICAL_BUILD;
-             $canonical_location = $where;
            }
        }
       elsif ($macro eq 'AC_CANONICAL_HOST')
@@ -5211,13 +5209,11 @@ sub scan_autoconf_traces ($)
          if ($seen_canonical <= AC_CANONICAL_HOST)
            {
              $seen_canonical = AC_CANONICAL_HOST;
-             $canonical_location = $where;
            }
        }
       elsif ($macro eq 'AC_CANONICAL_TARGET')
        {
          $seen_canonical = AC_CANONICAL_TARGET;
-         $canonical_location = $where;
        }
       elsif ($macro eq 'AC_CONFIG_AUX_DIR')
        {
@@ -5305,13 +5301,24 @@ sub scan_autoconf_traces ($)
 
          $seen_automake_version = 1;
        }
+      elsif ($macro eq 'AM_PROG_MKDIR_P')
+       {
+         msg 'obsolete', $where, <<'EOF';
+The 'AM_PROG_MKDIR_P' macro is deprecated, and its use is discouraged.
+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;
        }
-      elsif ($macro eq '_AM_EXTRA_RECURSIVE_TARGETS')
+      elsif ($macro eq 'AM_EXTRA_RECURSIVE_TARGETS')
        {
-         push @extra_recursive_targets, split (' ', $args[1]);
+          # Empty leading/trailing fields might be produced by split,
+          # hence the grep is really needed.
+          push @extra_recursive_targets,
+               grep (/./, (split /\s+/, $args[1]));
        }
       elsif ($macro eq 'AM_GNU_GETTEXT')
        {
@@ -5330,7 +5337,7 @@ sub scan_autoconf_traces ($)
            {
               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
+http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
 EOF
              $package_version = $args[2];
              $package_version_location = $where;
@@ -5613,12 +5620,6 @@ sub lang_c_rewrite
     return $r;
 }
 
-# Rewrite a single C++ source file.
-sub lang_cxx_rewrite
-{
-    return &lang_sub_obj;
-}
-
 # Rewrite a single header file.
 sub lang_header_rewrite
 {
@@ -5635,7 +5636,7 @@ sub lang_vala_rewrite
     return (LANG_SUBDIR, $newext);
 }
 
-# Rewrite a single yacc file.
+# Rewrite a single yacc/yacc++ file.
 sub lang_yacc_rewrite
 {
     my ($directory, $base, $ext) = @_;
@@ -5644,18 +5645,9 @@ sub lang_yacc_rewrite
     (my $newext = $ext) =~ tr/y/c/;
     return ($r, $newext);
 }
+sub lang_yaccxx_rewrite { lang_yacc_rewrite (@_); };
 
-# Rewrite a single yacc++ file.
-sub lang_yaccxx_rewrite
-{
-    my ($directory, $base, $ext) = @_;
-
-    my $r = &lang_sub_obj;
-    (my $newext = $ext) =~ tr/y/c/;
-    return ($r, $newext);
-}
-
-# Rewrite a single lex file.
+# Rewrite a single lex/lex++ file.
 sub lang_lex_rewrite
 {
     my ($directory, $base, $ext) = @_;
@@ -5664,76 +5656,7 @@ sub lang_lex_rewrite
     (my $newext = $ext) =~ tr/l/c/;
     return ($r, $newext);
 }
-
-# Rewrite a single lex++ file.
-sub lang_lexxx_rewrite
-{
-    my ($directory, $base, $ext) = @_;
-
-    my $r = &lang_sub_obj;
-    (my $newext = $ext) =~ tr/l/c/;
-    return ($r, $newext);
-}
-
-# Rewrite a single assembly file.
-sub lang_asm_rewrite
-{
-    return &lang_sub_obj;
-}
-
-# Rewrite a single preprocessed assembly file.
-sub lang_cppasm_rewrite
-{
-    return &lang_sub_obj;
-}
-
-# Rewrite a single Fortran 77 file.
-sub lang_f77_rewrite
-{
-    return &lang_sub_obj;
-}
-
-# Rewrite a single Fortran file.
-sub lang_fc_rewrite
-{
-    return &lang_sub_obj;
-}
-
-# Rewrite a single preprocessed Fortran file.
-sub lang_ppfc_rewrite
-{
-    return &lang_sub_obj;
-}
-
-# Rewrite a single preprocessed Fortran 77 file.
-sub lang_ppf77_rewrite
-{
-    return &lang_sub_obj;
-}
-
-# Rewrite a single ratfor file.
-sub lang_ratfor_rewrite
-{
-    return &lang_sub_obj;
-}
-
-# Rewrite a single Objective C file.
-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
-{
-    return &lang_sub_obj;
-}
+sub lang_lexxx_rewrite { lang_lex_rewrite (@_); };
 
 # Rewrite a single Java file.
 sub lang_java_rewrite
@@ -6050,7 +5973,7 @@ sub register_language (%)
   # Update the pattern of known extensions.
   accept_extensions (@{$lang->extensions});
 
-  # Upate the $suffix_rule map.
+  # Update the suffix rules map.
   foreach my $suffix (@{$lang->extensions})
     {
       foreach my $dest (&{$lang->output_extensions} ($suffix))
@@ -6068,12 +5991,11 @@ sub derive_suffix ($$)
 {
   my ($source_ext, $obj) = @_;
 
-  while (! $extension_map{$source_ext}
-        && $source_ext ne $obj
-        && exists $suffix_rules->{$source_ext}
-        && exists $suffix_rules->{$source_ext}{$obj})
+  while (!$extension_map{$source_ext} && $source_ext ne $obj)
     {
-      $source_ext = $suffix_rules->{$source_ext}{$obj}[0];
+      my $new_source_ext = next_in_suffix_chain ($source_ext, $obj);
+      last if not defined $new_source_ext;
+      $source_ext = $new_source_ext;
     }
 
   return $source_ext;
@@ -6640,7 +6562,7 @@ sub read_am_file ($$)
                # otherwise OSF make will implicitly copy the included
                # file in the build tree during "make distdir" to satisfy
                # the dependency.
-               # (subdircond2.test and subdircond3.test will fail.)
+               # (subdir-am-cond.sh and subdir-ac-cond.sh will fail)
                push_dist_common ("\$\(top_srcdir\)/$path");
              }
            else
@@ -6651,7 +6573,7 @@ sub read_am_file ($$)
                # otherwise OSF make will implicitly copy the included
                # file in the build tree during "make distdir" to satisfy
                # the dependency.
-               # (subdircond2.test and subdircond3.test will fail.)
+               # (subdir-am-cond.sh and subdir-ac-cond.sh will fail)
                push_dist_common ("\$\(srcdir\)/$path");
                $path = $relative_dir . "/" . $path if $relative_dir ne '.';
              }
@@ -6709,9 +6631,9 @@ sub define_standard_variables
 }
 
 # Read main am file.
-sub read_main_am_file
+sub read_main_am_file ($$)
 {
-    my ($amfile) = @_;
+    my ($amfile, $infile) = @_;
 
     # This supports the strange variable tricks we are about to play.
     prog_error ("variable defined before read_main_am_file\n" . variables_dump ())
@@ -6719,8 +6641,8 @@ sub read_main_am_file
 
     # Generate copyright header for generated Makefile.in.
     # We do discard the output of predefined variables, handled below.
-    $output_vars = ("# $in_file_name generated by automake "
-                  . $VERSION . " from $am_file_name.\n");
+    $output_vars = ("# " . basename ($infile) . " generated by automake "
+                  . $VERSION . " from " . basename ($amfile) . ".\n");
     $output_vars .= '# ' . subst ('configure_input') . "\n";
     $output_vars .= $gen_copyright;
 
@@ -6817,7 +6739,6 @@ sub preprocess_file ($%)
                 => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '',
 
                 'XZ'          => !! option 'dist-xz',
-                'LZMA'        => !! option 'dist-lzma',
                 'LZIP'        => !! option 'dist-lzip',
                 'BZIP2'       => !! option 'dist-bzip2',
                 'COMPRESS'    => !! option 'dist-tarZ',
@@ -6827,7 +6748,6 @@ sub preprocess_file ($%)
 
                 'INSTALL-INFO' =>  ! option 'no-installinfo',
                 'INSTALL-MAN'  =>  ! option 'no-installman',
-                'HAVE-MANS'    => !! var ('MANS'),
                 'CK-NEWS'      => !! option 'check-news',
 
                 'SUBDIRS'      => !! var ('SUBDIRS'),
@@ -7489,7 +7409,7 @@ sub push_required_file
     }
   # This is needed to allow a construct in a non-top-level Makefile.am
   # to require a file in the build-aux directory (see at least the test
-  # script 'test-driver-is-distributed.test').  This is related to the
+  # script 'test-driver-is-distributed.sh').  This is related to the
   # automake bug#9546.  Note that the use of $config_aux_dir instead
   # of $am_config_aux_dir here is deliberate and necessary.
   elsif ($dir eq $config_aux_dir)
@@ -7899,11 +7819,6 @@ sub generate_makefile ($$)
   # we have processed AUTOMAKE_OPTIONS.
   buffer_messages ('warning');
 
-  # Name of input file ("Makefile.am") and output file
-  # ("Makefile.in").  These have no directory components.
-  $am_file_name = basename ($makefile_am);
-  $in_file_name = basename ($makefile_in);
-
   # $OUTPUT is encoded.  If it contains a ":" then the first element
   # is the real output file, and all remaining elements are input
   # files.  We don't scan or otherwise deal with these input files,
@@ -7912,10 +7827,8 @@ sub generate_makefile ($$)
   my ($makefile, @inputs) = split (/:/, $output_files{$makefile_in});
 
   $relative_dir = dirname ($makefile);
-  $am_relative_dir = dirname ($makefile_am);
-  $topsrcdir = backname ($relative_dir);
 
-  read_main_am_file ($makefile_am);
+  read_main_am_file ($makefile_am, $makefile_in);
   if (handle_options)
     {
       # Process buffered warnings.
@@ -8027,6 +7940,7 @@ sub generate_makefile ($$)
       return;
     }
 
+  my $am_relative_dir = dirname ($makefile_am);
   mkdir ($am_relative_dir, 0755) if ! -d $am_relative_dir;
 
   # We make sure that 'all:' is the first target.