* m4/include_next.m4 (gl_INCLUDE_NEXT): Define and AC_SUBST
[gnulib.git] / gnulib-tool
index eb50ee2..72fa60e 100755 (executable)
@@ -22,7 +22,7 @@
 
 progname=$0
 package=gnulib
-cvsdatestamp='$Date: 2007-03-12 00:48:31 $'
+cvsdatestamp='$Date: 2007-05-28 15:46:55 $'
 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
 nl='
@@ -826,6 +826,7 @@ func_all_modules ()
             -e '/^COPYING$/d' -e '/\/COPYING$/d' \
             -e '/^README$/d' -e '/\/README$/d' \
             -e '/^TEMPLATE$/d' \
+            -e '/^TEMPLATE-EXTENDED$/d' \
             -e '/^TEMPLATE-TESTS$/d' \
             -e '/^\..*/d' \
             -e '/~$/d' \
@@ -848,6 +849,7 @@ func_verify_module ()
      && test "COPYING" != "$module" \
      && test "README" != "$module" \
      && test "TEMPLATE" != "$module" \
+     && test "TEMPLATE-EXTENDED" != "$module" \
      && test "TEMPLATE-TESTS" != "$module"; then
     # OK, $module is a correct module name.
     # Verify that building the module description with 'patch' succeeds.
@@ -1173,7 +1175,9 @@ ba
   done
   # Add the dummy module, to make sure the library will be non-empty.
   if test -z "$have_lib_SOURCES"; then
-    func_append modules " dummy"
+    if func_acceptable "dummy"; then
+      func_append modules " dummy"
+    fi
   fi
 }
 
@@ -1562,6 +1566,7 @@ func_import ()
   cached_m4base=
   cached_docbase=
   cached_testsbase=
+  cached_inctests=
   cached_libname=
   cached_lgpl=
   cached_makefile_name=
@@ -1595,6 +1600,9 @@ func_import ()
       /gl_TESTS_BASE(/ {
         s,^.*gl_TESTS_BASE([[ ]*\([^])]*\).*$,cached_testsbase="\1",p
       }
+      /gl_WITH_TESTS/ {
+        s,^.*$,cached_inctests=true,p
+      }
       /gl_LIB(/ {
         s,^.*gl_LIB([[ ]*\([^])]*\).*$,cached_libname="\1",p
       }
@@ -1683,6 +1691,10 @@ func_import ()
       func_fatal_error "missing --tests-base option"
     fi
   fi
+  # Require the tests if specified either way.
+  if test -z "$inctests"; then
+    inctests="$cached_inctests"
+  fi
   # The libname defaults to the cached one.
   if test -z "$supplied_libname"; then
     libname="$cached_libname"
@@ -1835,6 +1847,8 @@ func_import ()
   }
 
   # Copy files or make symbolic links. Remove obsolete files.
+  added_files=''
+  removed_files=''
   delimiter='  '
   # Construct a table with 2 columns: rewritten-file-name original-file-name,
   # representing the files according to the last gnulib-tool invocation.
@@ -1859,6 +1873,7 @@ func_import ()
       else
         echo "Remove file $g (backup in ${g}~)"
       fi
+      func_append removed_files "$g$nl"
     fi
   done
   # func_add_or_update handles a file that ought to be present afterwards.
@@ -1927,6 +1942,7 @@ func_import ()
       else
         echo "Copy file $g"
       fi
+      func_append added_files "$g$nl"
     fi
     rm -f "$tmpfile"
   }
@@ -1969,6 +1985,9 @@ func_import ()
   func_append actioncmd " --m4-base=$m4base"
   func_append actioncmd " --doc-base=$docbase"
   func_append actioncmd " --aux-dir=$auxdir"
+  if test -n "$inctests"; then
+    func_append actioncmd " --with-tests"
+  fi
   for module in $avoidlist; do
     func_append actioncmd " --avoid=$module"
   done
@@ -2020,6 +2039,7 @@ func_import ()
       echo "Create $sourcebase/$makefile_am"
       rm -f "$tmpfile"
     fi
+    func_append added_files "$sourcebase/$makefile_am$nl"
   fi
 
   # Create m4/gnulib-cache.m4.
@@ -2057,6 +2077,7 @@ func_import ()
     echo "gl_M4_BASE([$m4base])"
     echo "gl_DOC_BASE([$docbase])"
     echo "gl_TESTS_BASE([$testsbase])"
+    test -z "$inctests" || echo "gl_WITH_TESTS"
     echo "gl_LIB([$libname])"
     test -z "$lgpl" || echo "gl_LGPL"
     echo "gl_MAKEFILE_NAME([$makefile_name])"
@@ -2245,9 +2266,86 @@ func_import ()
         echo "Create $testsbase/$makefile_am"
         rm -f "$tmpfile"
       fi
+    func_append added_files "$testsbase/$makefile_am$nl"
     fi
   fi
 
