From 609b3d8096fb0cc1fa4d908b6e1a860ced260bda Mon Sep 17 00:00:00 2001
From: Akim Demaille <demaille@gostai.com>
Date: Tue, 14 Feb 2012 17:32:51 +0100
Subject: [PATCH] calc++: rely on Automake.

Rely on $(YACC) being the bison being built, and let Automake do the
rest.  It turned out to be much more difficult than anticipated, for
various reasons, including some bad behavior from Automake 1.11.2
which (i) generates calc++-parser.h instead of calc++-parser.hh, and
(ii) leaves an #include "y.tab.h" in the generated parser instead
of #include "calc++-parser.h".

The authors of Automake appear to be aware of the problem,
http://lists.gnu.org/archive/html/automake/2011-05/msg00008.html
so a simple work around will suffice for the time being.

	* examples/calc++/y.tab.h, examples/calc++/calc++-parser.hh: New.
	To work around Automake 1.11.2 issues.
	* examples/calc++/local.mk: Remove all the rules for compilation
	with bison, leave them to Automake.
	So provide it with "calc++-parse.yy" as a source file.
	(calc_sources_generated, calc_sources_extracted): Rename as.
	(calc_generated, calc_extracted): these.
	(calc_sources): New.
	Fix them.
---
 examples/calc++/.gitignore       |   19 ++++++++----
 examples/calc++/calc++-parser.hh |    4 ++
 examples/calc++/local.mk         |   58 ++++++++++++--------------------------
 examples/calc++/y.tab.h          |    6 ++++
 4 files changed, 41 insertions(+), 46 deletions(-)
 create mode 100644 examples/calc++/calc++-parser.hh
 create mode 100644 examples/calc++/y.tab.h

