autoupdate
[gnulib.git] / gnulib-tool
index 56f5616..ce1bbe9 100755 (executable)
@@ -1,6 +1,6 @@
 #! /bin/sh
 #
-# Copyright (C) 2002-2009 Free Software Foundation, Inc.
+# Copyright (C) 2002-2010 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
@@ -115,6 +115,7 @@ Usage: gnulib-tool --list
        gnulib-tool --extract-description module
        gnulib-tool --extract-status module
        gnulib-tool --extract-notice module
+       gnulib-tool --extract-applicability module
        gnulib-tool --extract-filelist module
        gnulib-tool --extract-dependencies module
        gnulib-tool --extract-autoconf-snippet module
@@ -252,7 +253,7 @@ q
     fi
     version=
   fi
-  year=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed 's,^.* ,,'`
+  year=`"$gnulib_dir"/build-aux/mdate-sh "$self_abspathname" | sed -e 's,^.* ,,'`
   echo "\
 gnulib-tool (GNU $package $date)$version
 Copyright (C) $year Free Software Foundation, Inc.
@@ -267,10 +268,10 @@ Written by" "Bruno Haible" "and" "Simon Josefsson"
 # outputs to stdout a header for a generated file.
 func_emit_copyright_notice ()
 {
-  sed -n '/Copyright/ {
-            p
-            q
-          }' < "$self_abspathname"
+  sed -n -e '/Copyright/ {
+               p
+               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"
@@ -703,7 +704,7 @@ if test -z "$have_echo" \
    && test "X$1" != "X--no-reexec" \
    && test -n "$CONFIG_SHELL" \
    && test -f "$CONFIG_SHELL" \
-   && $CONFIG_SHELL -c 'echo '\t' | grep t > /dev/null'; then
+   && $CONFIG_SHELL -c "echo '\\t' | grep t > /dev/null"; then
   exec $CONFIG_SHELL "$0" --no-reexec "$@"
   exit 127
 fi
@@ -1177,7 +1178,7 @@ fi
     if test -n "$prereqs"; then
       autoconf_minversion=`
         for version in $prereqs; do echo $version; done |
-        LC_ALL=C sort -nru | sed 1q
+        LC_ALL=C sort -nru | sed -e 1q
       `
     fi
   fi
@@ -1347,6 +1348,7 @@ sed_extract_prog=':[       ]*$/ {
     s/^Description:[    ]*$//
     s/^Status:[         ]*$//
     s/^Notice:[         ]*$//
+    s/^Applicability:[  ]*$//
     s/^Files:[  ]*$//
     s/^Depends-on:[     ]*$//
     s/^configure\.ac-early:[    ]*$//
@@ -1389,6 +1391,22 @@ func_get_notice ()
   sed -n -e "/^Notice$sed_extract_prog" < "$lookedup_file"
 }
 
+# func_get_applicability module
+# Input:
+# - local_gnulib_dir  from --local-dir
+# The expected result (on stdout) is either 'main', or 'tests', or 'all'.
+func_get_applicability ()
+{
+  func_lookup_file "modules/$1"
+  { sed -n -e "/^Applicability$sed_extract_prog" < "$lookedup_file"
+    # The default is 'main' or 'tests', depending on the module's name.
+    case "$1" in
+      *-tests) echo "tests";;
+      *)       echo "main";;
+    esac
+  } | sed -e 's,^ *$,,' | sed -e 1q
+}
+
 # func_get_filelist module
 # Input:
 # - local_gnulib_dir  from --local-dir
@@ -1410,6 +1428,7 @@ func_get_filelist ()
 # elements starting with prefix and ending with suffix are considered.
 # Processing: removed_prefix and removed_suffix are removed from each element,
 # added_prefix and added_suffix are added to each element.
+# prefix, suffix should not contain shell-special characters.
 # removed_prefix, removed_suffix should not contain the characters "$`\{}[]^|.
 # added_prefix, added_suffix should not contain the characters \|&.
 func_filter_filelist ()
