verify: new macro 'assume'
[gnulib.git] / gnulib-tool
index 37073ed..ed693e0 100755 (executable)
@@ -1,6 +1,6 @@
 #! /bin/sh
 #
-# Copyright (C) 2002-2011 Free Software Foundation, Inc.
+# Copyright (C) 2002-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
@@ -186,6 +186,8 @@ Operation modes:
       --extract-maintainer         report the maintainer(s) inside gnulib
       --extract-tests-module       report the unit test module, if it exists
       --copy-file                  copy a file that is not part of any module
+      --help                Show this help text.
+      --version             Show version and authorship information.
 
 General options:
 
@@ -204,21 +206,35 @@ Options for --import, --add/remove-import, --update:
 
       --dry-run             Only print what would have been done.
 
+Options for --import, --add/remove-import:
+
+      --with-tests          Include unit tests for the included modules.
+
+Options for --create-[mega]testdir, --[mega]test:
+
+      --without-tests       Don't include unit tests for the included modules.
+
 Options for --import, --add/remove-import,
             --create-[mega]testdir, --[mega]test:
 
-      --with-tests          Include unit tests for the included modules.
       --with-obsolete       Include obsolete modules when they occur among the
                             dependencies. By default, dependencies to obsolete
                             modules are ignored.
       --with-c++-tests      Include even unit tests for C++ interoperability.
+      --without-c++-tests   Exclude unit tests for C++ interoperability.
       --with-longrunning-tests
                             Include even unit tests that are long-runners.
+      --without-longrunning-tests
+                            Exclude unit tests that are long-runners.
       --with-privileged-tests
                             Include even unit tests that require root
                             privileges.
+      --without-privileged-tests
+                            Exclude unit tests that require root privileges.
       --with-unportable-tests
                             Include even unit tests that fail on some platforms.
+      --without-unportable-tests
+                            Exclude unit tests that fail on some platforms.
       --with-all-tests      Include all kinds of problematic unit tests.
       --avoid=MODULE        Avoid including the given MODULE. Useful if you
                             have code that provides equivalent functionality.
@@ -264,17 +280,9 @@ Options for --import, --add/remove-import:
       --vc-files            Update version control related files.
       --no-vc-files         Don't update version control related files
                             (.gitignore and/or .cvsignore).
-      --no-changelog        Don't update or create ChangeLog files.
 
 Options for --create-[mega]testdir, --[mega]test:
 
-      --without-c++-tests   Exclude unit tests for C++ interoperability.
-      --without-longrunning-tests
-                            Exclude unit tests that are long-runners.
-      --without-privileged-tests
-                            Exclude unit tests that require root privileges.
-      --without-unportable-tests
-                            Exclude unit tests that fail on some platforms.
       --single-configure    Generate a single configure file, not a separate
                             configure file for the tests directory.
 
@@ -314,18 +322,8 @@ q
     date=`date -d "$date" -u +"%Y-%m-%d %H:%M:%S"`
     version=' '`cd "$gnulib_dir" && ./build-aux/git-version-gen /dev/null | sed -e 's/-dirty/-modified/'`
   else
