[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gnulib] gnulib-tool plays nice with make
From: |
Derek Price |
Subject: |
Re: [bug-gnulib] gnulib-tool plays nice with make |
Date: |
Fri, 04 Mar 2005 10:42:09 -0500 |
User-agent: |
Mozilla Thunderbird 1.0 (Windows/20041206) |
Paul Eggert wrote:
The basic idea looks fine, but isn't there a lot of repeated code there?
It could be factored into a shell function.
Is this what you had in mind?
2005-03-04 Derek R. Price <address@hidden>
* gnulib-tool: Only replace files via --import when they have
actually changed.
Regards,
Derek
Index: gnulib-tool
===================================================================
RCS file: /cvsroot/gnulib/gnulib/gnulib-tool,v
retrieving revision 1.38
diff -u -p -r1.38 gnulib-tool
--- gnulib-tool 5 Jan 2005 02:50:04 -0000 1.38
+++ gnulib-tool 4 Mar 2005 15:39:47 -0000
@@ -117,6 +117,33 @@ func_fatal_error ()
exit 1
}
+# cp, but avoid munging timestamps if the file hasn't changed.
+cp_if_changed ()
+{
+ if test $# -ne 2; then
+ echo "usage: 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
+}
+
+# mv, but avoid munging timestamps if the file hasn't changed.
+# Remove the source file if it is not renamed.
+mv_if_changed ()
+{
+ if test $# -ne 2; then
+ echo "usage: 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 +550,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"
+ 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;' \
@@ -546,18 +572,20 @@ func_import ()
actioncmd="gnulib-tool --import --dir=$destdir --lib=$libname
--source-base=$sourcebase --m4-base=$m4base $opt_libtool $opt_lgpl `echo
$modules`"
# Create lib/Makefile.am.
- echo "Creating $destdir/$sourcebase/Makefile.am..."
+ echo "Creating $destdir/$sourcebase/Makefile.am.new..."
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
+ mv_if_changed $destdir/$sourcebase/Makefile.am.new \
+ $destdir/$sourcebase/Makefile.am
# Create gnulib.m4.
- echo "Creating $destdir/$m4base/gnulib.m4..."
+ echo "Creating $destdir/$m4base/gnulib.m4.new..."
(
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,6 +644,7 @@ func_import ()
echo
echo "# gnulib.m4 ends here"
)
+ 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."
signature.asc
Description: OpenPGP digital signature