@@ -1421,8 +1440,10 @@ func_filter_filelist ()
         }; then
     ffflist=
     for fff in $3; do
+      # Do not quote possibly-empty parameters in case patterns,
+      # AIX and HP-UX ksh won't match them if they are empty.
       case "$fff" in
-        "$4"*"$5")
+        $4*$5)
           if test -n "$6"; then
             func_remove_prefix fff "$6"
           fi
@@ -1442,7 +1463,7 @@ func_filter_filelist ()
     sed_fff_filter="s|^$6\(.*\)$7\$|$8\\1$9|"
     ffflist=`for fff in $3; do
                case "$fff" in
-                 "$4"*"$5") echo "$fff" ;;
+                 $4*$5) echo "$fff" ;;
                esac
              done | sed -e "$sed_fff_filter"`
   fi
@@ -1953,7 +1974,14 @@ func_emit_lib_Makefile_am ()
   echo "## Process this file with automake to produce Makefile.in."
   func_emit_copyright_notice
   if test -n "$actioncmd"; then
-    echo "# Reproduce by: $actioncmd"
+    # The maximum line length (excluding the terminating newline) of any file
+    # that is to be preprocessed by config.status is 3070.  config.status uses
+    # awk, and the HP-UX 11.00 awk fails if a line has length >= 3071;
+    # similarly, the IRIX 6.5 awk fails if a line has length >= 3072.
+    len=`echo "$actioncmd" | wc -c`
+    if test -n "$len" && test "$len" -le 3000; then
+      echo "# Reproduce by: $actioncmd"
+    fi
   fi
   echo
   uses_subdirs=
@@ -1974,16 +2002,16 @@ func_emit_lib_Makefile_am ()
             echo "${libname}_${libext}_LIBADD += @${perhapsLT}ALLOCA@"
             echo "${libname}_${libext}_DEPENDENCIES += @${perhapsLT}ALLOCA@"
           fi
-        } > amsnippet.tmp
+        } > "$tmp"/amsnippet
         # Skip the contents if it's entirely empty.
-        if grep '[^     ]' amsnippet.tmp > /dev/null ; then
+        if grep '[^     ]' "$tmp"/amsnippet > /dev/null ; then
           echo "## begin gnulib module $module"
           echo
-          cat amsnippet.tmp
+          cat "$tmp"/amsnippet
           echo "## end   gnulib module $module"
           echo
         fi
-        rm -f amsnippet.tmp
+        rm -f "$tmp"/amsnippet
         # Test whether there are some source files in subdirectories.
         for f in `func_get_filelist "$module"`; do
           case $f in
@@ -1995,7 +2023,7 @@ func_emit_lib_Makefile_am ()
         done
       fi
     done
-  } > allsnippets.tmp
+  } > "$tmp"/allsnippets
   if test -z "$makefile_name"; then
     # If there are source files in subdirectories, prevent collision of the
     # object files (example: hash.c and libxml/hash.c).
@@ -2013,7 +2041,7 @@ func_emit_lib_Makefile_am ()
     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.
-    if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
+    if grep '^pkgdata_DATA *+=' "$tmp"/allsnippets > /dev/null; then
       echo "pkgdata_DATA ="
     fi
     echo "EXTRA_DIST ="
@@ -2047,7 +2075,7 @@ func_emit_lib_Makefile_am ()
     echo "AM_CFLAGS ="
   fi
   echo
