Avoid creating an empty doc directory.
[gnulib.git] / gnulib-tool
index b7a6dea..4b814de 100755 (executable)
@@ -22,7 +22,7 @@
 
 progname=$0
 package=gnulib
-cvsdatestamp='$Date: 2006-04-24 11:35:07 $'
+cvsdatestamp='$Date: 2006-07-29 13:10:38 $'
 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
 
@@ -100,21 +100,29 @@ Operation modes:
       --extract-maintainer         report the maintainer(s) inside gnulib
       --extract-tests-module       report the unit test module, if it exists
 
-Options:
-      --dir=DIRECTORY       specify the target directory
+General options:
+      --dir=DIRECTORY       Specify the target directory.
                             For --import, this specifies where your
                             configure.ac can be found.  Defaults to current
                             directory.
+      --assume-autoconf=VERSION
+                            Assume a given autoconf version (or newer).
+                            If VERSION is 'latest-stable', assume the latest
+                            stable version.
+
+Options for --import:
       --lib=LIBRARY         Specify the library name.  Defaults to 'libgnu'.
       --source-base=DIRECTORY
-                            Directory relative --dir where source code is
-                            placed (default \"lib\"), for --import.
-      --m4-base=DIRECTORY   Directory relative --dir where *.m4 macros are
-                            placed (default \"m4\"), for --import.
+                            Directory relative to --dir where source code is
+                            placed (default \"lib\").
+      --m4-base=DIRECTORY   Directory relative to --dir where *.m4 macros are
+                            placed (default \"m4\").
+      --doc-base=DIRECTORY  Directory relative to --dir where doc files are
+                            placed (default \"doc\").
       --tests-base=DIRECTORY
-                            Directory relative --dir where unit tests are
-                            placed (default \"tests\"), for --import.
-      --aux-dir=DIRECTORY   Directory relative --dir where auxiliary build
+                            Directory relative to --dir where unit tests are
+                            placed (default \"tests\").
+      --aux-dir=DIRECTORY   Directory relative to --dir where auxiliary build
                             tools are placed (default \"build-aux\").
       --with-tests          Include unit tests for the included modules.
       --avoid=MODULE        Avoid including the given MODULE. Useful if you
@@ -122,10 +130,12 @@ Options:
                             This option can be repeated.
       --lgpl                Abort if modules aren't available under the LGPL.
                             Also modify license template from GPL to LGPL.
-      --libtool             Use libtool rules, for --import.
+      --libtool             Use libtool rules.
       --macro-prefix=PREFIX  Specify the prefix of the macros 'gl_EARLY' and
                             'gl_INIT'. Default is 'gl'.
       --no-changelog        don't update or create ChangeLog files
+
+Options for --import and --update:
       --dry-run             For --import, only print what would have been done.
   -s, --symbolic, --symlink Make symbolic links instead of copying files.
 
@@ -136,13 +146,29 @@ Report bugs to <bug-gnulib@gnu.org>."
 # outputs to stdout the --version message.
 func_version ()
 {
+  year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
   echo "$progname (GNU $package) $version"
-  echo "Copyright (C) 2002-2005 Free Software Foundation, Inc.
+  echo "Copyright (C) $year Free Software Foundation, Inc.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
   echo "Written by" "Bruno Haible" "and" "Simon Josefsson"
 }
 
+# func_emit_copyright_notice
+# outputs to stdout a header for a generated file.
+func_emit_copyright_notice ()
+{
+  echo "# Copyright (C) 2004-2006 Free Software Foundation, Inc."
+  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 "# the same distribution terms as the rest of that program."
+  echo "#"
+  echo "# Generated by gnulib-tool."
+}
+
 # func_tmpdir
 # creates a temporary directory.
 # Sets variable
@@ -222,12 +248,15 @@ func_ln_if_changed ()
 # - libname, supplied_libname  from --lib
 # - sourcebase      from --source-base
 # - m4base          from --m4-base
+# - docbase         from --doc-base
 # - testsbase       from --tests-base
 # - auxdir          from --aux-dir
 # - inctests        true if --with-tests was given, blank otherwise
 # - avoidlist       list of modules to avoid, from --avoid
 # - lgpl            true if --lgpl was given, blank otherwise
 # - libtool         true if --libtool was given, blank otherwise
+# - macro_prefix    from --macro-prefix
+# - 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
 {
@@ -237,6 +266,7 @@ func_ln_if_changed ()
   supplied_libname=
   sourcebase=
   m4base=
+  docbase=
   testsbase=
   auxdir=
   inctests=
@@ -244,6 +274,7 @@ func_ln_if_changed ()
   lgpl=
   libtool=
   macro_prefix=
+  autoconf_minversion=
   do_changelog=:
   doit=:
   symbolic=
@@ -318,6 +349,16 @@ func_ln_if_changed ()
       --m4-base=* )
         m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
         shift ;;
+      --doc-base )
+        shift
+        if test $# = 0; then
+          func_fatal_error "missing argument for --doc-base"
+        fi
+        docbase=$1
+        shift ;;
+      --doc-base=* )
+        docbase=`echo "X$1" | sed -e 's/^X--doc-base=//'`
+        shift ;;
       --tests-base )
         shift
         if test $# = 0; then
@@ -367,6 +408,16 @@ func_ln_if_changed ()
       --macro-prefix=* )
         macro_prefix=`echo "X$1" | sed -e 's/^X--macro-prefix=//'`
         shift ;;
+      --assume-autoconf )
+        shift
+        if test $# = 0; then
+          func_fatal_error "missing argument for --assume-autoconf"
+        fi
+        autoconf_minversion="$1"
+        shift ;;
+      --assume-autoconf=* )
+        autoconf_minversion=`echo "X$1" | sed -e 's/^X--assume-autoconf=//'`
+        shift ;;
       --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
         do_changelog=false
         shift ;;
@@ -403,9 +454,10 @@ func_ln_if_changed ()
       echo "you need to use 'gnulib --import' - at your own risk!" 1>&2
       exit 1
     fi
-    if test -n "$libname" || test -n "$sourcebase" || test -n "$m4base" \
-       || test -n "$testsbase" || test -n "$auxdir" || test -n "$inctests" \
-       || test -n "$avoidlist" || test -n "$lgpl" || test -n "$macro_prefix"; then
+    if test -n "$supplied_libname" || test -n "$sourcebase" || test -n "$m4base" \
+       || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
+       || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
+       || test -n "$macro_prefix" || test -n "$autoconf_minversion"; then
       echo "gnulib-tool: invalid options for 'update' mode" 1>&2
       echo "Try 'gnulib-tool --help' for more information." 1>&2
       echo "If you really want to modify the gnulib configuration of your project," 1>&2
@@ -415,6 +467,12 @@ func_ln_if_changed ()
     do_changelog=false
   fi
 
+  DEFAULT_AUTOCONF_MINVERSION="2.59"
+  case "$autoconf_minversion" in
+    1.* | 2.[0-4]* | 2.5[0-8]*)
+      func_fatal_error "minimum supported autoconf version is 2.59" ;;
+  esac
+
   # Remove trailing slashes from the directory names. This is necessary for
   # m4base (to avoid an error in func_import) and optional for the others.
   sed_trimtrailingslashes='s,\([^/]\)//*$,\1,'
@@ -424,6 +482,9 @@ func_ln_if_changed ()
   case "$m4base" in
     */ ) m4base=`echo "$m4base" | sed -e "$sed_trimtrailingslashes"` ;;
   esac
