From d769da460ff44fd92dc156c27880dc33d38c98fe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Franc=CC=A7ois=20Pottier?= <francois.pottier@inria.fr>
Date: Tue, 25 Mar 2025 23:41:47 +0100
Subject: [PATCH] Move [make view] into Makefile.demo and remove dune rule to
 build parser.pdf.

This ad hoc dune rule would conflict with dune's default rules and would
sometimes cause [make demos] to fail with a message along the lines of
"cannot remove parser.ml".
---
 demos/.gitignore                    |  1 +
 demos/Makefile.demo                 | 11 +++++++++++
 demos/calc-mini/Makefile            |  9 ---------
 demos/calc-mini/Makefile.demo       |  1 +
 demos/calc-mini/dune                | 16 ----------------
 demos/calc-stratified/Makefile      |  9 ---------
 demos/calc-stratified/Makefile.demo |  1 +
 demos/calc-stratified/dune          | 16 ----------------
 8 files changed, 14 insertions(+), 50 deletions(-)
 create mode 100644 demos/.gitignore
 create mode 120000 demos/calc-mini/Makefile.demo
 create mode 120000 demos/calc-stratified/Makefile.demo

diff --git a/demos/.gitignore b/demos/.gitignore
new file mode 100644
index 000000000..1bc4697d1
--- /dev/null
+++ b/demos/.gitignore
@@ -0,0 +1 @@
+parser.pdf
diff --git a/demos/Makefile.demo b/demos/Makefile.demo
index 5bf5df406..7eb6eb4ce 100644
--- a/demos/Makefile.demo
+++ b/demos/Makefile.demo
@@ -35,3 +35,14 @@ show: test
 .PHONY: api
 api: test
 	more $(IMAGE)/parser.mli
+
+# [make view] shows a .pdf image of the LR(1) automaton.
+
+VIEW = $(shell \
+  if command -v open >/dev/null ; then echo open ; else echo evince ; fi)
+
+.PHONY: view
+view: all
+	dune exec ../../src/stage2/main.exe -- --infer --automaton-graph parser.mly && rm -f parser.{ml,mli}
+	dot -Tpdf parser.dot > parser.pdf && rm -f parser.dot
+	$(VIEW) parser.pdf
diff --git a/demos/calc-mini/Makefile b/demos/calc-mini/Makefile
index 5465ca909..3b640d4f7 100644
--- a/demos/calc-mini/Makefile
+++ b/demos/calc-mini/Makefile
@@ -1,10 +1 @@
 include ../Makefile.demo
-
-# Choosing a PDF viewer.
-VIEW := $(shell \
-  if command -v open >/dev/null ; then echo open ; else echo evince ; fi)
-
-# Viewing a .pdf image of the LR(1) automaton.
-.PHONY: view
-view: all
-	$(VIEW) $(IMAGE)/parser.pdf
diff --git a/demos/calc-mini/Makefile.demo b/demos/calc-mini/Makefile.demo
new file mode 120000
index 000000000..88bd4c764
--- /dev/null
+++ b/demos/calc-mini/Makefile.demo
@@ -0,0 +1 @@
+../Makefile.demo
\ No newline at end of file
diff --git a/demos/calc-mini/dune b/demos/calc-mini/dune
index 721befad3..d7e98aaa8 100644
--- a/demos/calc-mini/dune
+++ b/demos/calc-mini/dune
@@ -14,22 +14,6 @@
   (name calc)
 )
 
-;; ------------------------------------------------------------------------------
-;; Visualizing the LR(1) automaton.
-
-(rule
-  (target parser.dot)
-  (action
-    (run menhir --infer
-       %{dep:parser.mly}
-       --automaton-graph
-)))
-
-(rule
-  (with-stdout-to parser.pdf
-    (system "dot -Tpdf %{dep:parser.dot}")
-))
-
 ;; ------------------------------------------------------------------------------
 ;; The following declarations are used to test this demo.
 
diff --git a/demos/calc-stratified/Makefile b/demos/calc-stratified/Makefile
index 5465ca909..3b640d4f7 100644
--- a/demos/calc-stratified/Makefile
+++ b/demos/calc-stratified/Makefile
@@ -1,10 +1 @@
 include ../Makefile.demo
-
-# Choosing a PDF viewer.
-VIEW := $(shell \
-  if command -v open >/dev/null ; then echo open ; else echo evince ; fi)
-
-# Viewing a .pdf image of the LR(1) automaton.
-.PHONY: view
-view: all
-	$(VIEW) $(IMAGE)/parser.pdf
diff --git a/demos/calc-stratified/Makefile.demo b/demos/calc-stratified/Makefile.demo
new file mode 120000
index 000000000..88bd4c764
--- /dev/null
+++ b/demos/calc-stratified/Makefile.demo
@@ -0,0 +1 @@
+../Makefile.demo
\ No newline at end of file
diff --git a/demos/calc-stratified/dune b/demos/calc-stratified/dune
index 89dc2ca44..cab8b753d 100644
--- a/demos/calc-stratified/dune
+++ b/demos/calc-stratified/dune
@@ -14,22 +14,6 @@
   (name calc)
 )
 
-;; ------------------------------------------------------------------------------
-;; Visualizing the LR(1) automaton.
-
-(rule
-  (target parser.dot)
-  (action
-    (run menhir --infer
-       %{dep:parser.mly}
-       --automaton-graph
-)))
-
-(rule
-  (with-stdout-to parser.pdf
-    (system "sed -i.bak 's/LR/TB/;s/landscape/portrait/' %{dep:parser.dot} && dot -Tpdf %{dep:parser.dot}")
-))
-
 ;; ------------------------------------------------------------------------------
 ;; The following declarations are used to test this demo.
 
-- 
GitLab