automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Save the timestamp of unmodified yacc-generated .h files


From: Alexandre Duret-Lutz
Subject: Re: Save the timestamp of unmodified yacc-generated .h files
Date: Tue, 18 Nov 2003 21:06:18 +0100
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux)

>>> "Paolo" == Paolo Bonzini <address@hidden> writes:

 Paolo> This patch to ylwrap avoids useless rebuilds by not
 Paolo> modifying the timestamp of yacc's header files if they
 Paolo> were not changed.

Thanks a lot.  I'm installing it as follows.

2003-11-18  Paolo Bonzini  <address@hidden>
            Alexandre Duret-Lutz  <address@hidden>

        * lib/ylwrap: Do not overwrite headers if they haven't changed.
        Fix the include guard substitution.
        * tests/yacc6.test: Augment to run ylwrap, and make sure it
        does not needlessly update headers.
        * tests/yacc8.test: Make sure headers are not needlessly updated
        with ylwrap is not used.  Move `test -f foo.o' into the
        Makefile as `test -f foo.$(OBJEXT)' for portability.

Index: NEWS
===================================================================
RCS file: /cvs/automake/automake/NEWS,v
retrieving revision 1.244
diff -u -r1.244 NEWS
--- NEWS        11 Nov 2003 21:44:03 -0000      1.244
+++ NEWS        18 Nov 2003 20:05:28 -0000
@@ -206,6 +206,9 @@
     install it once for all in your source tree (and in your code
     management system).
 
+  - Fix ylwrap so that it does not overwrite header files that haven't
+    changed, as the inline rule already does.
+
 * Miscellaneous
 
   - The Automake manual is now distributed under the terms of the GNU FDL.
Index: lib/ylwrap
===================================================================
RCS file: /cvs/automake/automake/lib/ylwrap,v
retrieving revision 1.23
diff -u -r1.23 ylwrap
--- lib/ylwrap  9 Nov 2003 00:10:50 -0000       1.23
+++ lib/ylwrap  18 Nov 2003 20:05:28 -0000
@@ -1,7 +1,7 @@
 #! /bin/sh
 # ylwrap - wrapper for lex/yacc invocations.
 
-scriptversion=2003-11-09.00
+scriptversion=2003-11-18.20
 
 # Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003
 #   Free Software Foundation, Inc.
@@ -149,6 +149,16 @@
        *) target="../$2";;
       esac
 
+      # We do not want to overwrite a header file if it hasn't
+      # changed.  This avoid useless recompilations.  However the
+      # parser itself (the first file) should always be updated,
+      # because it is the destination of the .y.c rule in the
+      # Makefile.  Divert the output of all other files to a temporary
+      # file so we can compare them to existing versions.
+      if test $first = no; then
+       realtarget="$target"
+       target="tmp-`echo $target | sed s/.*[\\/]//g`"
+      fi
       # Edit out `#line' or `#' directives.
       #
       # We don't want the resulting debug information to point at
@@ -165,8 +175,20 @@
       TARGET=`echo "$2" | sed \
             -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'\
             -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g'`
-      sed "/^#/{s,$input_rx,,;s,$from,$2,;s,$FROM,$TO,;}" "$from" >"$target" ||
-      status=$?
+
+      sed -e "/^#/!b" -e "s,$input_rx,," -e "s,$from,$2," \
+          -e "s,$FROM,$TARGET," "$from" >"$target" || status=$?
+
+      # Check whether header files must be updated.
+      if test $first = no; then
+       if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then
+         echo "$2" is unchanged
+         rm -f "$target"
+       else
+          echo updating "$2"
+          mv -f "$target" "$realtarget"
+        fi
+      fi
     else
       # A missing file is only an error for the first file.  This
       # is a blatant hack to let us support using "yacc -d".  If -d
Index: tests/yacc6.test
===================================================================
RCS file: /cvs/automake/automake/tests/yacc6.test,v
retrieving revision 1.5
diff -u -r1.5 yacc6.test
--- tests/yacc6.test    14 Nov 2003 21:26:01 -0000      1.5
+++ tests/yacc6.test    18 Nov 2003 20:05:28 -0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2001, 2002  Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003  Free Software Foundation, Inc.
 #
 # This file is part of GNU Automake.
 #
@@ -20,33 +20,86 @@
 
 # Test to make sure ylwrap put in right location.
 # Report from Tim Van Holder.
+# Also make sure depcomp does not needlessly update headers.
+# Report from Paolo Bonzini.
 
+required='gcc bison'
 . ./defs || exit 1
 
