autoupdate
[gnulib.git] / gnulib-tool
index 977587c..679d12f 100755 (executable)
@@ -100,6 +100,7 @@ Usage: gnulib-tool --list
        gnulib-tool --test --dir=directory module1 ... moduleN
        gnulib-tool --megatest --dir=directory [module1 ... moduleN]
        gnulib-tool --extract-description module
+       gnulib-tool --extract-status module
        gnulib-tool --extract-notice module
        gnulib-tool --extract-filelist module
        gnulib-tool --extract-dependencies module
@@ -126,6 +127,7 @@ Operation modes:
       --megatest            test the given modules one by one and all together
                             (recommended to use CC=\"gcc -Wall\" here)
       --extract-description        extract the description
+      --extract-status             extract the status (obsolete or not)
       --extract-notice             extract the notice or banner
       --extract-filelist           extract the list of files
       --extract-dependencies       extract the dependencies
@@ -165,6 +167,9 @@ Options for --import:
       --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.
+      --with-obsolete       Include obsolete modules when they occur among the
+                            dependencies. By default, dependencies to obsolete
+                            modules are ignored.
       --avoid=MODULE        Avoid including the given MODULE. Useful if you
                             have code that provides equivalent functionality.
                             This option can be repeated.
@@ -216,7 +221,7 @@ q
     date=`echo "$date" | sed -e "$sed_year_before_time"`
     # Use GNU date to compute the time in GMT.
     date=`date -d "$date" -u +"%Y-%m-%d %H:%M:%S"`
-    version=' '`"$gnulib_dir"/build-aux/git-version-gen /dev/null | sed -e 's/-dirty/-modified/'`
+    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
@@ -272,14 +277,16 @@ func_exit ()
 
 # func_gnulib_dir
 # locates the directory where the gnulib repository lives
+# Input:
+# - progname                 name of this program
 # Sets variables
 # - self_abspathname         absolute pathname of gnulib-tool
 # - gnulib_dir               absolute pathname of gnulib repository
 func_gnulib_dir ()
 {
-  case "$0" in
-    /*) self_abspathname="$0" ;;
-    */*) self_abspathname=`pwd`/"$0" ;;
+  case "$progname" in
+    /*) self_abspathname="$progname" ;;
+    */*) self_abspathname=`pwd`/"$progname" ;;
     *)
       # Look in $PATH.
       # Iterate through the elements of $PATH.
@@ -326,8 +333,8 @@ func_gnulib_dir ()
       for d in $pathx; do
         IFS="$save_IFS"
         test -z "$d" && d=.
-        if test -x "$d/$0" && test ! -d "$d/$0"; then
-          self_abspathname="$d/$0"
+        if test -x "$d/$progname" && test ! -d "$d/$progname"; then
+          self_abspathname="$d/$progname"
           break
         fi
       done
@@ -351,6 +358,8 @@ func_gnulib_dir ()
 
 # func_tmpdir
 # creates a temporary directory.
+# Input:
+# - progname                 name of this program
 # Sets variable
 # - tmp             pathname of freshly created temporary directory
 func_tmpdir ()
@@ -375,7 +384,7 @@ func_tmpdir ()
     (umask 077 && mkdir "$tmp")
   } ||
   {
-    echo "$0: cannot create a temporary directory in $TMPDIR" >&2
+    echo "$progname: cannot create a temporary directory in $TMPDIR" >&2
     func_exit 1
   }
 }
@@ -398,10 +407,12 @@ fi
 
 # func_fatal_error message
 # outputs to stderr a fatal error message, and terminates the program.
+# Input:
+# - progname                 name of this program
 func_fatal_error ()
 {
-  echo "gnulib-tool: *** $1" 1>&2
-  echo "gnulib-tool: *** Stop." 1>&2
+  echo "$progname: *** $1" 1>&2
+  echo "$progname: *** Stop." 1>&2
   func_exit 1
 }
 
