announce-gen: use Digest::SHA when possible
[gnulib.git] / gnulib-tool
index 37073ed..eef9ab6 100755 (executable)
@@ -1,6 +1,6 @@
 #! /bin/sh
 #
-# Copyright (C) 2002-2011 Free Software Foundation, Inc.
+# Copyright (C) 2002-2012 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
@@ -164,11 +164,15 @@ Operation modes:
       --update              update the current package, restore files omitted
                             from version control
       --create-testdir      create a scratch package with the given modules
+                            (pass --with-tests to include the unit tests)
       --create-megatestdir  create a mega scratch package with the given modules
                             one by one and all together
+                            (pass --with-tests to include the unit tests)
       --test                test the combination of the given modules
+                            (pass --with-tests to include the unit tests)
                             (recommended to use CC=\"gcc -Wall\" here)
       --megatest            test the given modules one by one and all together
+                            (pass --with-tests to include the unit tests)
                             (recommended to use CC=\"gcc -Wall\" here)
       --extract-description        extract the description
       --extract-comment            extract the comment
@@ -186,6 +190,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:
 
@@ -348,10 +354,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."
@@ -2363,31 +2381,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
@@ -2718,7 +2755,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"`
@@ -3341,20 +3378,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 \
@@ -3835,6 +3877,8 @@ func_emit_initmacro_done ()
 # - 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.
@@ -3857,6 +3901,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' \
@@ -3886,6 +3931,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 +3951,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 +3988,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 +4020,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"
@@ -5121,7 +5173,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
@@ -5443,7 +5495,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."
 }
 
@@ -5499,7 +5560,7 @@ 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=""
   for requested_module in $specified_modules; do
@@ -5730,7 +5791,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"
@@ -5845,7 +5906,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"
@@ -6481,6 +6542,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