diff --git a/examples/calc++/.gitignore b/examples/calc++/.gitignore
index 6dc7e2f..2306d17 100644
--- a/examples/calc++/.gitignore
+++ b/examples/calc++/.gitignore
@@ -1,11 +1,18 @@
-/*.cc
-/*.hh
-/*.ll
 /*.o
-/*.output
-/*.stamp
 /*.tmp
-/*.yy
 /.deps
 /calc++
+/calc++-driver.cc
+/calc++-driver.hh
+/calc++-parser.output
+/calc++-parser.yy
+/calc++-parser.cc
+/calc++-parser.h
+/calc++-scanner.cc
+/calc++-scanner.ll
+/calc++.cc
 /calc++.exe
+/calc.stamp
+/location.hh
+/position.hh
+/stack.hh
diff --git a/examples/calc++/calc++-parser.hh b/examples/calc++/calc++-parser.hh
new file mode 100644
index 0000000..6f1e885
--- /dev/null
+++ b/examples/calc++/calc++-parser.hh
@@ -0,0 +1,4 @@
+// Work around an Automake 1.11.2 bug: it asks for the creation of
+// y.tab.h and then renames it as calc++-parser.h instead of
+// calc++-parser.hh.  We don't want this to show in the documentation.
+#include "calc++-parser.h"
diff --git a/examples/calc++/local.mk b/examples/calc++/local.mk
index affb9c3..967925f 100644
--- a/examples/calc++/local.mk
+++ b/examples/calc++/local.mk
@@ -32,62 +32,40 @@ $(top_srcdir)/examples/calc++/calc.stamp: $(doc) $(extexi)
 	$(AM_V_at)mv $@.tmp $@
 
 $(calc_extracted): $(top_srcdir)/examples/calc++/calc.stamp
-
-## ------------------- ##
-## Parser generation.  ##
-## ------------------- ##
-
-BUILT_SOURCES += $(calc_extracted) $(calc_sources_generated)
-CLEANFILES += $(top_srcdir)/examples/calc++/*.output *.tmp
-MAINTAINERCLEANFILES += $(top_srcdir)/examples/calc++/*.stamp $(calc___SOURCES)
-
-# Compile the parser and save cycles.
-# This code comes from "Handling Tools that Produce Many Outputs",
-# from the Automake documentation.
-EXTRA_DIST +=					\
-  examples/calc++/calc++-parser.stamp		\
-  examples/calc++/calc++-parser.yy		\
-  examples/calc++/calc.stamp
-# Don't depend on $(BISON) otherwise we would rebuild these files
-# in srcdir, including during distcheck, which is forbidden.
-$(top_srcdir)/examples/calc++/calc++-parser.stamp: $(top_srcdir)/examples/calc++/calc++-parser.yy $(BISON_IN)
-	$(AM_V_GEN)rm -f calc++-parser.tmp
-	$(AM_V_at)touch calc++-parser.tmp
-	$(AM_V_at)$(BISON) -d -ra -o $(top_srcdir)/examples/calc++/calc++-parser.cc \
-	  $(top_srcdir)/examples/calc++/calc++-parser.yy
-	$(AM_V_at)mv -f calc++-parser.tmp $@
-
-$(calc_sources_generated): $(top_srcdir)/examples/calc++/calc++-parser.stamp
 	$(AM_V_GEN)if test -f $@; then :; else \
-	  rm -f $(top_srcdir)/examples/calc++/calc++-parser.stamp && \
-	  $(MAKE) $(AM_MAKEFLAGS) $(top_srcdir)/examples/calc++/calc++-parser.stamp; \
+	  rm -f $< && \
+	  $(MAKE) $(AM_MAKEFLAGS) $<; \
 	fi
 
-
 ## --------------------------- ##
 ## Building & testing calc++.  ##
 ## --------------------------- ##
 
-calc_sources_extracted =			\
+BUILT_SOURCES += $(calc_sources) examples/calc++/calc++-parser.h
+CLEANFILES += *.tmp
+MAINTAINERCLEANFILES += $(top_srcdir)/examples/calc++/calc.stamp $(calc_sources)
+EXTRA_DIST += examples/calc++/calc.stamp
+
+calc_extracted =				\
   examples/calc++/calc++-scanner.ll		\
   examples/calc++/calc++.cc			\
   examples/calc++/calc++-driver.hh		\
-  examples/calc++/calc++-driver.cc
-calc_extracted =				\
-  $(calc_sources_extracted)			\
+  examples/calc++/calc++-driver.cc		\
   examples/calc++/calc++-parser.yy
-calc_sources_generated =			\
+calc_generated =				\
+  examples/calc++/calc++-parser.h		\
   examples/calc++/stack.hh			\
   examples/calc++/position.hh			\
-  examples/calc++/location.hh			\
-  examples/calc++/calc++-parser.hh		\
-  examples/calc++/calc++-parser.cc
-
+  examples/calc++/location.hh
+calc_sources =					\
+  $(calc_extracted) $(calc_generated)
 if BISON_CXX_WORKS
 check_PROGRAMS = examples/calc++/calc++
 examples_calc___calc___SOURCES =		\
-  $(calc_sources_extracted) 			\
-  $(calc_sources_generated)
+  $(calc_sources)				\
+  examples/calc++/y.tab.h			\
+  examples/calc++/calc++-parser.hh
+
 examples_calc___calc___CPPFLAGS = -I$(top_srcdir)/examples/calc++
 TESTS = examples/calc++/test
 endif
diff --git a/examples/calc++/y.tab.h b/examples/calc++/y.tab.h
new file mode 100644
index 0000000..798b670
--- /dev/null
+++ b/examples/calc++/y.tab.h
@@ -0,0 +1,6 @@
+// Work around an Automake 1.11.2 bug: it asks for the creation of
+// y.tab.c and y.tab.h and then renames them as calc++-parser.cc and
+// calc++-parser.h, but in the former it does not convert the
+// #include "y.tab.h".  We don't want this to show in the
+// documentation.
+#include "calc++-parser.hh"
-- 
1.7.9