@@ -740,6 +751,7 @@ fi
 # - testsbase       from --tests-base
 # - auxdir          from --aux-dir
 # - inctests        true if --with-tests was given, blank otherwise
+# - incobsolete     true if --with-obsolete was given, blank otherwise
 # - avoidlist       list of modules to avoid, from --avoid
 # - lgpl            yes or a number if --lgpl was given, blank otherwise
 # - makefile_name   from --makefile-name
@@ -770,6 +782,7 @@ fi
   testsbase=
   auxdir=
   inctests=
+  incobsolete=
   avoidlist=
   lgpl=
   makefile_name=
@@ -912,6 +925,9 @@ fi
       --with-tests )
         inctests=true
         shift ;;
+      --with-obsolete )
+        incobsolete=true
+        shift ;;
       --avoid )
         shift
         if test $# = 0; then
@@ -1022,9 +1038,10 @@ fi
     if test -n "$local_gnulib_dir" || test -n "$supplied_libname" \
        || test -n "$sourcebase" || test -n "$m4base" || test -n "$pobase" \
        || test -n "$docbase" || test -n "$testsbase" || test -n "$auxdir" \
-       || test -n "$inctests" || test -n "$avoidlist" || test -n "$lgpl" \
-       || test -n "$makefile_name" || test -n "$macro_prefix" \
-       || test -n "$po_domain" || test -n "$vc_files"; then
+       || test -n "$inctests" || test -n "$incobsolete" \
+       || test -n "$avoidlist" || test -n "$lgpl" || test -n "$makefile_name" \
+       || test -n "$macro_prefix" || test -n "$po_domain" \
+       || test -n "$vc_files"; 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
@@ -1250,6 +1267,7 @@ sed_extract_prog=':[       ]*$/ {
   :a
     n
     s/^Description:[    ]*$//
+    s/^Status:[         ]*$//
     s/^Notice:[         ]*$//
     s/^Files:[  ]*$//
     s/^Depends-on:[     ]*$//
@@ -1275,6 +1293,15 @@ func_get_description ()
   sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
 }
 
+# func_get_status module
+# Input:
+# - local_gnulib_dir  from --local-dir
+func_get_status ()
+{
+  func_lookup_file "modules/$1"
+  sed -n -e "/^Status$sed_extract_prog" < "$lookedup_file"
+}
+
 # func_get_notice module
 # Input:
 # - local_gnulib_dir  from --local-dir
@@ -1501,6 +1528,8 @@ func_acceptable ()
 # - local_gnulib_dir  from --local-dir
 # - modules         list of specified modules
 # - inctests        true if tests should be included, blank otherwise
+# - incobsolete     true if obsolete modules among dependencies should be
+#                   included, blank otherwise
 # - avoidlist       list of modules to avoid
 # - tmp             pathname of a temporary directory
 # Output:
@@ -1529,7 +1558,12 @@ func_modules_transitive_closure ()
           if test -n "$duplicated_deps"; then
             echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
           fi
-          func_append inmodules " $deps"
+          for dep in $deps; do
+            if test -n "$incobsolete" \
+               || { status=`func_get_status $dep`; test "$status" != obsolete; }; then
+              func_append inmodules " $dep"
+            fi
+          done
           if test -n "$inctests"; then
             testsmodule=`func_get_tests_module $module`
             if test -n "$testsmodule"; then
@@ -2221,6 +2255,7 @@ func_emit_initmacro_done ()
 # - 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
+# - incobsolete     true if --with-obsolete was given, blank otherwise
 # - avoidlist       list of modules to avoid, from --avoid
 # - lgpl            yes or a number if library's license shall be LGPL,
 #                   blank otherwise
@@ -2244,6 +2279,7 @@ func_import ()
   # Get the cached settings.
   cached_local_gnulib_dir=
   cached_specified_modules=
+  cached_incobsolete=
   cached_avoidlist=
   cached_sourcebase=
   cached_m4base=
@@ -2278,6 +2314,9 @@ func_import ()
         :b
         s,^.*gl_MODULES([[ ]*\([^])]*\).*$,cached_specified_modules="\1",p
       }
