canonicalize: Avoid a false-positive cycle failure.
[gnulib.git] / gnulib-tool
index 16f49aa..f6c4a17 100755 (executable)
 
 progname=$0
 package=gnulib
-cvsdatestamp='$Date: 2007-09-09 11:49:58 $'
+cvsdatestamp='$Date: 2007-09-17 10:26:33 $'
 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
+# Sometimes last_checkin_date is "YYYY/MM/DD ...", sometimes "YYYY-MM-DD ...".
 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
+# version is in YYYY-MM-DD format.
 nl='
 '
 IFS=" ""       $nl"
@@ -73,6 +75,17 @@ fi
 # gnulib-tool generates, since we don't want "sed --posix" to leak
 # into makefiles.
 if (alias) > /dev/null 2>&1 && echo | sed --posix -e d >/dev/null 2>&1; then
+  # Define sed as an alias.
+  # It is not always possible to use aliases. Aliases are guaranteed to work
+  # if the executing shell is bash and either it is invoked as /bin/sh or
+  # is a version >= 2.0, supporting shopt. This is the common case.
+  # Two other approaches (use of a variable $sed or of a function func_sed
+  # instead of an alias) require massive, fragile code changes.
+  # An other approach (use of function sed) requires `which sed` - but 'which'
+  # is hard to emulate, due to missing "test -x" on some platforms.
+  if test -n "$BASH_VERSION"; then
+    shopt -s expand_aliases >/dev/null 2>&1
+  fi
   alias sed='sed --posix'
 fi
 
@@ -89,6 +102,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-notice module
        gnulib-tool --extract-filelist module
        gnulib-tool --extract-dependencies module
        gnulib-tool --extract-autoconf-snippet module
@@ -114,6 +128,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-notice             extract the notice or banner
       --extract-filelist           extract the list of files
       --extract-dependencies       extract the dependencies
       --extract-autoconf-snippet   extract the snippet for configure.ac
@@ -183,7 +198,7 @@ Report bugs to <bug-gnulib@gnu.org>."
 # outputs to stdout the --version message.
 func_version ()
 {
-  year=`echo "$last_checkin_date" | sed -e 's,/.*$,,'`
+  year=`echo "$version" | sed -e 's,-.*$,,'`
   echo "\
 $progname (GNU $package) $version
 Copyright (C) $year Free Software Foundation, Inc.
@@ -1142,6 +1157,7 @@ sed_extract_prog=':[       ]*$/ {
   :a
     n
     s/^Description:[    ]*$//
+    s/^Notice:[         ]*$//
     s/^Files:[  ]*$//
     s/^Depends-on:[     ]*$//
     s/^configure\.ac-early:[    ]*$//
@@ -1166,6 +1182,15 @@ func_get_description ()
   sed -n -e "/^Description$sed_extract_prog" < "$lookedup_file"
 }
 
+# func_get_notice module
+# Input:
+# - local_gnulib_dir  from --local-dir
+func_get_notice ()
+{
+  func_lookup_file "modules/$1"
+  sed -n -e "/^Notice$sed_extract_prog" < "$lookedup_file"
+}
+
 # func_get_filelist module
 # Input:
 # - local_gnulib_dir  from --local-dir
@@ -1444,6 +1469,27 @@ ba
   fi
 }
 
+# func_modules_notice
+# Input:
+# - local_gnulib_dir  from --local-dir
+# - verbose         integer, default 0, inc/decremented by --verbose/--quiet
+# - modules         list of modules, including dependencies
+func_modules_notice ()
+{
+  if test $verbose -ge -1; then
+    for module in $modules; do
+      func_verify_module
+      if test -n "$module"; then
+        msg=`func_get_notice $module`
+        if test -n "$msg"; then
+          echo "Notice from module $module:"
+          echo "$msg" | sed -e 's/^/  /'
+        fi
+      fi
+    done
+  fi
+}
+
 # func_modules_to_filelist
 # Input:
 # - local_gnulib_dir  from --local-dir
@@ -1463,7 +1509,6 @@ func_modules_to_filelist ()
   files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
 }
 
-
 # func_execute_command command [args...]
 # Executes a command.
 # Uses also the variables
@@ -2148,6 +2193,9 @@ func_import ()
     done
   fi
 
+  # Show banner notice of every module.
+  func_modules_notice
+
   # Determine script to apply to imported library files.
   sed_transform_lib_file=
   for module in $modules; do
@@ -3068,6 +3116,9 @@ func_create_testdir ()
   # Add the dummy module if needed.
   func_modules_add_dummy
 
+  # Show banner notice of every module.
+  func_modules_notice
+
   # Determine final file list.
   func_modules_to_filelist
   if test $verbose -ge 0; then
@@ -3749,6 +3800,16 @@ case $mode in
     done
     ;;
 
+  extract-notice )
+    for module
+    do
+      func_verify_module
+      if test -n "$module"; then
+        func_get_notice "$module"
+      fi
+    done
+    ;;
+
   extract-filelist )
     for module
     do