+  case "$docbase" in
+    */ ) docbase=`echo "$docbase" | sed -e "$sed_trimtrailingslashes"` ;;
+  esac
   case "$testsbase" in
     */ ) testsbase=`echo "$testsbase" | sed -e "$sed_trimtrailingslashes"` ;;
   esac
@@ -504,17 +565,17 @@ func_verify_tests_module ()
   esac
 }
 
-sed_extract_prog=':[   ]*$/ {
+sed_extract_prog=':[    ]*$/ {
   :a
     n
-    s/^Description:[   ]*$//
-    s/^Files:[         ]*$//
-    s/^Depends-on:[    ]*$//
-    s/^configure\.ac:[         ]*$//
-    s/^Makefile\.am:[  ]*$//
-    s/^Include:[       ]*$//
-    s/^License:[       ]*$//
-    s/^Maintainer:[    ]*$//
+    s/^Description:[    ]*$//
+    s/^Files:[  ]*$//
+    s/^Depends-on:[     ]*$//
+    s/^configure\.ac:[  ]*$//
+    s/^Makefile\.am:[   ]*$//
+    s/^Include:[        ]*$//
+    s/^License:[        ]*$//
+    s/^Maintainer:[     ]*$//
     tb
     p
     ba
@@ -531,8 +592,12 @@ func_get_description ()
 func_get_filelist ()
 {
   sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
-  #echo m4/onceonly.m4
-  echo m4/onceonly_2_57.m4
+  case "$autoconf_minversion" in
+    2.59)
+      #echo m4/onceonly.m4
+      echo m4/onceonly_2_57.m4
+      ;;
+  esac
 }
 
 # func_get_dependencies module
