Previously, while automake did *not* distribute C source and header files derived from non-distributed Lex sources, it still caused them to be removed only by "make maintainer-clean" only, and not by simply "make clean" or "make distclean". This caused "make distcheck" to fail, unless the developer put those generated .c files in CLEANFILES or in DISTCLEANFILES by hand.
This change fixes this issue, by making non-distributed `.c' files generated by non-distributed Lex sources cleaned by "make clean". A similar problem for Yacc support had been fixed with the commit v1.11-263-ged2c8bc. * tests/automake.in (lang_lex_target_hook): Make C source files derived from non-distributed Lex files cleaned by "make clean", not only by "make maintainer-clean". * tests/lex-clean.test: New test. * tests/lex-clean-cxx.test: Likewise. * tests/lex-nodist.test: Likewise. * tests/lex-pr204.test: Likewise. * tests/pr204.test: For consistency, renamed ... * tests/yacc-pr204.test: ... to this, and updated to keep it more in sync with 'lex-pr204.test'. * tests/yacc-nodist.test: Updated to keep it more in sync with 'lex-nodist.test'. * tests/Makefile.am (TESTS): Update. * NEWS: Update. --- ChangeLog | 29 ++++++++ NEWS | 5 +- automake.in | 13 ++-- tests/Makefile.am | 6 ++- tests/Makefile.in | 6 ++- tests/lex-clean-cxx.test | 127 +++++++++++++++++++++++++++++++++ tests/lex-clean.test | 114 +++++++++++++++++++++++++++++ tests/lex-nodist.test | 83 +++++++++++++++++++++ tests/lex-pr204.test | 88 +++++++++++++++++++++++ tests/yacc-nodist.test | 13 ++-- tests/{pr204.test => yacc-pr204.test} | 12 ++- 11 files changed, 476 insertions(+), 20 deletions(-) create mode 100755 tests/lex-clean-cxx.test create mode 100755 tests/lex-clean.test create mode 100755 tests/lex-nodist.test create mode 100755 tests/lex-pr204.test rename tests/{pr204.test => yacc-pr204.test} (82%) diff --git a/ChangeLog b/ChangeLog index 2577f14..133a6aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2011-05-13 Stefano Lattarini <stefano.lattar...@gmail.com> + + lex: "make clean" removes .c files from non-distributed .l + Previously, while automake did *not* distribute C source and header + files derived from non-distributed Lex sources, it still caused + them to be removed only by "make maintainer-clean" only, and not by + simply "make clean" or "make distclean". + This caused "make distcheck" to fail, unless the developer put + those generated .c files in CLEANFILES or in DISTCLEANFILES by + hand. + This change fixes this issue, by making non-distributed `.c' files + generated by non-distributed Lex sources cleaned by "make clean". + A similar problem for Yacc support had been fixed with the commit + v1.11-263-ged2c8bc. + * tests/automake.in (lang_lex_target_hook): Make C source files + derived from non-distributed Lex files cleaned by "make clean", + not only by "make maintainer-clean". + * tests/lex-clean.test: New test. + * tests/lex-clean-cxx.test: Likewise. + * tests/lex-nodist.test: Likewise. + * tests/lex-pr204.test: Likewise. + * tests/pr204.test: For consistency, renamed ... + * tests/yacc-pr204.test: ... to this, and updated to keep it + more in sync with 'lex-pr204.test'. + * tests/yacc-nodist.test: Updated to keep it more in sync with + 'lex-nodist.test'. + * tests/Makefile.am (TESTS): Update. + * NEWS: Update. + 2011-05-13 Stefano Lattarini <stefano.lattar...@gmail.com> lex tests: make test on Lex dependency tracking more "semantic" diff --git a/NEWS b/NEWS index 80e0cfc..f861868 100644 --- a/NEWS +++ b/NEWS @@ -7,8 +7,9 @@ New in 1.11.0a: * Changes to Yacc support: - - C source and header files derived from non-distributed Yacc sources are - now removed by "make clean", not only by "make maintainer-clean". + - C source and header files derived from non-distributed Yacc and/or + Lex sources are now removed by a simple "make clean" (while they were + previously removed only "make maintainer-clean"). - Slightly backward-incompatible change, relevant only for use of Yacc with C++: the extensions of the header files produced by the Yacc diff --git a/automake.in b/automake.in index de0833c..83d9119 100755 --- a/automake.in +++ b/automake.in @@ -6151,13 +6151,12 @@ sub lang_yacc_target_hook # compile a lex file. sub lang_lex_target_hook { - my ($self, $aggregate, $output, $input) = @_; - # If the files are built in the build directory, then we want to - # remove them with `make clean'. If they are in srcdir they - # shouldn't be touched. However, we can't determine this - # statically, and the GNU rules say that yacc/lex output files - # should be removed by maintainer-clean. So that's what we do. - $clean_files{$output} = MAINTAINER_CLEAN; + my ($self, $aggregate, $output, $input, %transform) = @_; + # The GNU rules say that yacc/lex output files should be removed + # by maintainer-clean. However, if the files are not distributed, + # then we want to remove them with "make clean"; otherwise, + # "make distcheck" will fail. + $clean_files{$output} = $transform{'DIST_SOURCE'} ? MAINTAINER_CLEAN : CLEAN; } # This is a helper for both lex and yacc. diff --git a/tests/Makefile.am b/tests/Makefile.am index 76be331..6257975 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -445,10 +445,14 @@ lex3.test \ lex5.test \ lexcpp.test \ lexvpath.test \ +lex-clean.test \ +lex-clean-cxx.test \ lex-depend.test \ lex-depend-cxx.test \ lex-depend-grep.test \ lex-line.test \ +lex-nodist.test \ +lex-pr204.test \ lex-subobj-nodep.test \ lflags.test \ lflags2.test \ @@ -618,7 +622,6 @@ pr2.test \ pr9.test \ pr72.test \ pr87.test \ -pr204.test \ pr211.test \ pr220.test \ pr224.test \ @@ -858,6 +861,7 @@ yacc-deleted-headers.test \ yacc-dist-nobuild.test \ yacc-dist-nobuild-subdir.test \ yacc-nodist.test \ +yacc-pr204.test \ yaccpp.test \ yaccvpath.test \ yacc-d-vpath.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index c990062..2a13346 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -716,10 +716,14 @@ lex3.test \ lex5.test \ lexcpp.test \ lexvpath.test \ +lex-clean.test \ +lex-clean-cxx.test \ lex-depend.test \ lex-depend-cxx.test \ lex-depend-grep.test \ lex-line.test \ +lex-nodist.test \ +lex-pr204.test \ lex-subobj-nodep.test \ lflags.test \ lflags2.test \ @@ -889,7 +893,6 @@ pr2.test \ pr9.test \ pr72.test \ pr87.test \ -pr204.test \ pr211.test \ pr220.test \ pr224.test \ @@ -1129,6 +1132,7 @@ yacc-deleted-headers.test \ yacc-dist-nobuild.test \ yacc-dist-nobuild-subdir.test \ yacc-nodist.test \ +yacc-pr204.test \ yaccpp.test \ yaccvpath.test \ yacc-d-vpath.test \ diff --git a/tests/lex-clean-cxx.test b/tests/lex-clean-cxx.test new file mode 100755 index 0000000..3400977 --- /dev/null +++ b/tests/lex-clean-cxx.test @@ -0,0 +1,127 @@ +#! /bin/sh +# Copyright (C) 2011 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 +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + +# Check that C++ source and header files derived from non-distributed +# Yacc sources are cleaned by "make clean", while C++ source and +# header files derived from distributed Yacc sources are cleaned by +# "make maintainer-clean". +# See also sister test `lex-clean.test'. + +required=lex +. ./defs || Exit 1 + +set -e + +cat >> configure.in << 'END' +AC_PROG_CXX +AC_PROG_LEX +AC_OUTPUT +END + +cat > Makefile.am << 'END' +bin_PROGRAMS = foo bar baz qux + +foo_SOURCES = mainfoo.cc parsefoo.lxx + +bar_SOURCES = mainbar.cpp parsebar.ll +bar_LFLAGS = $(AM_LFLAGS) + +baz_SOURCES = mainbaz.c++ +nodist_baz_SOURCES = parsebaz.l++ + +qux_SOURCES = mainqux.cxx +nodist_qux_SOURCES = parsequx.lpp +qux_LFLAGS = $(AM_LFLAGS) + +parsebaz.l++ parsequx.lpp: + cp $(srcdir)/parsefoo.lxx $@ + +CLEANFILES = parsebaz.l++ parsequx.lpp + +LDADD = $(LEXLIB) +END + +cat > parsefoo.lxx << 'END' +%% +"GOOD" return EOF; +. +END +cp parsefoo.lxx parsebar.ll + +cat > mainfoo.cc << 'END' +// This file should contain valid C++ but invalid C. +using namespace std; +int main (int argc, char **argv) +{ + extern int yylex (void); + return yylex (); +} +END +cp mainfoo.cc mainbar.cpp +cp mainfoo.cc mainbaz.c++ +cp mainfoo.cc mainqux.cxx + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +./configure + +cp config.status config.sav + +$MAKE +ls -l +# Sanity checks. +test -f parsefoo.cxx +test -f bar-parsebar.cc +test -f parsebaz.l++ +test -f parsebaz.c++ +test -f parsequx.lpp +test -f qux-parsequx.cpp + +for target in clean distclean; do + $MAKE $target + ls -l + test -f parsefoo.cxx + test -f bar-parsebar.cc + test ! -r parsebaz.l++ + test ! -r parsebaz.c++ + test ! -r parsequx.lpp + test ! -r qux-parsequx.cpp +done + +cp config.sav config.status +./config.status # re-create Makefile + +$MAKE maintainer-clean +ls -l +test -f parsefoo.lxx +test -f parsebar.ll +test ! -r parsefoo.cxx +test ! -r bar-parsebar.cc +test -f parsefoo.lxx +test -f parsebar.ll +test ! -r parsefoo.cxx +test ! -r bar-parsebar.cc + +cp config.sav config.status +./config.status # re-create Makefile + +# The distribution must work correctly, assuming the user has +# the proper tools to process yacc files. +$MAKE distcheck + +: diff --git a/tests/lex-clean.test b/tests/lex-clean.test new file mode 100755 index 0000000..dd36f80 --- /dev/null +++ b/tests/lex-clean.test @@ -0,0 +1,114 @@ +#! /bin/sh +# Copyright (C) 2011 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 +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + +# Check that .c files derived from non-distributed .l sources +# are cleaned by "make clean", while .c files derived from +# distributed .l sources are cleaned by "make maintainer-clean". +# See also sister test `lex-clean-cxx.test'. + +required=yacc +. ./defs || Exit 1 + +set -e + +cat >> configure.in << 'END' +AC_PROG_CC +AC_PROG_LEX +AC_OUTPUT +END + +cat > Makefile.am << 'END' +bin_PROGRAMS = foo bar baz qux + +foo_SOURCES = main.c lexer.l + +bar_SOURCES = main.c lexer.l +bar_LFLAGS = $(AM_LFLAGS) + +baz_SOURCES = main.c +nodist_baz_SOURCES = baz.l + +qux_SOURCES = main.c +nodist_qux_SOURCES = baz.l +qux_LFLAGS = $(AM_LFLAGS) + +baz.l: + cp $(srcdir)/lexer.l $@ + +CLEANFILES = baz.l + +LDADD = $(LEXLIB) +END + +cat > lexer.l << 'END' +%% +"GOOD" return EOF; +. +END + +cat > main.c << 'END' +int main (void) +{ + return yylex (); +} +END + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +./configure + +cp config.status config.sav + +$MAKE +ls -l +# Sanity checks. +test -f lexer.l +test -f lexer.c +test -f bar-lexer.c +test -f baz.l +test -f baz.c +test -f qux-baz.c + +for target in clean distclean; do + $MAKE $target + ls -l + test -f lexer.l + test -f lexer.c + test -f bar-lexer.c + test ! -r baz.l + test ! -r baz.c + test ! -r qux-baz.c +done + +cp config.sav config.status +./config.status # re-create Makefile + +$MAKE maintainer-clean +ls -l +test -f lexer.l +test ! -r lexer.c +test ! -r bar-lexer.c + +cp config.sav config.status +./config.status # re-create Makefile + +# The distribution must work correctly, assuming the user has +# the proper tools to process yacc files. +$MAKE distcheck + +: diff --git a/tests/lex-nodist.test b/tests/lex-nodist.test new file mode 100755 index 0000000..5948400 --- /dev/null +++ b/tests/lex-nodist.test @@ -0,0 +1,83 @@ +#! /bin/sh +# Copyright (C) 2011 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 +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + +# Checks for .c files derived from non-distributed .l sources. +# The test `lex-pr204.test' does similar check with AM_MAINTAINER_MODE +# enabled. +# The tests 'yacc-nodist.test' and 'yacc-pr204.test' does similar checks +# for yacc-generated .c and .h files. + +required=lex +. ./defs || Exit 1 + +set -e + +cat >> configure.in << 'END' +AC_PROG_CC +dnl Sister test 'lex-pr204.test' should use 'AC_PROG_LEX' instead. +AM_PROG_LEX +AC_OUTPUT +END + +cat > Makefile.am << 'END' +.PHONY: test-build test-dist +test-build: all + ls -l + test -f lexer.l + test -f lexer.c +test-dist: distdir + ls -l $(distdir) + test ! -r $(distdir)/lexer.l + test ! -r $(distdir)/lexer.c +check-local: test-build test-dist + +lexer.l: + rm -f $@ $@-t + :; { : \ + && echo '%%' \ + && echo '"GOOD" return EOF;' \ + && echo '.'; \ + } > $@-t + chmod a-w $@-t && mv -f $@-t $@ + +bin_PROGRAMS = prog +prog_SOURCES = main.c +nodist_prog_SOURCES = lexer.l +prog_LDADD = $(LEXLIB) +CLEANFILES = $(nodist_prog_SOURCES) +END + +cat > main.c << 'END' +int main () +{ + return yylex (); +} +END + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +./configure +$MAKE +$MAKE test-build +$MAKE test-dist + +# But the distribution must work correctly, assuming the user has +# the proper tools to process yacc files. +$MAKE distcheck + +: diff --git a/tests/lex-pr204.test b/tests/lex-pr204.test new file mode 100755 index 0000000..095d611 --- /dev/null +++ b/tests/lex-pr204.test @@ -0,0 +1,88 @@ +#! /bin/sh +# Copyright (C) 2011 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 +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + +# Related to PR 204. +# C sources derived from nodist_ lex sources should not be distributed. +# See also related test `lex-nodist.test'. +# The tests 'yacc-nodist.test' and 'yacc-pr204.test' does similar checks +# for yacc-generated .c and .h files. + +required=lex +. ./defs || Exit 1 + +set -e + +cat >> configure.in <<'EOF' +AM_MAINTAINER_MODE +AC_PROG_CC +dnl We use AC_PROG_LEX deliberately. +dnl Sister 'lex-nodist.test' should use 'AM_PROG_LEX' instead. +AC_PROG_LEX +AC_OUTPUT +EOF + +# The LEXER2 intermediate variable is there to make sure Automake +# matches 'nodist_' against the right variable name... +cat > Makefile.am << 'EOF' +EXTRA_PROGRAMS = foo +LEXER2 = lexer2.l +nodist_foo_SOURCES = lexer.l $(LEXER2) + +distdirtest: distdir + test ! -f $(distdir)/lexer.c + test ! -f $(distdir)/lexer.l + test ! -f $(distdir)/lexer.h + test ! -f $(distdir)/lexer2.c + test ! -f $(distdir)/lexer2.l + test ! -f $(distdir)/lexer2.h +EOF + +cat > lexer.l << 'END' +%% +"GOOD" return EOF; +. +%% +int main (void) +{ + return yylex (); +} +END + +cp lexer.l lexer2.l + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +./configure +$MAKE distdirtest + +# Make sure lexer.c and lexer2.c are still targets. +$MAKE lexer.c lexer2.c +test -f lexer.c +test -f lexer2.c + +# Ensure the rebuild rule works despite AM_MAINTAINER_MODE, because +# it's a nodist_ lexer. +$sleep +touch lexer.l lexer2.l +$sleep +$MAKE lexer.c lexer2.c +stat lexer.c lexer.l lexer2.c lexer2.l || : # For debugging. +test `ls -t lexer.c lexer.l | sed 1q` = lexer.c +test `ls -t lexer2.c lexer2.l | sed 1q` = lexer2.c + +: diff --git a/tests/yacc-nodist.test b/tests/yacc-nodist.test index ab2af66..846e247 100755 --- a/tests/yacc-nodist.test +++ b/tests/yacc-nodist.test @@ -14,8 +14,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -# Checks for .c and .h files derived from non-distributed .y sources. -# The test `pr204' does similar check with AM_MAINTAINER_MODE enabled. +# Checks for .c and .h files derived from non-distributed yacc sources. +# The test 'yacc-pr204.test' does similar check with AM_MAINTAINER_MODE +# enabled. +# The tests 'lex-nodist.test' and 'lex-pr204.test' does similar checks +# for lex-generated .c files. required=yacc . ./defs || Exit 1 @@ -31,7 +34,7 @@ END cat > Makefile.am << 'END' SUBDIRS = sub1 sub2 -.PHONY: test +.PHONY: test-build test-dist test-build: all ls -l . sub1 sub2 test -f sub1/parse.y @@ -63,8 +66,8 @@ parse.y: && echo "%%" \ && echo "maude : 'm' 'a' 'u' 'd' 'e' {}"; \ } > $@-t - chmod a-w $@-t - mv -f $@-t $@ + chmod a-w $@-t && mv -f $@-t $@ + bin_PROGRAMS = prog prog_SOURCES = main.c nodist_prog_SOURCES = parse.y diff --git a/tests/pr204.test b/tests/yacc-pr204.test similarity index 82% rename from tests/pr204.test rename to tests/yacc-pr204.test index 64032c7..a1c3691 100755 --- a/tests/pr204.test +++ b/tests/yacc-pr204.test @@ -15,10 +15,12 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # For PR 204. -# Sources derived from nodist_ sources should not be distributed. +# C sources derived from nodist_ yacc sources should not be distributed. # See also related test `yacc-nodist.test'. +# The tests 'lex-nodist.test' and 'lex-pr204.test' does similar checks +# for lex-generated C files. -required='yacc gcc' +required=yacc . ./defs || Exit 1 set -e @@ -74,9 +76,11 @@ test -f parse2.c # Ensure the rebuild rule works despite AM_MAINTAINER_MODE, because # it's a nodist_ parser. $sleep -touch parse.y +touch parse.y parse2.y $sleep $MAKE parse.c parse2.c -test `ls -1t parse.c parse.y | sed 1q` = parse.c +stat parse.c parse.y parse2.c parse2.y || : # For debugging. +test `ls -t parse.c parse.y | sed 1q` = parse.c +test `ls -t parse2.c parse2.y | sed 1q` = parse2.c : -- 1.7.2.3