]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
lex: "make clean" removes .c files from non-distributed .l
authorStefano Lattarini <stefano.lattarini@gmail.com>
Fri, 13 May 2011 18:51:50 +0000 (20:51 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Sat, 14 May 2011 14:20:51 +0000 (16:20 +0200)
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
NEWS
automake.in
tests/Makefile.am
tests/Makefile.in
tests/lex-clean-cxx.test [new file with mode: 0755]
tests/lex-clean.test [new file with mode: 0755]
tests/lex-nodist.test [new file with mode: 0755]
tests/lex-pr204.test [new file with mode: 0755]
tests/yacc-nodist.test
tests/yacc-pr204.test [moved from tests/pr204.test with 82% similarity]

index 2577f14281006c663ccc8eaf6e155911a8cb76ec..133a6aac52cb7f6a8f27edfcc05412d7417ab79d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2011-05-13   Stefano Lattarini  <stefano.lattarini@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.lattarini@gmail.com>
 
        lex tests: make test on Lex dependency tracking more "semantic"
diff --git a/NEWS b/NEWS
index 80e0cfc59d0734f945fc21757159e3c718f56df4..f8618680d421cc57954a2e50010131d1d5cdea80 100644 (file)
--- 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
index de0833c345a280c38a311c2358451c793550b2b9..83d9119ca85bf6a6c8dc9f7f93bbdc178bddffd0 100755 (executable)
@@ -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.
index 76be331b2d22a916ccc4313ecdba02ee8a14f9d9..62579757d4b4a0ff66978558d37892bb6ca687e1 100644 (file)
@@ -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 \
index c99006207b9e02e6b9570c0ba6696fa72f56d7bd..2a133466d6636b9ceacf7384797298ec9d463e78 100644 (file)
@@ -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 (executable)
index 0000000..3400977
--- /dev/null
@@ -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 (executable)
index 0000000..dd36f80
--- /dev/null
@@ -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 (executable)
index 0000000..5948400
--- /dev/null
@@ -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 (executable)
index 0000000..095d611
--- /dev/null
@@ -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
+
+:
index ab2af66e574584fcc6951c4bf275ad17776e3ebb..846e247c680ee95cf4ade96b7161879ab60e6c56 100755 (executable)
 # 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
similarity index 82%
rename from tests/pr204.test
rename to tests/yacc-pr204.test
index 64032c70886e779b25156066c8ff26ec910430c4..a1c36913ede90381917b0bd91d86e4c7049e942b 100755 (executable)
 # 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
 
 :