From: Alexandre Duret-Lutz Date: Tue, 18 Nov 2003 20:06:43 +0000 (+0000) Subject: * lib/ylwrap: Do not overwrite headers if they haven't changed. X-Git-Tag: Release-1-7d~3 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=ce7c5cd7def9f966c7c8407d62d154e4993bf383;p=automake.git * 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. --- diff --git a/ChangeLog b/ChangeLog index 20f0fb35..7a9440d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2003-11-18 Paolo Bonzini + Alexandre Duret-Lutz + + * 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. + 2003-11-17 Alexandre Duret-Lutz * automake.in (generate_makefile): Define SUBDIRS if it is diff --git a/NEWS b/NEWS index 66b2386b..58752da6 100644 --- a/NEWS +++ b/NEWS @@ -206,6 +206,9 @@ New in 1.7c: 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. diff --git a/lib/ylwrap b/lib/ylwrap index f5d0c30f..f86e2173 100755 --- a/lib/ylwrap +++ b/lib/ylwrap @@ -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 @@ if test $status -eq 0; then *) 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 @@ if test $status -eq 0; then 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 diff --git a/tests/yacc6.test b/tests/yacc6.test index 2b153589..108bc20b 100755 --- a/tests/yacc6.test +++ b/tests/yacc6.test @@ -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 + +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 -$ACLOCAL || exit 1 -$AUTOMAKE -a || exit 1 -test -f ylwrap || exit 1 -$FGREP '(srcdir)/ylwrap' sub/Makefile.in && exit 1 -exit 0 +$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 diff --git a/tests/yacc8.test b/tests/yacc8.test index 3d93ccce..40009b86 100755 --- a/tests/yacc8.test +++ b/tests/yacc8.test @@ -39,6 +39,16 @@ AUTOMAKE_OPTIONS = subdir-objects 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 @@ mkdir sub 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 @@ rm -f foo/parse.h $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 @@ test -f ./ylwrap || exit 1 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