@@ -667,7 +732,7 @@ ba
     func_verify_nontests_module
     if test -n "$module"; then
       # Extract the value of "lib_SOURCES += ...".
-      for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[   ]*+=\([^#]*\).*$,\1,p'`; do
+      for file in `func_get_automake_snippet "$module" | sed -e "$sed_remove_backslash_newline" | sed -n -e 's,^lib_SOURCES[    ]*+=\([^#]*\).*$,\1,p'`; do
         # Ignore .h files since they are not compiled.
         case "$file" in
           *.h) ;;
@@ -716,15 +781,7 @@ func_emit_lib_Makefile_am ()
     perhapsLT=
   fi
   echo "## Process this file with automake to produce Makefile.in."
-  echo "# Copyright (C) 2004 Free Software Foundation, Inc."
-  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 Automake, under"
-  echo "# the same distribution terms as the rest of that program."
-  echo "#"
-  echo "# Generated by gnulib-tool."
+  func_emit_copyright_notice
   if test -n "$actioncmd"; then
     echo "# Reproduce by: $actioncmd"
   fi
@@ -741,6 +798,7 @@ func_emit_lib_Makefile_am ()
   echo "BUILT_SOURCES ="
   echo "SUFFIXES ="
   echo "MOSTLYCLEANFILES ="
+  echo "MOSTLYCLEANDIRS ="
   echo "CLEANFILES ="
   echo "DISTCLEANFILES ="
   echo "MAINTAINERCLEANFILES ="
@@ -758,7 +816,7 @@ func_emit_lib_Makefile_am ()
         fi
       } > amsnippet.tmp
       # Skip the contents if its entirely empty.
-      if grep '[^      ]' amsnippet.tmp > /dev/null ; then
+      if grep '[^       ]' amsnippet.tmp > /dev/null ; then
         echo "## begin gnulib module $module"
         echo
         cat amsnippet.tmp
@@ -769,6 +827,14 @@ func_emit_lib_Makefile_am ()
     fi
   done
   echo
+  echo "mostlyclean-local:"
+  echo "       @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
+  echo "         for dir in \$(MOSTLYCLEANDIRS); do \\"
+  echo "           if test -d \$\$dir; then \\"
+  echo "             echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
+  echo "           fi; \\"
+  echo "         done"
+  echo
   echo "# Makefile.am ends here"
 }
 
@@ -790,15 +856,7 @@ func_emit_tests_Makefile_am ()
   fi
   testsbase_inverse=`echo "$testsbase" | sed -e 's,/$,,' | sed -e 's,[^/][^/]*,..,g'`
   echo "## Process this file with automake to produce Makefile.in."
-  echo "# Copyright (C) 2004-2005 Free Software Foundation, Inc."
-  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 Automake, under"
-  echo "# the same distribution terms as the rest of that program."
-  echo "#"
-  echo "# Generated by gnulib-tool."
+  func_emit_copyright_notice
   echo
   # Generate dependencies here, since it eases the debugging of test failures.
   echo "AUTOMAKE_OPTIONS = 1.5 foreign"
@@ -818,6 +876,7 @@ func_emit_tests_Makefile_am ()
   echo "BUILT_SOURCES ="
   echo "SUFFIXES ="
   echo "MOSTLYCLEANFILES ="
+  echo "MOSTLYCLEANDIRS ="
   echo "CLEANFILES ="
   echo "DISTCLEANFILES ="
   echo "MAINTAINERCLEANFILES ="