+      /gl_WITH_OBSOLETE/ {
+        s,^.*$,cached_incobsolete=true,p
+      }
       /gl_AVOID(/ {
         s,^.*gl_AVOID([[ ]*\([^])]*\).*$,cached_avoidlist="\1",p
       }
@@ -2372,6 +2411,10 @@ func_import ()
   # Append the cached and the specified module names. So that
   # "gnulib-tool --import foo" means to add the module foo.
   specified_modules="$cached_specified_modules $1"
+  # Included obsolete modules among the dependencies if specified either way.
+  if test -z "$incobsolete"; then
+    incobsolete="$cached_incobsolete"
+  fi
   # Append the cached and the specified avoidlist. This is probably better
   # than dropping the cached one when --avoid is specified at least once.
   avoidlist=`for m in $cached_avoidlist $avoidlist; do echo $m; done | LC_ALL=C sort -u`
@@ -2863,6 +2906,9 @@ s,^\(.................................................[^ ]*\) *,
   if test -n "$inctests"; then
     func_append actioncmd " --with-tests"
   fi
+  if test -n "$incobsolete"; then
+    func_append actioncmd " --with-obsolete"
+  fi
   for module in $avoidlist; do
     func_append actioncmd " --avoid=$module"
   done
@@ -3148,6 +3194,7 @@ s,//*$,/,'
     echo "gl_MODULES(["
     echo "$specified_modules" | sed 's/^/  /g'
     echo "])"
+    test -z "$incobsolete" || echo "gl_WITH_OBSOLETE"
     echo "gl_AVOID([$avoidlist])"
     echo "gl_SOURCE_BASE([$sourcebase])"
     echo "gl_M4_BASE([$m4base])"
@@ -3775,7 +3822,14 @@ func_create_testdir ()
      for module in $modules; do
        func_verify_module
        if test -n "$module"; then
-         func_get_autoconf_early_snippet "$module"
+         case $module in
+           gnumakefile | maintainer-makefile)
+             # These modules are meant to be used only in the top-level directory.
+             ;;
+           *)
+             func_get_autoconf_early_snippet "$module"
+             ;;
+         esac
        fi
      done \
        | sed -e '/^$/d;' -e 's/AC_REQUIRE(\[\([^()]*\)\])/\1/'
@@ -3810,8 +3864,15 @@ func_create_testdir ()
      for module in $modules; do
        func_verify_nontests_module
        if test -n "$module"; then
-         func_get_autoconf_snippet "$module" \
-           | sed -e "$sed_replace_build_aux"
+         case $module in
+           gnumakefile | maintainer-makefile)
+             # These modules are meant to be used only in the top-level directory.
+             ;;
+           *)
+             func_get_autoconf_snippet "$module" \
+               | sed -e "$sed_replace_build_aux"
+             ;;
+         esac
        fi
      done
      echo "gl_source_base='.'"
@@ -4259,9 +4320,9 @@ case $mode in
             for m4base in $m4dirs; do
               # Perform func_import in a subshell, so that variable values
               # such as
-              #   local_gnulib_dir, avoidlist, sourcebase, m4base, pobase,
-              #   docbase, testsbase, inctests, libname, lgpl, makefile_name,
-              #   libtool, macro_prefix, po_domain, vc_files
+              #   local_gnulib_dir, incobsolete, avoidlist, sourcebase, m4base,
+              #   pobase, docbase, testsbase, inctests, libname, lgpl,
+              #   makefile_name, libtool, macro_prefix, po_domain, vc_files
               # don't propagate from one directory to another.
               (func_import) || func_exit 1
             done
@@ -4350,6 +4411,16 @@ case $mode in
     done
     ;;
 
+  extract-status )
+    for module
+    do
+      func_verify_module
+      if test -n "$module"; then
+        func_get_status "$module"
+      fi
+    done
+    ;;
+
   extract-notice )
     for module
     do