-  if LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" allsnippets.tmp > /dev/null \
+  if LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" "$tmp"/allsnippets > /dev/null \
      || { test -n "$makefile_name" \
           && test -f "$sourcebase/Makefile.am" \
           && LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" "$sourcebase/Makefile.am" > /dev/null; \
@@ -2075,7 +2103,7 @@ func_emit_lib_Makefile_am ()
     echo "AM_CPPFLAGS += -DDEFAULT_TEXT_DOMAIN=\\\"${po_domain}-gnulib\\\""
     echo
   fi
-  cat allsnippets.tmp \
+  cat "$tmp"/allsnippets \
     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
   echo
   echo "mostlyclean-local: mostlyclean-generic"
@@ -2085,7 +2113,7 @@ func_emit_lib_Makefile_am ()
   echo "         fi; \\"
   echo "       done; \\"
   echo "       :"
-  rm -f allsnippets.tmp
+  rm -f "$tmp"/allsnippets
 }
 
 # func_emit_po_Makevars
@@ -2209,7 +2237,7 @@ func_emit_tests_Makefile_am ()
   func_emit_copyright_notice
   echo
   uses_subdirs=
-  (
+  {
     for module in $modules; do
       if $for_test; then
         func_verify_tests_module
@@ -2230,16 +2258,16 @@ func_emit_tests_Makefile_am ()
             echo "libtests_a_LIBADD += @${perhapsLT}ALLOCA@"
             echo "libtests_a_DEPENDENCIES += @${perhapsLT}ALLOCA@"
           fi
-        } > amsnippet.tmp
+        } > "$tmp"/amsnippet
         # Skip the contents if it's entirely empty.
-        if grep '[^     ]' amsnippet.tmp > /dev/null ; then
+        if grep '[^     ]' "$tmp"/amsnippet > /dev/null ; then
           echo "## begin gnulib module $module"
           echo
-          cat amsnippet.tmp
+          cat "$tmp"/amsnippet
           echo "## end   gnulib module $module"
           echo
         fi
-        rm -f amsnippet.tmp
+        rm -f "$tmp"/amsnippet
         # Test whether there are some source files in subdirectories.
         for f in `func_get_filelist "$module"`; do
           case $f in
@@ -2251,7 +2279,7 @@ func_emit_tests_Makefile_am ()
         done
       fi
     done
-  ) > allsnippets.tmp
+  } > "$tmp"/allsnippets
   # Generate dependencies here, since it eases the debugging of test failures.
   # If there are source files in subdirectories, prevent collision of the
   # object files (example: hash.c and libxml/hash.c).
@@ -2270,6 +2298,7 @@ func_emit_tests_Makefile_am ()
   #   "AM_GNU_GETTEXT used but SUBDIRS not defined"
   echo "SUBDIRS ="
   echo "TESTS ="
+  echo "XFAIL_TESTS ="
   echo "TESTS_ENVIRONMENT ="
   echo "noinst_PROGRAMS ="
   if ! $for_test; then
@@ -2286,7 +2315,7 @@ func_emit_tests_Makefile_am ()
   fi
   # Automake versions < 1.9b create an empty pkgdatadir at installation time
   # if you specify pkgdata_DATA to empty. This is a workaround.
-  if grep '^pkgdata_DATA *+=' allsnippets.tmp > /dev/null; then
+  if grep '^pkgdata_DATA *+=' "$tmp"/allsnippets > /dev/null; then
     echo "pkgdata_DATA ="
   fi
   echo "EXTRA_DIST ="
@@ -2344,7 +2373,7 @@ func_emit_tests_Makefile_am ()
     echo "AM_LIBTOOLFLAGS = --preserve-dup-deps"
     echo
   fi
-  cat allsnippets.tmp \
+  cat "$tmp"/allsnippets \
     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
   echo "# Clean up after Solaris cc."
   echo "clean-local:"
@@ -2357,7 +2386,7 @@ func_emit_tests_Makefile_am ()
   echo "         fi; \\"
   echo "       done; \\"
   echo "       :"
-  rm -f allsnippets.tmp
+  rm -f "$tmp"/allsnippets
 }
 
 # func_emit_initmacro_start macro_prefix