@@ -834,7 +893,7 @@ func_emit_tests_Makefile_am ()
     if test -n "$module"; then
       func_get_automake_snippet "$module" > amsnippet.tmp
       # Skip the contents if its entirely empty.
-      if grep '[^      ]' amsnippet.tmp > /dev/null ; then
+      if grep '[^       ]' amsnippet.tmp > /dev/null ; then
         echo "## begin gnulib module $module"
         echo
         cat amsnippet.tmp
@@ -848,6 +907,14 @@ func_emit_tests_Makefile_am ()
   echo "clean-local:"
   echo "       rm -rf SunWS_cache"
   echo
+  echo "mostlyclean-local:"
+  echo "       @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
+  echo "         for dir in \$(MOSTLYCLEANDIRS); do \\"
+  echo "           if test -d \$\$dir; then \\"
+  echo "             echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
+  echo "           fi; \\"
+  echo "         done"
+  echo
   echo "# Makefile.am ends here"
 }
 
@@ -857,6 +924,7 @@ func_emit_tests_Makefile_am ()
 # - libname         library name
 # - sourcebase      directory relative to destdir where to place source code
 # - m4base          directory relative to destdir where to place *.m4 macros
+# - 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
@@ -865,6 +933,7 @@ func_emit_tests_Makefile_am ()
 # - libtool         true if libtool will be used, blank otherwise
 # - guessed_libtool true if the configure.ac file uses libtool, blank otherwise
 # - macro_prefix    prefix of gl_EARLY, gl_INIT macros to use
+# - autoconf_minversion  minimum supported autoconf version
 # - doit            : if actions shall be executed, false if only to be printed
 # - symbolic        true if files should be symlinked, copied otherwise
 func_import ()
@@ -874,11 +943,13 @@ func_import ()
   cached_avoidlist=
   cached_sourcebase=
   cached_m4base=
+  cached_docbase=
   cached_testsbase=
   cached_libname=
   cached_lgpl=
   cached_libtool=
   cached_macro_prefix=
+  cached_autoconf_minversion=
   cached_files=
   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
     my_sed_traces='
