Include <stdbool.h>. Use bool where appropriate,
[gnulib.git] / gnulib-tool
index 08890c8..44fd4a1 100755 (executable)
@@ -1,6 +1,6 @@
 #! /bin/sh
 #
-# Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+# Copyright (C) 2002, 2003, 2004, 2005 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
@@ -22,7 +22,7 @@
 
 progname=$0
 package=gnulib
-cvsdatestamp='$Date: 2004-12-15 22:31:01 $'
+cvsdatestamp='$Date: 2005-03-04 19:36:42 $'
 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
 
@@ -117,6 +117,41 @@ func_fatal_error ()
   exit 1
 }
 
+# func_cp_if_changed SRC DEST
+# Like cp, but avoids munging timestamps if the file hasn't changed.
+# Uses also the variables
+# - dry_run         true if actions shall only be printed, blank otherwise
+func_cp_if_changed ()
+{
+  if test $# -ne 2; then
+    echo "usage: func_cp_if_changed SRC DEST" >&2
+  fi
+  test -n "$dry_run" && dry=echo
+  if cmp "$1" "$2" >/dev/null 2>&1; then
+    :
+  else
+    $dry cp -p "$1" "$2"
+  fi
+}
+
+# func_mv_if_changed SRC DEST
+# Like mv, but avoids munging timestamps if the file hasn't changed.
+# Removes SRC if it is not renamed.
+# Uses also the variables
+# - dry_run         true if actions shall only be printed, blank otherwise
+func_mv_if_changed ()
+{
+  if test $# -ne 2; then
+    echo "usage: func_mv_if_changed SRC DEST" >&2
+  fi
+  test -n "$dry_run" && dry=echo
+  if cmp "$1" "$2" >/dev/null 2>&1; then
+    $dry rm "$1"
+  else
+    $dry mv "$1" "$2"
+  fi
+}
+
 # Command-line option processing.
 # Removes the OPTIONS from the arguments. Sets the variables:
 # - mode            list or import or create-testdir or create-megatestdir
@@ -523,8 +558,7 @@ func_import ()
       m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
       *) g="$f" ;;
     esac
-    test -n "$dry_run" && dry=echo
-    $dry cp -p "$gnulib_dir/$f" "$destdir/$g"
+    func_cp_if_changed "$gnulib_dir/$f" "$destdir/$g"
     # Update license.
     if test -z "$dry_run" && test -n "$lgpl" && test -n "$source"; then
       perl -pi -e 's/GNU General/GNU Lesser General/g;' \
@@ -548,16 +582,18 @@ func_import ()
   # Create lib/Makefile.am.
   echo "Creating $destdir/$sourcebase/Makefile.am..."
   if test -z "$dry_run"; then
-    func_emit_lib_Makefile_am > $destdir/$sourcebase/Makefile.am
+    func_emit_lib_Makefile_am > $destdir/$sourcebase/Makefile.am.new
   else
     func_emit_lib_Makefile_am
   fi
+  func_mv_if_changed $destdir/$sourcebase/Makefile.am.new \
+                     $destdir/$sourcebase/Makefile.am
 
   # Create gnulib.m4.
   echo "Creating $destdir/$m4base/gnulib.m4..."
   (
     if test -z "$dry_run"; then
-      exec > $destdir/$m4base/gnulib.m4
+      exec > $destdir/$m4base/gnulib.m4.new
     else
       echo "# $destdir/$m4base/gnulib.m4"
     fi
@@ -616,8 +652,14 @@ func_import ()
     echo
     echo "# gnulib.m4 ends here"
   )
+  func_mv_if_changed $destdir/$m4base/gnulib.m4.new $destdir/$m4base/gnulib.m4
   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" | sed -e '/^$/d;' -e 's/^/  /'
+  done
+  echo
   echo "Don't forget to add \"$sourcebase/Makefile\""
   echo "to AC_CONFIG_FILES in \"$configure_ac\" and to mention"
   echo "\"`basename $sourcebase`\" in SUBDIRS in some Makefile.am."