@@ -2425,7 +2454,7 @@ func_emit_initmacro_end ()
   echo "    if test -n \"\$${macro_prefix_arg}_LIBOBJS\"; then"
   echo "      # Remove the extension."
   echo "      sed_drop_objext='s/\\.o\$//;s/\\.obj\$//'"
-  echo "      for i in \`for i in \$${macro_prefix_arg}_LIBOBJS; do echo \"\$i\"; done | sed \"\$sed_drop_objext\" | sort | uniq\`; do"
+  echo "      for i in \`for i in \$${macro_prefix_arg}_LIBOBJS; do echo \"\$i\"; done | sed -e \"\$sed_drop_objext\" | sort | uniq\`; do"
   echo "        ${macro_prefix_arg}_libobjs=\"\$${macro_prefix_arg}_libobjs \$i.\$ac_objext\""
   echo "        ${macro_prefix_arg}_ltlibobjs=\"\$${macro_prefix_arg}_ltlibobjs \$i.lo\""
   echo "      done"
@@ -2736,9 +2765,10 @@ func_import ()
   # ignoring tests modules. Its lib/* sources go into $sourcebase/. If --lgpl
   # is specified, it will consist only of LGPLed source.
   # The tests-related module list is the transitive closure of the specified
-  # modules, including tests modules, minus the main module list. Its lib/*
-  # sources (brought in through dependencies of *-tests modules) go into
-  # $testsbase/. It may contain GPLed source, even if --lgpl is specified.
+  # modules, including tests modules, minus the main module list excluding
+  # modules of applicability 'all'. Its lib/* sources (brought in through
+  # dependencies of *-tests modules) go into $testsbase/. It may contain GPLed
+  # source, even if --lgpl is specified.
   # Determine main module list.
   saved_inctests="$inctests"
   inctests=""
@@ -2752,7 +2782,13 @@ func_import ()
   fi
   # Determine tests-related module list.
   echo "$final_modules" | LC_ALL=C sort -u > "$tmp"/final-modules
-  testsrelated_modules=`func_reset_sigpipe; echo "$main_modules" | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/final-modules`
+  testsrelated_modules=`func_reset_sigpipe
+                        for module in $main_modules; do
+                          if test \`func_get_applicability $module\` = main; then
+                            echo $module
+                          fi
+                        done \
+                        | LC_ALL=C sort -u | LC_ALL=C join -v 2 - "$tmp"/final-modules`
   if test $verbose -ge 1; then
     echo "Tests-related module list:"
     echo "$testsrelated_modules" | sed -e 's/^/  /'
@@ -2800,7 +2836,7 @@ func_import ()
           case "$lgpl" in
             yes | 3)
               case $license in
-                LGPL | LGPLv2+) ;;
+                LGPL | LGPLv2+ | LGPLv3+) ;;
                 *) func_append license_incompatibilities "$module $license$nl" ;;
               esac
               ;;
@@ -2862,11 +2898,22 @@ s,^\(.................................................[^ ]*\) *,
       sed_transform_main_lib_file=$sed_transform_main_lib_file'
         s/GNU Lesser General/GNU General/g
         s/GNU Library General/GNU General/g
-        s/version \(2\|2\.1\)\([ ,]\)/version 3\2/g
+        s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
       '
     fi
   fi
 
+  # Determine script to apply to auxiliary files that go into $auxdir/.
+  sed_transform_build_aux_file=
+  if test -n "$do_copyrights"; then
+    # Update license.
+    sed_transform_build_aux_file=$sed_transform_build_aux_file'
+      s/GNU Lesser General/GNU General/g
+      s/GNU Library General/GNU General/g
+      s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
+    '
+  fi
+
   # Determine script to apply to library files that go into $testsbase/.
   sed_transform_testsrelated_lib_file="$sed_transform_lib_file"
   if test -n "$do_copyrights"; then