-    if test -d "$gnulib_dir"/CVS \
-       && (cvs --version) >/dev/null 2>/dev/null; then
-      # gnulib checked out from CVS.
-      sed_extract_first_date='/^date: /{
-s/^date: \([0-9][0-9][0-9][0-9]\).\([0-9][0-9]\).\([0-9][0-9]\) \([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\).*/\1-\2-\3 \4/p
-q
-}'
-      date=`cd "$gnulib_dir" && cvs log -N ChangeLog 2>/dev/null | sed -n -e "$sed_extract_first_date"`
-    else
-      # gnulib copy without versioning information.
-      date=`sed -e 's/ .*//;q' "$gnulib_dir"/ChangeLog`
-    fi
+    # gnulib copy without versioning information.
+    date=`sed -e 's/ .*//;q' "$gnulib_dir"/ChangeLog`
     version=
   fi
   year=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed -e 's,^.* ,,'`
@@ -335,8 +333,8 @@ Copyright (C) $year Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.
-
-Written by" "Bruno Haible" "and" "Simon Josefsson"
+"
+  printf "Written by %s, %s, and %s.\n" "Bruno Haible" "Paul Eggert" "Simon Josefsson"
 }
 
 # func_emit_copyright_notice
@@ -348,10 +346,22 @@ func_emit_copyright_notice ()
                q
              }' < "$self_abspathname"
   echo "#"
-  echo "# This file is free software, distributed under the terms of the GNU"
-  echo "# General Public License.  As a special exception to the GNU General"
-  echo "# Public License, this file may be distributed as part of a program"
-  echo "# that contains a configuration script generated by Autoconf, under"
+  echo "# This file is free software; you can redistribute it and/or modify"
+  echo "# it under the terms of the GNU General Public License as published by"
+  echo "# the Free Software Foundation; either version 3 of the License, or"
+  echo "# (at your option) any later version."
+  echo "#"
+  echo "# This file is distributed in the hope that it will be useful,"
+  echo "# but WITHOUT ANY WARRANTY; without even the implied warranty of"
+  echo "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the"
+  echo "# GNU General Public License for more details."
+  echo "#"
+  echo "# You should have received a copy of the GNU General Public License"
+  echo "# along with this file.  If not, see <http://www.gnu.org/licenses/>."
+  echo "#"
+  echo "# As a special exception to the GNU General Public License,"
+  echo "# this file may be distributed as part of a program that"
+  echo "# contains a configuration script generated by Autoconf, under"
   echo "# the same distribution terms as the rest of that program."
   echo "#"
   echo "# Generated by gnulib-tool."
@@ -573,7 +583,7 @@ func_warning ()
 
 # func_readlink SYMLINK
 # outputs the target of the given symlink.
-if (type -p readlink) > /dev/null 2>&1; then
+if (type readlink) > /dev/null 2>&1; then
   func_readlink ()
   {
     # Use the readlink program from GNU coreutils.
@@ -890,8 +900,9 @@ fi
 
 # Command-line option processing.
 # Removes the OPTIONS from the arguments. Sets the variables:
-# - mode            list or import or add-import or remove-import or update
-#                   or create-testdir or create-megatestdir
+# - mode            one of: list, find, import, add-import, remove-import,
+#                   update, create-testdir, create-megatestdir, test, megatest,
+#                   copy-file
 # - destdir         from --dir
 # - local_gnulib_dir  from --local-dir
 # - modcache        true or false, from --cache-modules/--no-cache-modules
@@ -903,7 +914,8 @@ fi
 # - docbase         from --doc-base
 # - testsbase       from --tests-base
 # - auxdir          from --aux-dir
-# - inctests        true if --with-tests was given, blank otherwise
+# - inctests        true if --with-tests was given, false if --without-tests
+#                   was given, blank otherwise
 # - incobsolete     true if --with-obsolete was given, blank otherwise
 # - inc_cxx_tests   true if --with-c++-tests was given, blank otherwise
 # - inc_longrunning_tests  true if --with-longrunning-tests was given, blank
@@ -934,7 +946,6 @@ fi
 # - vc_files        true if --vc-files was given, false if --no-vc-files was
 #                   given, blank otherwise
 # - autoconf_minversion  minimum supported autoconf version
-# - do_changelog    false if --no-changelog was given, : otherwise
 # - doit            : if actions shall be executed, false if only to be printed
 # - symbolic        true if --symlink or --more-symlinks was given, blank
 #                   otherwise
@@ -975,7 +986,6 @@ fi
   po_domain=
   witness_c_macro=
   vc_files=
-  do_changelog=:
   doit=:
   symbolic=
   lsymbolic=
@@ -1146,6 +1156,9 @@ fi
       --with-all-tests | --with-all-test | --with-all-tes | --with-all-te | --with-all-t | --with-all- | --with-all | --with-al | --with-a)
         inc_all_tests=true
         shift ;;
+      --without-tests | --without-test | --without-tes | --without-te | --without-t)
+        inctests=false
+        shift ;;
       --without-c++-tests | --without-c++-test | --without-c++-tes | --without-c++-te | --without-c++-t | --without-c++- | --without-c++ | --without-c+ | --without-c)
         excl_cxx_tests=true
         shift ;;
@@ -1242,7 +1255,7 @@ fi
         vc_files=false
         shift ;;
       --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch )
-        do_changelog=false
+        # A no-op for backward compatibility.
         shift ;;
       --dry-run )
         doit=false
@@ -1285,19 +1298,6 @@ fi
       func_exit 1
     fi
   fi
-  # This code helps migrating from --import to --add-import or --update. It can
-  # be removed on 2012-01-01.
-  if test "$mode" = import && test $# = 0; then
-    echo "gnulib-tool: cowardly refusing to erase the module list." 1>&2
-    echo "The meaning of the option '--import' has changed." 1>&2
-    echo "See the documentation at" 1>&2
-    echo "<http://www.gnu.org/software/gnulib/manual/html_node/Modified-imports.html>." 1>&2
-    echo "For updating to a newer version of gnulib, use" 1>&2
-    echo "  gnulib-tool --add-import" 1>&2
-    echo "For restoring files that were omitted from version control, use" 1>&2
-    echo "  gnulib-tool --update" 1>&2
-    func_exit 1
-  fi
   if test "$mode" = update; then
     if test $# != 0; then
       echo "gnulib-tool: too many arguments in 'update' mode" 1>&2
@@ -1324,7 +1324,6 @@ fi
       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
       func_exit 1
     fi
-    do_changelog=false
   fi
   if test -n "$pobase" && test -z "$po_domain"; then
     echo "gnulib-tool: together with --po-base, you need to specify --po-domain" 1>&2
@@ -1334,7 +1333,22 @@ fi
   if test -z "$pobase" && test -n "$po_domain"; then
     func_warning "--po-domain has no effect without a --po-base option"
   fi
-  if test "$cond_dependencies" = true && test -n "$inctests"; then
+  # Canonicalize the inctests variable.
+  case "$mode" in
+    import | add-import | remove-import | update)
+      if test -z "$inctests"; then
+        inctests=false
+      fi
+      ;;
+    create-testdir | create-megatestdir | test | megatest)
+      if test -z "$inctests"; then
+        inctests=true
+      fi
+      ;;
+  esac
+  # Now the only possible values of "$inctests" are true and false
+  # (or blank but then it is irrelevant).
+  if test "$cond_dependencies" = true && test "$inctests" = true; then
     echo "gnulib-tool: option --conditional-dependencies is not supported with --with-tests" 1>&2
     func_exit 1
   fi
@@ -1480,8 +1494,7 @@ func_lookup_file ()
 # the resulting list to standard output, one per line.
 func_sanitize_modulelist ()
 {
-  sed -e '/^CVS\//d' -e '/\/CVS\//d' \
-      -e '/^ChangeLog$/d' -e '/\/ChangeLog$/d' \
+  sed -e '/^ChangeLog$/d' -e '/\/ChangeLog$/d' \
       -e '/^COPYING$/d' -e '/\/COPYING$/d' \
       -e '/^README$/d' -e '/\/README$/d' \
       -e '/^TEMPLATE$/d' \
@@ -1519,7 +1532,6 @@ func_exists_module ()
   { test -f "$gnulib_dir/modules/$1" \
     || { test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules" \
          && test -f "$local_gnulib_dir/modules/$1"; }; } \
-  && test "CVS" != "$1" \
   && test "ChangeLog" != "$1" \
   && test "COPYING" != "$1" \
   && test "README" != "$1" \
@@ -2363,31 +2375,50 @@ func_get_link_directive ()
   fi
 }
 
-# func_get_license module
+# func_get_license_raw module
 # Input:
 # - local_gnulib_dir  from --local-dir
 # - modcache          true or false, from --cache-modules/--no-cache-modules
-func_get_license ()
+func_get_license_raw ()
 {
-  {
-    if ! $modcache; then
-      func_lookup_file "modules/$1"
-      sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
+  if ! $modcache; then
+    func_lookup_file "modules/$1"
+    sed -n -e "/^License$sed_extract_prog" < "$lookedup_file"
+  else
+    func_cache_lookup_module "$1"
+    # Output the field's value, including the final newline (if any).
+    if $have_associative; then
+      if eval 'test -n "${modcache_license[$1]+set}"'; then
+        eval 'echo "${modcache_license[$1]}"'
+      fi
     else
-      func_cache_lookup_module "$1"
-      # Output the field's value, including the final newline (if any).
-      if $have_associative; then
-        if eval 'test -n "${modcache_license[$1]+set}"'; then
-          eval 'echo "${modcache_license[$1]}"'
-        fi
-      else
-        eval "field_set=\"\$${cachevar}_license_set\""
-        if test -n "$field_set"; then
-          eval "field_value=\"\$${cachevar}_license\""
-          echo "${field_value}"
-        fi
+      eval "field_set=\"\$${cachevar}_license_set\""
+      if test -n "$field_set"; then
+        eval "field_value=\"\$${cachevar}_license\""
+        echo "${field_value}"
       fi
     fi
+  fi
+}
+
+# func_get_license module
+# Input:
+# - local_gnulib_dir  from --local-dir
+# - modcache          true or false, from --cache-modules/--no-cache-modules
+func_get_license ()
+{
+  # Warn if the License field is missing.
+  case "$1" in
+    *-tests ) ;;
+    * )
+      license=`func_get_license_raw "$1"`
+      if test -z "$license"; then
+        func_warning "module $1 lacks a License"
+      fi
+      ;;
+  esac
+  {
+    func_get_license_raw "$1"
     # The default is GPL.
     echo "GPL"
   } | sed -e 's,^ *$,,' | sed -e 1q
@@ -2588,7 +2619,7 @@ sed_dependencies_without_conditions='s/ *\[.*//'
 # - local_gnulib_dir  from --local-dir
 # - modcache        true or false, from --cache-modules/--no-cache-modules
 # - modules         list of specified modules
-# - inctests        true if tests should be included, blank otherwise
+# - inctests        true if tests should be included, false otherwise
 # - incobsolete     true if obsolete modules among dependencies should be
 #                   included, blank otherwise
 # - inc_cxx_tests   true if C++ interoperability tests should be included,
@@ -2673,7 +2704,7 @@ func_modules_transitive_closure ()
           if test -n "$duplicated_deps"; then
             func_warning "module $module has duplicated dependencies: "`echo $duplicated_deps`
           fi
-          if test -n "$inctests"; then
+          if $inctests; then
             testsmodule=`func_get_tests_module $module`
             if test -n "$testsmodule"; then
               deps="$deps $testsmodule"
@@ -2718,7 +2749,7 @@ func_modules_transitive_closure ()
                   ;;
               esac
             done
-            if $inc; then
+            if $inc && func_acceptable "$dep"; then
               func_append inmodules " $dep"
               if test "$cond_dependencies" = true; then
                 escaped_dep=`echo "$dep" | sed -e "$sed_escape_dependency"`
@@ -2796,7 +2827,7 @@ func_show_module_list ()
 # - local_gnulib_dir  from --local-dir
 # - modcache        true or false, from --cache-modules/--no-cache-modules
 # - specified_modules  list of specified modules
-# - inctests        true if tests should be included, blank otherwise
+# - inctests        true if tests should be included, false otherwise
 # - incobsolete     true if obsolete modules among dependencies should be
 #                   included, blank otherwise
 # - inc_cxx_tests   true if C++ interoperability tests should be included,
@@ -2834,7 +2865,7 @@ func_modules_transitive_closure_separately ()
 {
   # Determine main module list.
   saved_inctests="$inctests"
-  inctests=""
+  inctests=false
   modules="$specified_modules"
   func_modules_transitive_closure
   main_modules="$modules"
@@ -3114,7 +3145,7 @@ func_add_file ()
          || { test -n "$lsymbolic" \
               && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
        && test -z "$lookedup_tmp" \
-       && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
+       && cmp -s "$lookedup_file" "$tmpfile"; then
       func_ln_if_changed "$lookedup_file" "$destdir/$g"
     else
       mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
@@ -3143,7 +3174,7 @@ func_add_file ()
 # - already_present  nonempty if the file should already exist, empty otherwise
 func_update_file ()
 {
-  if cmp "$destdir/$g" "$tmpfile" > /dev/null; then
+  if cmp -s "$destdir/$g" "$tmpfile"; then
     : # The file has not changed.
   else
     # Replace the file.
@@ -3158,7 +3189,7 @@ func_update_file ()
            || { test -n "$lsymbolic" \
                 && test "$lookedup_file" = "$local_gnulib_dir/$f"; }; } \
          && test -z "$lookedup_tmp" \
-         && cmp "$lookedup_file" "$tmpfile" > /dev/null; then
+         && cmp -s "$lookedup_file" "$tmpfile"; then
         func_ln_if_changed "$lookedup_file" "$destdir/$g"
       else
         mv -f "$tmpfile" "$destdir/${g}" || func_fatal_error "failed"
@@ -3303,7 +3334,7 @@ func_emit_lib_Makefile_am ()
     if test -n "$uses_subdirs"; then
       subdir_options=' subdir-objects'
     fi
-    echo "AUTOMAKE_OPTIONS = 1.5 gnits${subdir_options}"
+    echo "AUTOMAKE_OPTIONS = 1.9.6 gnits${subdir_options}"
   fi
   echo
   if test -z "$makefile_name"; then
@@ -3311,8 +3342,12 @@ func_emit_lib_Makefile_am ()
     echo "noinst_HEADERS ="
     echo "noinst_LIBRARIES ="
     echo "noinst_LTLIBRARIES ="
-    # Automake versions < 1.9b create an empty pkgdatadir at installation time
-    # if you specify pkgdata_DATA to empty. This is a workaround.
+    # Automake versions < 1.11.4 create an empty pkgdatadir at
+    # installation time if you specify pkgdata_DATA to empty.
+    # See automake bugs #10997 and #11030:
+    #  * http://debbugs.gnu.org/10997
+    #  * http://debbugs.gnu.org/11030
+    # So we need this workaround.
     if grep '^pkgdata_DATA *+=' "$tmp"/allsnippets > /dev/null; then
       echo "pkgdata_DATA ="
     fi
@@ -3341,20 +3376,25 @@ func_emit_lib_Makefile_am ()
       fi
     fi
   done
+  if test -n "$witness_c_macro"; then
+    cppflags_part1=" -D$witness_c_macro=1"
+  else
+    cppflags_part1=
+  fi
+  if $for_test; then
+    cppflags_part2=" -DGNULIB_STRICT_CHECKING=1"
+  else
+    cppflags_part2=
+  fi
   if test -z "$makefile_name"; then
     echo
-    if $for_test; then
-      cppflags_part1=" -DGNULIB_STRICT_CHECKING=1"
-    else
-      cppflags_part1=
-    fi
-    if test -n "$witness_c_macro"; then
-      cppflags_part2=" -D$witness_c_macro=1"
-    else
-      cppflags_part2=
-    fi
     echo "AM_CPPFLAGS =$cppflags_part1$cppflags_part2"
     echo "AM_CFLAGS ="
+  else
+    if test -n "$cppflags_part1$cppflags_part2"; then
+      echo
+      echo "AM_CPPFLAGS +=$cppflags_part1$cppflags_part2"
+    fi
   fi
   echo
   if LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" "$tmp"/allsnippets > /dev/null \
@@ -3520,9 +3560,11 @@ func_emit_tests_Makefile_am ()
   witness_macro="$1"
   if test "$libtool" = true; then
     libext=la
+    perhapsLT=LT
     sed_eliminate_LDFLAGS="$sed_noop"
   else
     libext=a
+    perhapsLT=
     sed_eliminate_LDFLAGS='/^lib_LDFLAGS[       ]*+=/d'
   fi
   if $for_test; then
@@ -3601,7 +3643,7 @@ func_emit_tests_Makefile_am ()
   if test -n "$uses_subdirs"; then
     subdir_options=' subdir-objects'
   fi
-  echo "AUTOMAKE_OPTIONS = 1.5 foreign${subdir_options}"
+  echo "AUTOMAKE_OPTIONS = 1.9.6 foreign${subdir_options}"
   echo
   if $for_test && ! $single_configure; then
     echo "ACLOCAL_AMFLAGS = -I ${testsbase_inverse}/${m4base}"
@@ -3627,8 +3669,12 @@ func_emit_tests_Makefile_am ()
       echo "check_LIBRARIES = libtests.a"
     fi
   fi
-  # Automake versions < 1.9b create an empty pkgdatadir at installation time
-  # if you specify pkgdata_DATA to empty. This is a workaround.
+  # Automake versions < 1.11.4 create an empty pkgdatadir at
+  # installation time if you specify pkgdata_DATA to empty.
+  # See automake bugs #10997 and #11030:
+  #  * http://debbugs.gnu.org/10997
+  #  * http://debbugs.gnu.org/11030
+  # So we need this workaround.
   if grep '^pkgdata_DATA *+=' "$tmp"/main_snippets "$tmp"/longrunning_snippets > /dev/null; then
     echo "pkgdata_DATA ="
   fi
@@ -3832,9 +3878,12 @@ func_emit_initmacro_done ()
 # func_emit_autoconf_snippet indentation
 # emits the autoconf snippet of a module.
 # Input:
+# - indentation       spaces to prepend on each line
 # - local_gnulib_dir  from --local-dir
 # - modcache          true or false, from --cache-modules/--no-cache-modules
 # - sed_replace_build_aux  sed expression that replaces reference to build-aux
+# - sed_replace_include_guard_prefix
+#                     sed expression for resolving ${gl_include_guard_prefix}
 # - module            the module name
 # - toplevel          true or false. 'false' means a subordinate use of
 #                     gnulib-tool.
@@ -3843,9 +3892,9 @@ func_emit_initmacro_done ()
 #                     command line options.
 # - disable_gettext   true or false. It tells whether to disable AM_GNU_GETTEXT
 #                     invocations.
-# - indentation       spaces to prepend on each line
 func_emit_autoconf_snippet ()
 {
+  indentation="$1"
   if { case $module in
          gnumakefile | maintainer-makefile)
            # These modules are meant to be used only in the top-level directory.
@@ -3857,6 +3906,7 @@ func_emit_autoconf_snippet ()
     func_get_autoconf_snippet "$module" \
       | sed -e '/^$/d;' -e "s/^/$indentation/" \
             -e "$sed_replace_build_aux" \
+            -e "$sed_replace_include_guard_prefix" \
       | { if $disable_libtool; then
             sed -e 's/\$gl_cond_libtool/false/g' \
                 -e 's/gl_libdeps/gltests_libdeps/g' \
@@ -3868,7 +3918,9 @@ func_emit_autoconf_snippet ()
       | { if $disable_gettext; then
             sed -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./'
           else
-            cat
+            # Don't indent AM_GNU_GETTEXT_VERSION line, as that confuses
+            # autopoint through at least GNU gettext version 0.18.2.
+            sed -e 's/^ *AM_GNU_GETTEXT_VERSION/AM_GNU_GETTEXT_VERSION/'
           fi
         }
     if test "$module" = 'alloca' && test "$libtool" = true && ! $disable_libtool; then
@@ -3886,6 +3938,8 @@ func_emit_autoconf_snippet ()
 # - local_gnulib_dir  from --local-dir
 # - modcache          true or false, from --cache-modules/--no-cache-modules
 # - sed_replace_build_aux  sed expression that replaces reference to build-aux
+# - sed_replace_include_guard_prefix
+#                     sed expression for resolving ${gl_include_guard_prefix}
 # - modules           the list of modules.
 # - verifier          one of func_verify_module, func_verify_nontests_module,
 #                     func_verify_tests_module. It selects the subset of
@@ -3904,6 +3958,7 @@ func_emit_autoconf_snippets ()
   disable_libtool="$4"
   disable_gettext="$5"
   if test "$cond_dependencies" = true; then
+    for m in $modules; do echo $m; done | LC_ALL=C sort -u > "$tmp"/modules
     # Emit the autoconf code for the unconditional modules.
     for module in $1; do
       eval $verifier
@@ -3940,12 +3995,14 @@ func_emit_autoconf_snippets ()
           func_emit_autoconf_snippet "      "
           echo "      $shellvar=true"
           deps=`func_get_dependencies $module | sed -e "$sed_dependencies_without_conditions"`
+          # Intersect $deps with the modules list $1.
+          deps=`for m in $deps; do echo $m; done | LC_ALL=C sort -u | LC_ALL=C join - "$tmp"/modules`
           for dep in $deps; do
             if func_cond_module_p "$dep"; then
               func_module_shellfunc_name "$dep"
               func_cond_module_condition "$module" "$dep"
               if test "$condition" != true; then
-                echo '      if $condition; then'
+                echo "      if $condition; then"
                 echo "        $shellfunc"
                 echo '      fi'
               else
@@ -3970,6 +4027,8 @@ func_emit_autoconf_snippets ()
           :
         else
           deps=`func_get_dependencies $module | sed -e "$sed_dependencies_without_conditions"`
+          # Intersect $deps with the modules list $1.
+          deps=`for m in $deps; do echo $m; done | LC_ALL=C sort -u | LC_ALL=C join - "$tmp"/modules`
           for dep in $deps; do
             if func_cond_module_p "$dep"; then
               func_module_shellfunc_name "$dep"
@@ -4028,7 +4087,7 @@ func_emit_autoconf_snippets ()
 # - docbase         directory relative to destdir where to place doc files
 # - testsbase       directory relative to destdir where to place unit test code
 # - auxdir          directory relative to destdir where to place build aux files
-# - inctests        true if --with-tests was given, blank otherwise
+# - inctests        true if --with-tests was given, false otherwise
 # - incobsolete     true if --with-obsolete was given, blank otherwise
 # - inc_cxx_tests   true if --with-c++-tests was given, blank otherwise
 # - inc_longrunning_tests  true if --with-longrunning-tests was given, blank
@@ -4322,8 +4381,11 @@ func_import ()
       fi
     fi
     # Require the tests if specified either way.
-    if test -z "$inctests"; then
+    if ! $inctests; then
       inctests="$cached_inctests"
+      if test -z "$inctests"; then
+        inctests=false
+      fi
     fi
     # The libname defaults to the cached one.
     if test -z "$supplied_libname"; then
@@ -4372,7 +4434,7 @@ func_import ()
       vc_files="$cached_vc_files"
     fi
     # Ensure constraints.
-    if test "$cond_dependencies" = true && test -n "$inctests"; then
+    if test "$cond_dependencies" = true && $inctests; then
       echo "gnulib-tool: option --conditional-dependencies is not supported with --with-tests" 1>&2
       func_exit 1
     fi
@@ -4569,7 +4631,7 @@ s,^\(.................................................[^ ]*\) *,
     if test -n "$docfiles"; then
       echo "$docbase"
     fi
-    if test -n "$inctests"; then
+    if $inctests; then
       echo "$testsbase"
     fi
     echo "$auxdir"
@@ -4718,7 +4780,7 @@ s,^\(.................................................[^ ]*\) *,
   func_append actioncmd " --doc-base=$docbase"
   func_append actioncmd " --tests-base=$testsbase"
   func_append actioncmd " --aux-dir=$auxdir"
-  if test -n "$inctests"; then
+  if $inctests; then
     func_append actioncmd " --with-tests"
   fi
   if test -n "$incobsolete"; then
@@ -4815,7 +4877,7 @@ s,^\(.................................................[^ ]*\) *,
     pobase_base=`basename "$pobase"`
     func_note_Makefile_am_edit "$pobase_dir" SUBDIRS "$pobase_base"
   fi
-  if test -n "$inctests"; then
+  if $inctests; then
     if test "$makefile_am" = Makefile.am; then
       testsbase_dir=`echo "$testsbase" | sed -n -e 's,/[^/]*$,/,p'`
       testsbase_base=`basename "$testsbase"`
@@ -4834,7 +4896,7 @@ s,//*$,/,'
           && ! { test -f "${destdir}/${dir1}Makefile.am" \
                  || test "${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
                  || test "./${dir1}Makefile.am" = "$sourcebase/$makefile_am" \
-                 || { test -n "$inctests" \
+                 || { $inctests \
                       && { test "${dir1}Makefile.am" = "$testsbase/$makefile_am" \
                            || test "./${dir1}Makefile.am" = "$testsbase/$makefile_am"; }; }; }; do
       dir2=`echo "$dir1" | sed -e "$sed_last"`"$dir2"
@@ -4849,7 +4911,7 @@ s,//*$,/,'
   modules="$main_modules"
   func_emit_lib_Makefile_am > "$tmpfile"
   if test -f "$destdir"/$sourcebase/$makefile_am; then
-    if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
+    if cmp -s "$destdir"/$sourcebase/$makefile_am "$tmpfile"; then
       rm -f "$tmpfile"
     else
       if $doit; then
@@ -4880,7 +4942,7 @@ s,//*$,/,'
       func_lookup_file build-aux/po/$file
       cat "$lookedup_file" > "$tmpfile"
       if test -f "$destdir"/$pobase/$file; then
-        if cmp "$destdir"/$pobase/$file "$tmpfile" > /dev/null; then
+        if cmp -s "$destdir"/$pobase/$file "$tmpfile"; then
           rm -f "$tmpfile"
         else
           if $doit; then
@@ -4907,7 +4969,7 @@ s,//*$,/,'
     func_dest_tmpfilename $pobase/Makevars
     func_emit_po_Makevars > "$tmpfile"
     if test -f "$destdir"/$pobase/Makevars; then
-      if cmp "$destdir"/$pobase/Makevars "$tmpfile" > /dev/null; then
+      if cmp -s "$destdir"/$pobase/Makevars "$tmpfile"; then
         rm -f "$tmpfile"
       else
         if $doit; then
@@ -4933,7 +4995,7 @@ s,//*$,/,'
     func_dest_tmpfilename $pobase/POTFILES.in
     func_emit_po_POTFILES_in > "$tmpfile"
     if test -f "$destdir"/$pobase/POTFILES.in; then
-      if cmp "$destdir"/$pobase/POTFILES.in "$tmpfile" > /dev/null; then
+      if cmp -s "$destdir"/$pobase/POTFILES.in "$tmpfile"; then
         rm -f "$tmpfile"
       else
         if $doit; then
@@ -4982,7 +5044,7 @@ s,//*$,/,'
           }
       ) > "$tmpfile"
       if test -f "$destdir"/$pobase/LINGUAS; then
-        if cmp "$destdir"/$pobase/LINGUAS "$tmpfile" > /dev/null; then
+        if cmp -s "$destdir"/$pobase/LINGUAS "$tmpfile"; then
           rm -f "$tmpfile"
         else
           echo "Updating $pobase/LINGUAS (backup in $pobase/LINGUAS~)"
@@ -5047,7 +5109,9 @@ s,//*$,/,'
     echo "gl_PO_BASE([$pobase])"
     echo "gl_DOC_BASE([$docbase])"
     echo "gl_TESTS_BASE([$testsbase])"
-    test -z "$inctests" || echo "gl_WITH_TESTS"
+    if $inctests; then
+      echo "gl_WITH_TESTS"
+    fi
     echo "gl_LIB([$libname])"
     if test -n "$lgpl"; then
       if test "$lgpl" = yes; then
@@ -5065,13 +5129,13 @@ s,//*$,/,'
     fi
     echo "gl_MACRO_PREFIX([$macro_prefix])"
     echo "gl_PO_DOMAIN([$po_domain])"
-    echo "gl_WITNESS_C_DOMAIN([$witness_c_macro])"
+    echo "gl_WITNESS_C_MACRO([$witness_c_macro])"
     if test -n "$vc_files"; then
       echo "gl_VC_FILES([$vc_files])"
     fi
   ) > "$tmpfile"
   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
-    if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
+    if cmp -s "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile"; then
       rm -f "$tmpfile"
     else
       if $doit; then
@@ -5121,7 +5185,7 @@ s,//*$,/,'
     echo "  m4_pattern_allow([^gl_ES\$])dnl a valid locale name"
     echo "  m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
     echo "  m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
-    echo "  AC_REQUIRE([AC_PROG_RANLIB])"
+    echo "  AC_REQUIRE([gl_PROG_AR_RANLIB])"
     if test -n "$uses_subdirs"; then
       echo "  AC_REQUIRE([AM_PROG_CC_C_O])"
     fi
@@ -5210,7 +5274,7 @@ s,//*$,/,'
     echo "])"
   ) > "$tmpfile"
   if test -f "$destdir"/$m4base/gnulib-comp.m4; then
-    if cmp "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile" > /dev/null; then
+    if cmp -s "$destdir"/$m4base/gnulib-comp.m4 "$tmpfile"; then
       rm -f "$tmpfile"
     else
       if $doit; then
@@ -5238,14 +5302,14 @@ s,//*$,/,'
     fi
   fi
 
-  if test -n "$inctests"; then
+  if $inctests; then
     # Create tests makefile.
     func_dest_tmpfilename $testsbase/$makefile_am
     destfile="$testsbase/$makefile_am"
     modules="$testsrelated_modules"
     func_emit_tests_Makefile_am "${macro_prefix}tests_WITNESS" > "$tmpfile"
     if test -f "$destdir"/$testsbase/$makefile_am; then
-      if cmp "$destdir"/$testsbase/$makefile_am "$tmpfile" > /dev/null; then
+      if cmp -s "$destdir"/$testsbase/$makefile_am "$tmpfile"; then
         rm -f "$tmpfile"
       else
         if $doit; then
@@ -5265,7 +5329,7 @@ s,//*$,/,'
         echo "Create $testsbase/$makefile_am"
         rm -f "$tmpfile"
       fi
-    func_append added_files "$testsbase/$makefile_am$nl"
+      func_append added_files "$testsbase/$makefile_am$nl"
     fi
   fi
 
@@ -5299,7 +5363,7 @@ s,//*$,/,'
             (echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
                | LC_ALL=C join -v 1 - "$tmp"/ignore > "$tmp"/ignore-added
              echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
-               | LC_ALL=C join -v 1 - "$tmp"/ignore > "$tmp"/ignore-removed
+               > "$tmp"/ignore-removed
             )
             if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
               if $doit; then
@@ -5426,7 +5490,7 @@ s,//*$,/,'
   if test -n "$pobase"; then
     echo "  - add \"$pobase/Makefile.in\" to AC_CONFIG_FILES in $configure_ac,"
   fi
-  if test -n "$inctests"; then
+  if $inctests; then
     if test "$makefile_am" = Makefile.am; then
       echo "  - add \"$testsbase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
     else
@@ -5443,7 +5507,16 @@ s,//*$,/,'
       echo "  - mention \"${val}\" in ${var} in ${dir}Makefile.am,"
     fi
   done
-  echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after AC_PROG_CC,"
+  if grep '^ *AC_PROG_CC_STDC' "$configure_ac" > /dev/null; then
+    position_early_after=AC_PROG_CC_STDC
+  else
+    if grep '^ *AC_PROG_CC_C99' "$configure_ac" > /dev/null; then
+      position_early_after=AC_PROG_CC_C99
+    else
+      position_early_after=AC_PROG_CC
+    fi
+  fi
+  echo "  - invoke ${macro_prefix}_EARLY in $configure_ac, right after $position_early_after,"
   echo "  - invoke ${macro_prefix}_INIT in $configure_ac."
 }
 
@@ -5452,7 +5525,7 @@ s,//*$,/,'
 # - local_gnulib_dir  from --local-dir
 # - modcache        true or false, from --cache-modules/--no-cache-modules
 # - auxdir          directory relative to destdir where to place build aux files
-# - inctests        true if tests should be included, blank otherwise
+# - inctests        true if tests should be included, false otherwise
 # - incobsolete     true if obsolete modules among dependencies should be
 #                   included, blank otherwise
 # - excl_cxx_tests   true if C++ interoperability tests should be excluded,
@@ -5499,9 +5572,9 @@ func_create_testdir ()
   # its dependencies.
   saved_inctests="$inctests"
   # When computing transitive closures, don't consider $module to depend on
-  # $module-tests. Need this becauses tests are implicitly GPL and may depend
+  # $module-tests. Need this because tests are implicitly GPL and may depend
   # on GPL modules - therefore we don't want a warning in this case.
-  inctests=""
+  inctests=false
   for requested_module in $specified_modules; do
     requested_license=`func_get_license "$requested_module"`
     if test "$requested_license" != GPL; then
@@ -5703,7 +5776,7 @@ func_create_testdir ()
     func_append subdirs " po"
   fi
 
-  if test -n "$inctests"; then
+  if $inctests; then
     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
     if $single_configure; then
       # Create $testsbase/Makefile.am.
@@ -5730,7 +5803,7 @@ func_create_testdir ()
        echo "AC_PROG_CC"
        echo "AC_PROG_INSTALL"
        echo "AC_PROG_MAKE_SET"
-       echo "AC_PROG_RANLIB"
+       echo "gl_PROG_AR_RANLIB"
        echo
        if test -n "$uses_subdirs"; then
          echo "AM_PROG_CC_C_O"
@@ -5815,7 +5888,7 @@ func_create_testdir ()
   # Create Makefile.am.
   (echo "## Process this file with automake to produce Makefile.in."
    echo
-   echo "AUTOMAKE_OPTIONS = 1.5 foreign"
+   echo "AUTOMAKE_OPTIONS = 1.9.6 foreign"
    echo
    echo "SUBDIRS = $subdirs"
    echo
@@ -5845,7 +5918,7 @@ func_create_testdir ()
    echo "m4_pattern_allow([^gl_LIBOBJS\$])dnl a variable"
    echo "m4_pattern_allow([^gl_LTLIBOBJS\$])dnl a variable"
    echo
-   echo "AC_PROG_RANLIB"
+   echo "gl_PROG_AR_RANLIB"
    echo
    if test -n "$any_uses_subdirs"; then
      echo "AM_PROG_CC_C_O"
@@ -5976,7 +6049,7 @@ func_create_testdir ()
    func_execute_command ${AUTOHEADER} || func_exit 1
    func_execute_command ${AUTOMAKE} --add-missing --copy || func_exit 1
   ) || func_exit 1
-  if test -n "$inctests" && ! $single_configure; then
+  if $inctests && ! $single_configure; then
     # Create autogenerated files.
     (cd "$testdir/$testsbase" || func_exit 1
      # Do not use "${AUTORECONF} --force --install", because it may invoke
@@ -6017,7 +6090,7 @@ func_create_testdir ()
                                esac;
                              done`
   tests_distributed_built_sources=