@@ -897,6 +968,9 @@ func_import ()
       /gl_M4_BASE(/ {
         s,^.*gl_M4_BASE([[ ]*\([^])]*\).*$,cached_m4base="\1",p
       }
+      /gl_DOC_BASE(/ {
+        s,^.*gl_DOC_BASE([[ ]*\([^])]*\).*$,cached_docbase="\1",p
+      }
       /gl_TESTS_BASE(/ {
         s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
       }
@@ -911,6 +985,9 @@ func_import ()
       }
       /gl_MACRO_PREFIX(/ {
         s,^.*gl_MACRO_PREFIX([[ ]*\([^])]*\).*$,cached_macro_prefix="\1",p
+      }
+      /gl_AUTOCONF_MINVERSION(/ {
+        s,^.*gl_AUTOCONF_MINVERSION([[ ]*\([^])]*\).*$,cached_autoconf_minversion="\1",p
       }'
     eval `sed -n -e "$my_sed_traces" < "$destdir"/$m4base/gnulib-cache.m4`
     if test -f "$destdir"/$m4base/gnulib-comp.m4; then
@@ -953,6 +1030,13 @@ func_import ()
       func_fatal_error "missing --source-base option"
     fi
   fi
+  # The docbase defaults to the cached one.
+  if test -z "$docbase"; then
+    docbase="$cached_docbase"
+    if test -z "$docbase"; then
+      func_fatal_error "missing --doc-base option. --doc-base has been introduced on 2006-07-11; if your last invocation of 'gnulib-tool --update' is before that date, you need to run 'gnulib-tool --update' once, with a --doc-base option."
+    fi
+  fi
   # The testsbase defaults to the cached one.
   if test -z "$testsbase"; then
     testsbase="$cached_testsbase"
@@ -986,6 +1070,13 @@ func_import ()
       func_fatal_error "missing --macro-prefix option"
     fi
   fi
+  # The autoconf_minversion defaults to the cached one.
+  if test -z "$autoconf_minversion"; then
+    autoconf_minversion="$cached_autoconf_minversion"
+    if test -z "$autoconf_minversion"; then
+      autoconf_minversion="$DEFAULT_AUTOCONF_MINVERSION"
+    fi
+  fi
 
   # Canonicalize the list of specified modules.
   specified_modules=`for m in $specified_modules; do echo $m; done | LC_ALL=C sort | LC_ALL=C uniq`
@@ -1042,6 +1133,17 @@ func_import ()
       echo "Create directory $destdir/$m4base"
     fi
   fi
+  docfiles=`echo "$files" | sed -n -e 's,^doc/,,p'`
+  if test -n "$docfiles"; then
+    if test ! -d "$destdir/$docbase"; then
+      if $doit; then
+        echo "Creating directory $destdir/$docbase"
+        mkdir "$destdir/$docbase" || func_fatal_error "failed"
+      else
+        echo "Create directory $destdir/$docbase"
+      fi
+    fi
+  fi
   if test -n "$inctests"; then
     if test ! -d "$destdir/$testsbase"; then
       if $doit; then
@@ -1085,6 +1187,7 @@ func_import ()
   for f in $old_files; do
     case "$f" in
       build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
+      doc/*) g=`echo "$f" | sed -e "s,^doc/,$cached_docbase/,"` ;;
       lib/*) g=`echo "$f" | sed -e "s,^lib/,$cached_sourcebase/,"` ;;
       m4/*) g=`echo "$f" | sed -e "s,^m4/,$cached_m4base/,"` ;;
       tests/*) g=`echo "$f" | sed -e "s,^tests/,$cached_testsbase/,"` ;;
@@ -1095,6 +1198,7 @@ func_import ()
   for f in $new_files; do
     case "$f" in
       build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
+      doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
       lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
       m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
       tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
@@ -1180,6 +1284,7 @@ func_import ()
   for f in `LC_ALL=C join -t"$delimiter" -v2 "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
     case "$f" in
       build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
+      doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
       lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
       m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
       tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
@@ -1192,6 +1297,7 @@ func_import ()
   for f in `LC_ALL=C join -t"$delimiter" "$tmp"/old-files "$tmp"/new-files | sed -e "$sed_take_last_column"`; do
     case "$f" in
       build-aux/*) g=`echo "$f" | sed -e "s,^build-aux/,$auxdir/,"` ;;
+      doc/*) g=`echo "$f" | sed -e "s,^doc/,$docbase/,"` ;;
       lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
       m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
       tests/*) g=`echo "$f" | sed -e "s,^tests/,$testsbase/,"` ;;
@@ -1206,6 +1312,7 @@ func_import ()
   actioncmd="$actioncmd --lib=$libname"
   actioncmd="$actioncmd --source-base=$sourcebase"
   actioncmd="$actioncmd --m4-base=$m4base"
+  actioncmd="$actioncmd --doc-base=$docbase"
   actioncmd="$actioncmd --aux-dir=$auxdir"
   for module in $avoidlist; do
     actioncmd="$actioncmd --avoid=$module"
@@ -1217,6 +1324,7 @@ func_import ()
     actioncmd="$actioncmd --libtool"
   fi
   actioncmd="$actioncmd --macro-prefix=$macro_prefix"
+  actioncmd="$actioncmd --assume-autoconf=$autoconf_minversion"
   actioncmd="$actioncmd `echo $specified_modules`"
 
   # Create lib/Makefile.am.
@@ -1248,14 +1356,7 @@ func_import ()
   # Create m4/gnulib-cache.m4.
   func_dest_tmpfilename $m4base/gnulib-cache.m4
   (
-    echo "# Copyright (C) 2004 Free Software Foundation, Inc."
-    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 "# the same distribution terms as the rest of that program."
-    echo "#"
-    echo "# Generated by gnulib-tool."
+    func_emit_copyright_notice
     echo "#"
     echo "# This file represents the specification of how gnulib-tool is used."
     echo "# It acts as a cache: It is written and read by gnulib-tool."
@@ -1271,11 +1372,13 @@ func_import ()
     echo "gl_AVOID([$avoidlist])"
     echo "gl_SOURCE_BASE([$sourcebase])"
     echo "gl_M4_BASE([$m4base])"
+    echo "gl_DOC_BASE([$docbase])"
     echo "gl_TESTS_BASE([$testsbase])"
     echo "gl_LIB([$libname])"
     test -z "$lgpl" || echo "gl_LGPL"
     test -z "$libtool" || echo "gl_LIBTOOL"
     echo "gl_MACRO_PREFIX([$macro_prefix])"
+    echo "gl_AUTOCONF_MINVERSION([$autoconf_minversion])"
   ) > "$tmpfile"
   if test -f "$destdir"/$m4base/gnulib-cache.m4; then
     if cmp "$destdir"/$m4base/gnulib-cache.m4 "$tmpfile" > /dev/null; then
@@ -1309,14 +1412,7 @@ func_import ()
   # Create m4/gnulib-comp.m4.
   func_dest_tmpfilename $m4base/gnulib-comp.m4
   (
-    echo "# Copyright (C) 2004 Free Software Foundation, Inc."
-    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 "# the same distribution terms as the rest of that program."
-    echo "#"
-    echo "# Generated by gnulib-tool."
+    func_emit_copyright_notice
     echo "#"
     echo "# This file represents the compiled summary of the specification in"
     echo "# gnulib-cache.m4. It lists the computed macro invocations that need"
@@ -1453,9 +1549,30 @@ func_import ()
   echo "Finished."
   echo
   echo "You may need to add #include directives for the following .h files."
-  for module in $modules; do
-    func_get_include_directive "$module"
-  done | LC_ALL=C sort -u | sed -e '/^$/d;' -e 's/^/  /'
+  (
+   # First the #include <...> directives without #ifs, sorted for convenience.
+   for module in $modules; do
+     if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
+       :
+     else
+       func_get_include_directive "$module" | grep -v 'include "'
+     fi
+   done | LC_ALL=C sort -u
+   # Then the #include "..." directives without #ifs, sorted for convenience.
+   for module in $modules; do
+     if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
+       :
+     else
+       func_get_include_directive "$module" | grep 'include "'
+     fi
+   done | LC_ALL=C sort -u
+   # Then the #include directives that are surrounded by #ifs. Not sorted.
+   for module in $modules; do
+     if func_get_include_directive "$module" | grep '^#if' >/dev/null; then
+       func_get_include_directive "$module"
+     fi
+   done
+  ) | sed -e '/^$/d;' -e 's/^/  /'
   echo
   echo "Don't forget to"
   echo "  - add \"$sourcebase/Makefile\" to AC_CONFIG_FILES in $configure_ac,"
@@ -1788,7 +1905,7 @@ case $mode in
     ;;
 
   import | update )
-    
+
     # Where to import.
     if test -z "$destdir"; then
       destdir=.
@@ -1837,8 +1954,10 @@ case $mode in
         # First use of gnulib in the given m4base.
         test -n "$supplied_libname" || supplied_libname=true
         test -n "$sourcebase" || sourcebase="lib"
+        test -n "$docbase" || docbase="doc"
         test -n "$testsbase" || testsbase="tests"
         test -n "$macro_prefix" || macro_prefix="gl"
+        test -n "$autoconf_minversion" || autoconf_minversion="$DEFAULT_AUTOCONF_MINVERSION"
       fi
       func_import "$*"
     else
@@ -1846,7 +1965,7 @@ case $mode in
       # To get this list of directories, look at Makefile.am. (Not at
       # configure, because it may be omitted from CVS. Also, don't run
       # "find $destdir -name gnulib-cache.m4", as it might be too expensive.)
-      aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[         ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[       ]*=\(.*\)$/\1/'`
+      aclocal_amflags=`grep '^ACLOCAL_AMFLAGS[  ]*=' "$destdir"/Makefile.am | sed -e 's/^ACLOCAL_AMFLAGS[       ]*=\(.*\)$/\1/'`
       m4dirs=
       m4dirs_count=0
       m4dir_is_next=
@@ -1876,8 +1995,10 @@ case $mode in
         test -n "$supplied_libname" || supplied_libname=true
         test -n "$sourcebase" || sourcebase="lib"
         m4base="m4"
+        test -n "$docbase" || docbase="doc"
         test -n "$testsbase" || testsbase="tests"
         test -n "$macro_prefix" || macro_prefix="gl"
+        test -n "$autoconf_version" || autoconf_version="$DEFAULT_AUTOCONF_MINVERSION"
         func_import "$*"
       else
         if test $m4dirs_count = 1; then