@@ -2874,7 +2921,7 @@ s,^\(.................................................[^ ]*\) *,
     sed_transform_testsrelated_lib_file=$sed_transform_testsrelated_lib_file'
       s/GNU Lesser General/GNU General/g
       s/GNU Library General/GNU General/g
-      s/version \(2\|2\.1\)\([ ,]\)/version 3\2/g
+      s/version 2\(.1\)\{0,1\}\([ ,]\)/version 3\2/g
     '
   fi
 
@@ -2910,22 +2957,25 @@ s,^\(.................................................[^ ]*\) *,
     func_append old_files " m4/gnulib-tool.m4"
   fi
 
+  rewritten='%REWRITTEN%'
   sed_rewrite_old_files="\
-    s,^build-aux/,$auxdir/,
-    s,^doc/,$cached_docbase/,
-    s,^lib/,$cached_sourcebase/,
-    s,^m4/,$cached_m4base/,
-    s,^tests/,$cached_testsbase/,
-    s,^tests=lib/,$cached_testsbase/,
-    s,^top/,,"
+    s,^build-aux/,$rewritten$auxdir/,
+    s,^doc/,$rewritten$cached_docbase/,
+    s,^lib/,$rewritten$cached_sourcebase/,
+    s,^m4/,$rewritten$cached_m4base/,
+    s,^tests/,$rewritten$cached_testsbase/,
+    s,^tests=lib/,$rewritten$cached_testsbase/,
+    s,^top/,$rewritten,
+    s,^$rewritten,,"
   sed_rewrite_new_files="\
-    s,^build-aux/,$auxdir/,
-    s,^doc/,$docbase/,
-    s,^lib/,$sourcebase/,
-    s,^m4/,$m4base/,
-    s,^tests/,$testsbase/,
-    s,^tests=lib/,$testsbase/,
-    s,^top/,,"
+    s,^build-aux/,$rewritten$auxdir/,
+    s,^doc/,$rewritten$docbase/,
+    s,^lib/,$rewritten$sourcebase/,
+    s,^m4/,$rewritten$m4base/,
+    s,^tests/,$rewritten$testsbase/,
+    s,^tests=lib/,$rewritten$testsbase/,
+    s,^top/,$rewritten,
+    s,^$rewritten,,"
 
   # Create directories.
   { echo "$sourcebase"
@@ -3015,6 +3065,14 @@ s,^\(.................................................[^ ]*\) *,
           ;;
       esac
     fi
+    if test -n "$sed_transform_build_aux_file"; then
+      case "$of" in
+        build-aux/*)
+          sed -e "$sed_transform_build_aux_file" \
+            < "$lookedup_file" > "$tmpfile" || func_fatal_error "failed"
+          ;;
+      esac
+    fi
     if test -n "$sed_transform_testsrelated_lib_file"; then
       case "$of" in
         tests=lib/*)
@@ -3367,7 +3425,7 @@ s,//*$,/,'
     esac
     echo "gl_LOCAL_DIR([$relative_local_gnulib_dir])"
     echo "gl_MODULES(["
-    echo "$specified_modules" | sed 's/^/  /g'
+    echo "$specified_modules" | sed -e 's/^/  /g'
     echo "])"
     test -z "$incobsolete" || echo "gl_WITH_OBSOLETE"
     echo "gl_AVOID([$avoidlist])"
@@ -3492,7 +3550,7 @@ s,//*$,/,'
                 -e "$sed_replace_build_aux"
         if test "$module" = 'alloca' && test "$libtool" = true; then
           echo 'changequote(,)dnl'
-          echo 'LTALLOCA=`echo "$ALLOCA" | sed '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
+          echo 'LTALLOCA=`echo "$ALLOCA" | sed -e '"'"'s/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'"'"'`'
           echo 'changequote([, ])dnl'
           echo 'AC_SUBST([LTALLOCA])'
         fi
@@ -3789,10 +3847,9 @@ func_create_testdir ()
   if test -z "$modules"; then
     # All modules together.
     # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
-    # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
     # Except ftruncate, mountlist, which abort the configuration on mingw. FIXME.
     modules=`func_all_modules`
-    modules=`for m in $modules; do case $m in config-h | fnmatch-posix | ftruncate | mountlist) ;; *) echo $m;; esac; done`
+    modules=`for m in $modules; do case $m in config-h | ftruncate | mountlist) ;; *) echo $m;; esac; done`
   fi
   modules=`for m in $modules; do echo $m; done | LC_ALL=C sort -u`
 
@@ -3877,13 +3934,15 @@ func_create_testdir ()
     echo "$files" | sed -e 's/^/  /'
   fi
 
+  rewritten='%REWRITTEN%'
   sed_rewrite_files="\
-    s,^build-aux/,$auxdir/,
-    s,^doc/,$docbase/,
-    s,^lib/,$sourcebase/,
-    s,^m4/,$m4base/,
-    s,^tests/,$testsbase/,
-    s,^top/,,"
+    s,^build-aux/,$rewritten$auxdir/,
+    s,^doc/,$rewritten$docbase/,
+    s,^lib/,$rewritten$sourcebase/,
+    s,^m4/,$rewritten$m4base/,
+    s,^tests/,$rewritten$testsbase/,
+    s,^top/,$rewritten,
+    s,^$rewritten,,"
 
   # Create directories.
   for f in $files; do echo $f; done \
@@ -3968,7 +4027,7 @@ func_create_testdir ()
     test -d "$testdir/$testsbase" || mkdir "$testdir/$testsbase"
     # Viewed from the $testsbase subdirectory, $auxdir is different.
     saved_auxdir="$auxdir"
-    auxdir=`echo "$testsbase/"|sed 's%[^/][^/]*//*%../%g'`"$auxdir"
+    auxdir=`echo "$testsbase/" | sed -e 's%[^/][^/]*//*%../%g'`"$auxdir"
     # Create $testsbase/Makefile.am.
     use_libtests=false
     destfile="$testsbase/Makefile.am"
@@ -3980,13 +4039,17 @@ func_create_testdir ()
      echo "AC_CONFIG_AUX_DIR([$auxdir])"
      echo "AM_INIT_AUTOMAKE"
      echo
-     echo "AM_CONFIG_HEADER([config.h])"
+     echo "AC_CONFIG_HEADERS([config.h])"
      echo
      echo "AC_PROG_CC"
      echo "AC_PROG_INSTALL"
      echo "AC_PROG_MAKE_SET"
      echo "AC_PROG_RANLIB"
      echo
+     if test -n "$uses_subdirs"; then
+       echo "AM_PROG_CC_C_O"
+       echo
+     fi
      for module in $modules; do
        func_verify_module
        if test -n "$module"; then
@@ -4070,7 +4133,8 @@ func_create_testdir ()
      # by "merging" config.h into $testsbase/config.h; look out for gcc warnings.
      echo "AH_TOP([#include \"../config.h\"])"
      echo
-     echo "AC_OUTPUT([Makefile])"
+     echo "AC_CONFIG_FILES([Makefile])"
+     echo "AC_OUTPUT"
     ) > "$testdir/$testsbase/configure.ac"
     auxdir="$saved_auxdir"
     func_append subdirs " $testsbase"
@@ -4095,7 +4159,7 @@ func_create_testdir ()
    fi
    echo "AM_INIT_AUTOMAKE"
    echo
-   echo "AM_CONFIG_HEADER([config.h])"
+   echo "AC_CONFIG_HEADERS([config.h])"
    echo
    echo "AC_PROG_CC"
    echo "AC_PROG_INSTALL"
@@ -4186,7 +4250,8 @@ func_create_testdir ()
        *) func_append makefiles " $d/Makefile" ;;
      esac
    done
-   echo "AC_OUTPUT([$makefiles])"
+   echo "AC_CONFIG_FILES([$makefiles])"
+   echo "AC_OUTPUT"
   ) > "$testdir/configure.ac"
 
   # Create autogenerated files.
@@ -4281,8 +4346,7 @@ func_create_megatestdir ()
   done
   # Then, all modules all together.
   # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
-  # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
-  allmodules=`for m in $allmodules; do if test $m != config-h && test $m != fnmatch-posix; then echo $m; fi; done`
+  allmodules=`for m in $allmodules; do if test $m != config-h; then echo $m; fi; done`
   func_create_testdir "$megatestdir/ALL" "$allmodules"
   func_append megasubdirs "ALL"
 
@@ -4349,7 +4413,8 @@ func_create_megatestdir ()
    echo "AC_PROG_MAKE_SET"
    echo
    echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
-   echo "AC_OUTPUT([Makefile])"
+   echo "AC_CONFIG_FILES([Makefile])"
+   echo "AC_OUTPUT"
   ) > "$megatestdir/configure.ac"
 
   # Create autogenerated files.
@@ -4388,7 +4453,7 @@ case $mode in
       if test -f "$destdir"/configure.in; then
         configure_ac="$destdir/configure.in"
       else
-        func_fatal_error "cannot find $destdir/configure.ac"
+        func_fatal_error "cannot find $destdir/configure.ac - make sure you run gnulib-tool from within your package's directory"
       fi
     fi
 
@@ -4432,7 +4497,7 @@ case $mode in
       m4dirs=
       m4dirs_count=0
       if test -f "$destdir"/Makefile.am; then
-        aclocal_amflags=`sed -n 's/^ACLOCAL_AMFLAGS[    ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
+        aclocal_amflags=`sed -n -e 's/^ACLOCAL_AMFLAGS[         ]*=\(.*\)$/\1/p' "$destdir"/Makefile.am`
         m4dir_is_next=
         for arg in $aclocal_amflags; do
           if test -n "$m4dir_is_next"; then
@@ -4462,7 +4527,7 @@ case $mode in
           sedexpr2='s,^[^/]*$,.,'
           sedexpr3='s,/[^/]*$,,'
           m4dirs=`sed -n -e "$sedexpr1" aclocal.m4 | sed -e "$sedexpr2" -e "$sedexpr3" | LC_ALL=C sort -u`
-          m4dirs_count=`echo "$m4dirs" | wc -l`
+          m4dirs_count=`printf %s "$m4dirs" | wc -l`
         fi
       fi
       if test $m4dirs_count = 0; then
@@ -4600,6 +4665,16 @@ case $mode in
     done
     ;;
 
+  extract-applicability )
+    for module
+    do
+      func_verify_module
+      if test -n "$module"; then
+        func_get_applicability "$module"
+      fi
+    done
+    ;;
+
   extract-filelist )
     for module
     do
@@ -4710,13 +4785,15 @@ case $mode in
     test -n "$docbase" || docbase="doc"
     test -n "$testsbase" || testsbase="tests"
     test -n "$auxdir" || auxdir="build-aux"
+    rewritten='%REWRITTEN%'
     sed_rewrite_files="\
-      s,^build-aux/,$auxdir/,
-      s,^doc/,$docbase/,
-      s,^lib/,$sourcebase/,
-      s,^m4/,$m4base/,
-      s,^tests/,$testsbase/,
-      s,^top/,,"
+      s,^build-aux/,$rewritten$auxdir/,
+      s,^doc/,$rewritten$docbase/,
+      s,^lib/,$rewritten$sourcebase/,
+      s,^m4/,$rewritten$m4base/,
+      s,^tests/,$rewritten$testsbase/,
+      s,^top/,$rewritten,
+      s,^$rewritten,,"
     if test -d "$dest"; then
       destdir="$dest"
       g=`echo "$f" | sed -e "$sed_rewrite_files"`