-cat > configure.in << 'END'
-AC_INIT
-AM_INIT_AUTOMAKE(nonesuch, nonesuch)
+set -e
+
+cat >> configure.in << 'END'
+AC_CONFIG_AUX_DIR([aux])
 AC_PROG_CC
 AC_PROG_YACC
-AC_OUTPUT(Makefile sub/Makefile)
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
 END
 
 cat > Makefile.am << 'END'
 SUBDIRS = sub
+
+test-time-unchanged:
+       test `ls -1t sub/main.$(OBJEXT) z | sed 1q` = z
+test-time-changed:
+       test `ls -1t sub/main.$(OBJEXT) z | sed 1q` = sub/main.$(OBJEXT)
 END
 
-mkdir sub
+mkdir aux sub
 
 cat > sub/Makefile.am << 'END'
-bin_PROGRAMS = foo
-foo_SOURCES = foo.y bar.y
+bin_PROGRAMS = foo bar
+AM_YFLAGS = -d
+foo_SOURCES = foo.y main.c
+foo_CPPFLAGS = -DFOO
+bar_SOURCES = bar.y main.c
+END
+
+cat > sub/foo.y << 'END'
+%{
+int yylex () {return 0;}
+void yyerror (char *s) {}
+%}
+%token TOKEN
+%%
+foobar : 'f' 'o' 'o' 'b' 'a' 'r' {};
 END
 
-: > sub/foo.y
-: > sub/bar.y
+cp sub/foo.y sub/bar.y
 
-$ACLOCAL || exit 1
-$AUTOMAKE -a || exit 1
-test -f ylwrap || exit 1
-$FGREP '(srcdir)/ylwrap' sub/Makefile.in && exit 1
-exit 0
+cat >sub/main.c <<'EOF'
+#ifdef FOO
+#  include "foo.h"
+#else
+#  include "bar.h"
+#endif
+
+int
+main()
+{
+  return 0;
+}
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+test -f aux/ylwrap
+test ! -f ylwrap
+test ! -f sub/ylwrap
+$FGREP '(top_srcdir)/aux/ylwrap' sub/Makefile.in
+./configure
+$MAKE
+grep '#.*line.*foo.y' sub/foo.c
+grep '#.*line.*bar.y' sub/bar.c
+
+$sleep
+: > z
+$sleep
+touch sub/bar.y
+$MAKE
+$MAKE test-time-unchanged
+$sleep
+$PERL -pi -e s/TOKEN/TEKON/g sub/bar.y
+$MAKE
+$MAKE test-time-changed
Index: tests/yacc8.test
===================================================================
RCS file: /cvs/automake/automake/tests/yacc8.test,v
retrieving revision 1.12
diff -u -r1.12 yacc8.test
--- tests/yacc8.test    14 Nov 2003 21:26:01 -0000      1.12
+++ tests/yacc8.test    18 Nov 2003 20:05:28 -0000
@@ -39,6 +39,16 @@
 bin_PROGRAMS = foo/foo
 foo_foo_SOURCES = foo/parse.y
 AM_YFLAGS = -d
+
+obj: foo/parse.$(OBJEXT)
+
+test1: obj
+       test -f foo/parse.c
+       test -f foo/parse.$(OBJEXT)
+
+test2: obj
+       test -f foo/parse.c
+       test -f foo/parse.$(OBJEXT)
 END
 
 mkdir foo
@@ -60,9 +70,7 @@
 cd sub
 
 ../configure
-$MAKE foo/parse.o
-test -f foo/parse.c
-test -f foo/parse.o
+$MAKE test1
 
 # Aside of the rest of this test, let's see if we can recover from
 # parse.h removal
@@ -71,6 +79,18 @@
 $MAKE foo/parse.h
 test -f foo/parse.h
 
+# Make sure foo/parse.h is not updated, unless when needed.
+$sleep
+: > z
+$sleep
+touch ../foo/parse.y
+$MAKE obj
+test `ls -1t foo/parse.h z | sed 1q` = z
+$sleep
+$PERL -pi -e 's/%%/%token TOKEN\n%%/g' ../foo/parse.y
+$MAKE obj
+test `ls -1t foo/parse.h z | sed 1q` = foo/parse.h
+
 # Now, adds another parser to test ylwrap.
 
 cd ..
@@ -89,8 +109,4 @@
 cd sub
 # Regenerate Makefile (automatic in GNU Make, but not in other Makes)
 ./config.status
-$MAKE foo/parse2.o
-test -f foo/parse2.c
-test -f foo/parse2.o
-
-exit 0
+$MAKE test2
-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]