From 16e08014a193dd5fadf043bcbdfa9f7735115af6 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Sun, 1 Aug 2004 17:31:22 +0000 Subject: [PATCH] Disable Lex and Yacc rules whenever possible if AM_MAINTAINER_MODE is used and maintainer-mode disabled. * automake.in (Automake::struct): Define nodist_specific. Set it in languages yacc, yaccxx, lex, and lexxx. (register_language): Default nodist_specific to 0. (handle_single_transform): Honor nodist_specific. * lib/am/yacc.am (am__skipyacc): Define this in maintainer mode. (%EXT%%DERIVED-EXT%, %OBJ%): Use $(am__skipyacc) to disable these rules when needed. * lib/am/lex.am (am__skiplex): Define this in maintainer mode. (%EXT%%DERIVED-EXT%, %OBJ%): Use $(am__skiplex) to disable these rules when needed. * tests/mmodely.test: New file. * tests/pr204.test: Augment to check AM_MAINTAINER_MODE and nodist_ parsers. * tests/Makefile.am (TESTS): ADd mmodely.test. * doc/automake.texi (Yacc and Lex): Note dependence on maintainer mode. --- ChangeLog | 21 ++++++++++++ NEWS | 4 +++ automake.in | 27 ++++++++++++---- doc/automake.texi | 3 ++ doc/stamp-vti | 2 +- doc/version.texi | 2 +- lib/am/lex.am | 21 +++++++++--- lib/am/yacc.am | 42 +++++++++++++++++++++--- tests/Makefile.am | 1 + tests/Makefile.in | 1 + tests/mmodely.test | 79 ++++++++++++++++++++++++++++++++++++++++++++++ tests/pr204.test | 29 ++++++++++++----- 12 files changed, 205 insertions(+), 27 deletions(-) create mode 100755 tests/mmodely.test diff --git a/ChangeLog b/ChangeLog index b0b211b23..02a5fdb4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2004-08-01 Alexandre Duret-Lutz + Derek R. Price + + Disable Lex and Yacc rules whenever possible if AM_MAINTAINER_MODE + is used and maintainer-mode disabled. + * automake.in (Automake::struct): Define nodist_specific. + Set it in languages yacc, yaccxx, lex, and lexxx. + (register_language): Default nodist_specific to 0. + (handle_single_transform): Honor nodist_specific. + * lib/am/yacc.am (am__skipyacc): Define this in maintainer mode. + (%EXT%%DERIVED-EXT%, %OBJ%): Use $(am__skipyacc) to disable these + rules when needed. + * lib/am/lex.am (am__skiplex): Define this in maintainer mode. + (%EXT%%DERIVED-EXT%, %OBJ%): Use $(am__skiplex) to disable these + rules when needed. + * tests/mmodely.test: New file. + * tests/pr204.test: Augment to check AM_MAINTAINER_MODE and nodist_ + parsers. + * tests/Makefile.am (TESTS): ADd mmodely.test. + * doc/automake.texi (Yacc and Lex): Note dependence on maintainer mode. + 2004-07-28 Alexandre Duret-Lutz * configure.ac, NEWS: Bump version to 1.9a. diff --git a/NEWS b/NEWS index 359cc0fe0..266f3872f 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,8 @@ New in 1.9a: + + - The rebuild rules for distributed Yacc and Lex output will avoid + overwriting existing files if AM_MAINTAINER_MODE and maintainer-mode + is not enabled. New in 1.9: diff --git a/automake.in b/automake.in index fdad1800c..5a3b4bd33 100755 --- a/automake.in +++ b/automake.in @@ -100,7 +100,11 @@ struct (# Short name of the language (c, f77...). # This is a subroutine which is called whenever we finally # determine the context in which a source file will be # compiled. - '_target_hook' => "\$"); + '_target_hook' => "\$", + + # If TRUE, nodist_ sources will be compiled using specific rules + # (i.e. not inference rules). The default is FALSE. + 'nodist_specific' => "\$"); sub finish ($) @@ -732,7 +736,8 @@ register_language ('name' => 'yacc', return ($ext,) }, 'rule_file' => 'yacc', '_finish' => \&lang_yacc_finish, - '_target_hook' => \&lang_yacc_target_hook); + '_target_hook' => \&lang_yacc_target_hook, + 'nodist_specific' => 1); register_language ('name' => 'yaccxx', 'Name' => 'Yacc (C++)', 'config_vars' => ['YACC'], @@ -744,7 +749,8 @@ register_language ('name' => 'yaccxx', 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/y/c/; return ($ext,) }, '_finish' => \&lang_yacc_finish, - '_target_hook' => \&lang_yacc_target_hook); + '_target_hook' => \&lang_yacc_target_hook, + 'nodist_specific' => 1); # Lex (C & C++). register_language ('name' => 'lex', @@ -758,7 +764,8 @@ register_language ('name' => 'lex', 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/; return ($ext,) }, '_finish' => \&lang_lex_finish, - '_target_hook' => \&lang_lex_target_hook); + '_target_hook' => \&lang_lex_target_hook, + 'nodist_specific' => 1); register_language ('name' => 'lexxx', 'Name' => 'Lex (C++)', 'config_vars' => ['LEX'], @@ -770,7 +777,8 @@ register_language ('name' => 'lexxx', 'output_extensions' => sub { (my $ext = $_[0]) =~ tr/l/c/; return ($ext,) }, '_finish' => \&lang_lex_finish, - '_target_hook' => \&lang_lex_target_hook); + '_target_hook' => \&lang_lex_target_hook, + 'nodist_specific' => 1); # Assembler. register_language ('name' => 'asm', @@ -1643,8 +1651,11 @@ sub handle_single_transform ($$$$$%) # Using inference rules for subdir-objects has been tested # with GNU make, Solaris make, Ultrix make, BSD make, # HP-UX make, and OSF1 make successfully. - if ($renamed || - ($directory ne '' && ! option 'subdir-objects')) + if ($renamed + || ($directory ne '' && ! option 'subdir-objects') + # We must also use specific rules for a nodist_ source + # if its language requests it. + || ($lang->nodist_specific && ! $transform{'DIST_SOURCE'})) { my $obj_sans_ext = substr ($object, 0, - length ($this_obj_ext)); @@ -5447,6 +5458,8 @@ sub register_language (%) unless defined $option{'flags'}; $option{'output_extensions'} = sub { return ( '.$(OBJEXT)', '.lo' ) } unless defined $option{'output_extensions'}; + $option{'nodist_specific'} = 0 + unless defined $option{'nodist_specific'}; my $lang = new Language (%option); diff --git a/doc/automake.texi b/doc/automake.texi index a01c6821b..0fac2d93d 100644 --- a/doc/automake.texi +++ b/doc/automake.texi @@ -3765,6 +3765,9 @@ When @code{lex} is invoked, it is passed @samp{LFLAGS} and @samp{AM_LFLAGS}. The former is a user variable and the latter is intended for the @file{Makefile.am} author. +When @code{AM_MAINTAINER_MODE} (@pxref{maintainer-mode}) is used, the +rebuild rule for distributed Yacc and Lex sources are only used when +@code{maintainer-mode} is enabled, or when the files have been erased. @cindex ylwrap diff --git a/doc/stamp-vti b/doc/stamp-vti index 45e6d352a..a3b24499d 100644 --- a/doc/stamp-vti +++ b/doc/stamp-vti @@ -1,4 +1,4 @@ -@set UPDATED 28 July 2004 +@set UPDATED 29 July 2004 @set UPDATED-MONTH July 2004 @set EDITION 1.9a @set VERSION 1.9a diff --git a/doc/version.texi b/doc/version.texi index 45e6d352a..a3b24499d 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -1,4 +1,4 @@ -@set UPDATED 28 July 2004 +@set UPDATED 29 July 2004 @set UPDATED-MONTH July 2004 @set EDITION 1.9a @set VERSION 1.9a diff --git a/lib/am/lex.am b/lib/am/lex.am index 9ce16f9d0..645cbe6d1 100644 --- a/lib/am/lex.am +++ b/lib/am/lex.am @@ -1,5 +1,5 @@ ## automake - create Makefile.in from Makefile.am -## Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +## Copyright (C) 2001, 2002, 2003, 2004 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 @@ -16,17 +16,28 @@ ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ## 02111-1307, USA. +## See the comment about am__skipyacc in yacc.am. +if %?MAINTAINER-MODE% +if %?FIRST% +@MAINTAINER_MODE_FALSE@am__skiplex = test -f $@ || +endif %?FIRST% +endif %?MAINTAINER-MODE% + ?GENERIC?%EXT%%DERIVED-EXT%: ?!GENERIC?%OBJ%: %SOURCE% if %?MORE-THAN-ONE% -?GENERIC? $(SHELL) $(YLWRAP) %SOURCE% $(LEX_OUTPUT_ROOT).c %OBJ% -- %COMPILE% +?GENERIC? $(am__skiplex) $(SHELL) $(YLWRAP) %SOURCE% $(LEX_OUTPUT_ROOT).c %OBJ% -- %COMPILE% +?!GENERIC??DIST_SOURCE? $(am__skiplex) \ ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%. ?!GENERIC? $(SHELL) $(YLWRAP) `test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% $(LEX_OUTPUT_ROOT).c %OBJ% -- %COMPILE% else !%?MORE-THAN-ONE% -?GENERIC? %COMPILE% %SOURCE% +?GENERIC? $(am__skiplex) %COMPILE% %SOURCE% +?!GENERIC??DIST_SOURCE? $(am__skiplex) \ ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%. ?!GENERIC? %COMPILE% `test -f %SOURCE% || echo '$(srcdir)/'`%SOURCE% ## Edit out `#line' or `#' directives. - sed '/^#/ s|$(LEX_OUTPUT_ROOT)\.c|%OBJ%|' $(LEX_OUTPUT_ROOT).c >%OBJ% - rm -f $(LEX_OUTPUT_ROOT).c +?GENERIC? $(am__skiplex) \ +?!GENERIC??DIST_SOURCE? $(am__skiplex)\ + { sed '/^#/ s|$(LEX_OUTPUT_ROOT)\.c|%OBJ%|' $(LEX_OUTPUT_ROOT).c >%OBJ% && \ + rm -f $(LEX_OUTPUT_ROOT).c; } endif !%?MORE-THAN-ONE% diff --git a/lib/am/yacc.am b/lib/am/yacc.am index cc799c49a..4655f0631 100644 --- a/lib/am/yacc.am +++ b/lib/am/yacc.am @@ -1,5 +1,5 @@ ## automake - create Makefile.in from Makefile.am -## Copyright (C) 1998, 1999, 2001, 2002, 2003 Free Software Foundation, Inc. +## Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004 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 @@ -16,19 +16,47 @@ ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ## 02111-1307, USA. +## We want to disable the Yacc rebuild rule when +## 1. AM_MAINTAINER_MODE is used, and +## 2. --enable-maintainer-mode is not specified, and +## 3. parser.c already exist, and +## 4. parser.y and parser.c are distributed. +## Point #3 is because `make maintainer-clean' erases parser.c, yet +## the GNU Coding Standards require that ./configure; make works even +## after that. +## Point #4 is because parsers listed in nodist_*_SOURCES are always +## built on the user's side, so it makes no sense to disable them. +## +## Points #1, #2, #3 are solved by unconditionally prefixing the rules +## with $(am__skipyacc) defined below only when needed. +## +## Point #4 requires a condition on whether parser.y/parser.c are +## distributed or not. We cannot have a generic rule that works in +## both cases, so we ensure in automake that nodist_ parsers always +## use non-generic rules. +if %?MAINTAINER-MODE% +if %?FIRST% +@MAINTAINER_MODE_FALSE@am__skipyacc = test -f $@ || +endif %?FIRST% +endif %?MAINTAINER-MODE% + ?GENERIC?%EXT%%DERIVED-EXT%: ?!GENERIC?%OBJ%: %SOURCE% if %?MORE-THAN-ONE% -?GENERIC? $(SHELL) $(YLWRAP) %SOURCE% y.tab.c %OBJ% y.tab.h %BASE%.h y.output %BASE%.output -- %COMPILE% +?GENERIC? $(am__skipyacc) $(SHELL) $(YLWRAP) %SOURCE% y.tab.c %OBJ% y.tab.h %BASE%.h y.output %BASE%.output -- %COMPILE% +?!GENERIC??DIST_SOURCE? $(am__skipyacc) \ ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%. ?!GENERIC? $(SHELL) $(YLWRAP) `test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% y.tab.c %OBJ% y.tab.h %BASE%.h y.output %BASE%.output -- %COMPILE% else !%?MORE-THAN-ONE% -?GENERIC? %COMPILE% %SOURCE% +?GENERIC? $(am__skipyacc) %COMPILE% %SOURCE% +?!GENERIC??DIST_SOURCE? $(am__skipyacc) \ ## For non-suffix rules, we must emulate a VPATH search on %SOURCE%. ?!GENERIC? %COMPILE% `test -f '%SOURCE%' || echo '$(srcdir)/'`%SOURCE% ## Edit out Bison multiple inclusion guards. It may be BISON_Y_TAB_H, ## or Y_TAB_H depending upon the version, that's why the regexp is ## so loose. +?GENERIC? $(am__skipyacc) \ +?!GENERIC??DIST_SOURCE? $(am__skipyacc) \ if test -f y.tab.h; then \ to=`echo "%BASE%_H" | sed \ -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \ @@ -41,10 +69,14 @@ else !%?MORE-THAN-ONE% mv %BASE%.ht %BASE%.h; \ fi; \ fi +?GENERIC? $(am__skipyacc) \ +?!GENERIC??DIST_SOURCE? $(am__skipyacc) \ if test -f y.output; then \ mv y.output %BASE%.output; \ fi +?GENERIC? $(am__skipyacc) \ +?!GENERIC??DIST_SOURCE? $(am__skipyacc) \ ## Edit out `#line' or `#' directives. - sed '/^#/ s|y\.tab\.c|%OBJ%|' y.tab.c >%OBJ%t && mv %OBJ%t %OBJ% - rm -f y.tab.c + { sed '/^#/ s|y\.tab\.c|%OBJ%|' y.tab.c >%OBJ%t && mv %OBJ%t %OBJ% && \ + rm -f y.tab.c; } endif !%?MORE-THAN-ONE% diff --git a/tests/Makefile.am b/tests/Makefile.am index 12fabd94a..d62c7d84c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -333,6 +333,7 @@ missing.test \ missing2.test \ mkinst2.test \ mkinstall.test \ +mmodely.test \ multlib.test \ nobase.test \ nodef.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 875f8434d..61d760a03 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -449,6 +449,7 @@ missing.test \ missing2.test \ mkinst2.test \ mkinstall.test \ +mmodely.test \ multlib.test \ nobase.test \ nodef.test \ diff --git a/tests/mmodely.test b/tests/mmodely.test new file mode 100755 index 000000000..d687da5e8 --- /dev/null +++ b/tests/mmodely.test @@ -0,0 +1,79 @@ +#! /bin/sh +# Copyright (C) 2004 Free Software Foundation, Inc. +# +# This file is part of GNU Automake. +# +# GNU Automake is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# GNU Automake is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Automake; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +# Verify that intermediate files are only built from Yacc and Lex +# sources in maintainer mode. +# From Derek R. Price. + +required=gcc +. ./defs || exit 1 + +set -e + +cat >> configure.in << 'END' +AM_MAINTAINER_MODE +AC_PROG_CC +AM_PROG_LEX +AC_PROG_YACC +AC_OUTPUT +END + +cat > Makefile.am <<'END' +YACC = false +LEX = false +bin_PROGRAMS = zardoz +zardoz_SOURCES = zardoz.y joe.l +LDADD = @LEXLIB@ +END + +# The point of this test is that it is not dependant on a working lex or yacc. +cat > joe.c < zardoz.c < joe.l +: > zardoz.y + +$ACLOCAL +$AUTOCONF +$AUTOMAKE + +./configure +$MAKE + +# make maintainer-clean; ./configure; make should always work, +# per GNU Standard. +$MAKE maintainer-clean +./configure +YACC='echo>y.tab.c' LEX='echo>lex.yy.c' $MAKE -e zardoz.c joe.c +grep zardoz.y zardoz.c +grep joe.l joe.c diff --git a/tests/pr204.test b/tests/pr204.test index 26c861110..752800b66 100755 --- a/tests/pr204.test +++ b/tests/pr204.test @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 2002 Free Software Foundation, Inc. +# Copyright (C) 2002, 2004 Free Software Foundation, Inc. # # This file is part of GNU Automake. # @@ -29,6 +29,7 @@ set -e cat > configure.in <<'EOF' AC_INIT(pr204, 0.1) AM_INIT_AUTOMAKE +AM_MAINTAINER_MODE AC_PROG_CC AC_PROG_YACC AC_CONFIG_FILES(Makefile) @@ -43,6 +44,14 @@ AM_YFLAGS = -d EXTRA_PROGRAMS = foo PARSE2 = parse2.y nodist_foo_SOURCES = parse.y $(PARSE2) + +distdirtest: distdir + test ! -f $(distdir)/parse.c + test ! -f $(distdir)/parse.y + test ! -f $(distdir)/parse.h + test ! -f $(distdir)/parse2.c + test ! -f $(distdir)/parse2.y + test ! -f $(distdir)/parse2.h EOF cat > parse.y << 'END' @@ -60,12 +69,16 @@ $ACLOCAL $AUTOCONF $AUTOMAKE -a ./configure -$MAKE distdir -test -f pr204-0.1/parse.c && exit 1 -test -f pr204-0.1/parse.y && exit 1 -test -f pr204-0.1/parse.h && exit 1 -test -f pr204-0.1/parse2.c && exit 1 -test -f pr204-0.1/parse2.y && exit 1 -test -f pr204-0.1/parse2.h && exit 1 +$MAKE distdirtest # Make sure parse.c and parse2.c are still targets. $MAKE parse.c parse2.c +test -f parse.c +test -f parse2.c + +# Ensure the rebuild rule works despite AM_MAINTAINER_MODE, because +# it's a nodist_ parser. +$sleep +touch parse.y +$sleep +$MAKE parse.c parse2.c +test `ls -1t parse.c parse.y | sed 1q` = parse.c -- 2.47.2