+  # Update the .cvsignore and .gitignore files.
+  { echo "$added_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|A|\1,'
+    echo "$removed_files" | sed -e '/^$/d' -e 's,\([^/]*\)$,|R|\1,'
+  } | LC_ALL=C sort -t'|' -k1,1 > "$tmp"/fileset-changes
+  { # Rearrange file descriptors. Needed because "while ... done < ..."
+    # constructs are executed in a subshell e.g. by Solaris 10 /bin/sh.
+    exec 5<&0 < "$tmp"/fileset-changes
+    func_update_ignorelist ()
+    {
+      ignore="$1"
+      if test -f "$destdir/$dir$ignore"; then
+        if test -n "$dir_added" || test -n "$dir_removed"; then
+          LC_ALL=C sort "$destdir/$dir$ignore" > "$tmp"/ignore
+          echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u \
+            | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-added
+          echo "$dir_removed" | sed -e '/^$/d' | LC_ALL=C sort -u \
+            | LC_ALL=C join -v 2 "$tmp"/ignore - > "$tmp"/ignore-removed
+          if test -s "$tmp"/ignore-added || test -s "$tmp"/ignore-removed; then
+            if $doit; then
+              echo "Updating $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
+              mv -f "$destdir/$dir$ignore" "$destdir/$dir$ignore"~
+              sed -e 's,^,/^,' -e 's,$,\$/d,' < "$tmp"/ignore-removed > "$tmp"/sed-ignore-removed
+              cat "$destdir/$dir$ignore"~ "$tmp"/ignore-added \
+                | sed -f "$tmp"/sed-ignore-removed \
+                > "$destdir/$dir$ignore"
+            else
+              echo "Update $destdir/$dir$ignore (backup in $destdir/$dir${ignore}~)"
+            fi
+          fi
+        fi
+      else
+        if test -n "$dir_added"; then
+          if $doit; then
+            echo "Creating $destdir/$dir$ignore"
+            echo "$dir_added" | sed -e '/^$/d' | LC_ALL=C sort -u > "$destdir/$dir$ignore"
+          else
+            echo "Create $destdir/$dir$ignore"
+          fi
+        fi
+      fi
+    }
+    func_done_dir ()
+    {
+      dir="$1"
+      dir_added="$2"
+      dir_removed="$3"
+      if test -d "$destdir/${dir}CVS" || test -f "$destdir/${dir}.cvsignore"; then
+        func_update_ignorelist .cvsignore
+      fi
+      if test -d "$destdir/.git" || test -f "$destdir/${dir}.gitignore"; then
+        func_update_ignorelist .gitignore
+      fi
+    }
+    last_dir=
+    last_dir_added=
+    last_dir_removed=
+    while read line; do
+      # Why not ''read next_dir op file'' ? Because the dir column can be empty.
+      next_dir=`echo "$line" | sed -e 's,|.*,,'`
+      op=`echo "$line" | sed -e 's,^[^|]*|\([^|]*\)|.*$,\1,'`
+      file=`echo "$line" | sed -e 's,^[^|]*|[^|]*|,,'`
+      if test "$next_dir" != "$last_dir"; then
+        func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
+        last_dir="$next_dir"
+        last_dir_added=
+        last_dir_removed=
+      fi
+      case $op in
+        A) func_append last_dir_added "$file$nl";;
+        R) func_append last_dir_removed "$file$nl";;
+      esac
+    done
+    func_done_dir "$last_dir" "$last_dir_added" "$last_dir_removed"
+    exec 0<&5 5<&-
+  }
+
   echo "Finished."
   echo
   echo "You may need to add #include directives for the following .h files."
@@ -2741,13 +2839,13 @@ func_create_testdir ()
   # distributed (such as getdate.c).
   # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
   cleaned_files=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
-                 | sed -n -e 's,^CLEANFILES[   ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
+                 | sed -n -e 's,^CLEANFILES[    ]*+=\([^#]*\).*$,\1,p' -e 's,^MOSTLYCLEANFILES[         ]*+=\([^#]*\).*$,\1,p'`
   cleaned_files=`for file in $cleaned_files; do echo " $file "; done`
   # Extract the value of "BUILT_SOURCES += ...". Remove variable references
   # such $(FOO_H) because they don't refer to distributed files.
   sed_remove_make_variables='s,[$]([A-Za-z0-9_]*),,g'
   built_sources=`sed -e "$sed_remove_backslash_newline" < "$testdir/$sourcebase/Makefile.am" \
-                 | sed -n -e 's,^BUILT_SOURCES[        ]*+=\([^#]*\).*$,\1,p' \
+                 | sed -n -e 's,^BUILT_SOURCES[         ]*+=\([^#]*\).*$,\1,p' \
                  | sed -e "$sed_remove_make_variables"`
   distributed_built_sources=`for file in $built_sources; do
                                case "$cleaned_files" in
@@ -2825,8 +2923,8 @@ func_create_megatestdir ()
    echo "   echo rc=\$?"
    echo "  ) 2>&1 | { if test -n \"\$AUTOBUILD_SUBST\"; then sed -e \"\$AUTOBUILD_SUBST\"; else cat; fi; } > logs/\$safemodule"
    echo "done"
-  ) > "$megatestdir/autobuild"
-  chmod a+x "$megatestdir/autobuild"
+  ) > "$megatestdir/do-autobuild"
+  chmod a+x "$megatestdir/do-autobuild"
 
   # Create Makefile.am.
   (echo "## Process this file with automake to produce Makefile.in."
@@ -2835,7 +2933,7 @@ func_create_megatestdir ()
    echo
    echo "SUBDIRS = $megasubdirs"
    echo
-   echo "EXTRA_DIST = autobuild"
+   echo "EXTRA_DIST = do-autobuild"
   ) > "$megatestdir/Makefile.am"
 
   # Create configure.ac.
@@ -2994,7 +3092,8 @@ case $mode in
               # Perform func_import in a subshell, so that variable values
               # such as
               #   local_gnulib_dir, avoidlist, sourcebase, m4base, docbase,
-              #   testsbase, libname, lgpl, makefile_name, libtool, macro_prefix
+              #   testsbase, inctests, libname, lgpl, makefile_name, libtool,
+              #   macro_prefix
               # don't propagate from one directory to another.
               (func_import) || func_exit 1
             done