-  if test -n "$inctests"; then
+  if $inctests; then
     # Likewise for built files in the $testsbase directory.
     tests_cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$testsbase/Makefile.am" \
                          | sed -n -e 's,^CLEANFILES[    ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
@@ -6084,11 +6157,7 @@ func_create_megatestdir ()
   func_append megasubdirs "ALL"
 
   # Create autobuild.
-  cvsdate=`if test -f "$gnulib_dir/CVS/Entries"; then \
-             vc_witness="$gnulib_dir/CVS/Entries"; \
-           else \
-             vc_witness="$gnulib_dir/.git/refs/heads/master"; \
-           fi; \
+  cvsdate=`vc_witness="$gnulib_dir/.git/refs/heads/master"; \
            sh "$gnulib_dir/build-aux/mdate-sh" "$vc_witness" \
              | sed -e 's,January,01,'   -e 's,Jan,01,' \
                    -e 's,February,02,'  -e 's,Feb,02,' \
@@ -6128,7 +6197,7 @@ func_create_megatestdir ()
   # Create Makefile.am.
   (echo "## Process this file with automake to produce Makefile.in."
    echo
-   echo "AUTOMAKE_OPTIONS = 1.5 foreign"
+   echo "AUTOMAKE_OPTIONS = 1.9.6 foreign"
    echo
    echo "SUBDIRS = $megasubdirs"
    echo
@@ -6481,6 +6550,9 @@ s/\([.*$]\)/[\1]/g'
     ;;
 
   extract-dependencies )
+    if test -n "$avoidlist"; then
+      func_fatal_error "cannot combine --avoid and --extract-dependencies"
+    fi
     for module
     do
       func_verify_module