From 59eef752d4740ecc369c9eab986a32e07c15f125 Mon Sep 17 00:00:00 2001
From: Ralf Jung <jung@mpi-sws.org>
Date: Tue, 6 Oct 2020 16:28:03 +0200
Subject: [PATCH] update build system

---
 .gitignore             |  2 +-
 Makefile               | 51 +++++++++++++++++++++++++-----------------
 opam => coq-stdpp.opam |  0
 3 files changed, 31 insertions(+), 22 deletions(-)
 rename opam => coq-stdpp.opam (100%)

diff --git a/.gitignore b/.gitignore
index 4265b415..b6e84eae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,5 +17,5 @@ Makefile.coq
 Makefile.coq.conf
 *.crashcoqide
 html/
-build-dep/
+builddep/
 _opam
diff --git a/Makefile b/Makefile
index 163ff30f..8d16271e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,18 +1,22 @@
+# Default target
+all: Makefile.coq
+	+@make -f Makefile.coq all
+.PHONY: all
+
 # Permit local customization
 -include Makefile.local
 
 # Forward most targets to Coq makefile (with some trick to make this phony)
 %: Makefile.coq phony
+	@#echo "Forwarding $@"
 	+@make -f Makefile.coq $@
-
-all: Makefile.coq
-	+@make -f Makefile.coq all
-.PHONY: all
+phony: ;
+.PHONY: phony
 
 clean: Makefile.coq
 	+@make -f Makefile.coq clean
 	find theories tests exercises solutions \( -name "*.d" -o -name "*.vo" -o -name "*.vo[sk]" -o -name "*.aux" -o -name "*.cache" -o -name "*.glob" -o -name "*.vio" \) -print -delete || true
-	rm -f Makefile.coq .lia.cache
+	rm -f Makefile.coq .lia.cache builddep/*
 .PHONY: clean
 
 # Create Coq Makefile.
@@ -20,27 +24,32 @@ Makefile.coq: _CoqProject Makefile
 	"$(COQBIN)coq_makefile" -f _CoqProject -o Makefile.coq $(EXTRA_COQFILES)
 
 # Install build-dependencies
-build-dep/opam: opam Makefile
-	@echo "# Creating build-dep package."
-	@mkdir -p build-dep
-	@sed <opam -E 's/^(build|install|remove):.*/\1: []/; s/^name: *"(.*)" */name: "\1-builddep"/' >build-dep/opam
-	@fgrep builddep build-dep/opam >/dev/null || (echo "sed failed to fix the package name" && exit 1) # sanity check
+OPAMFILES=$(wildcard *.opam)
+BUILDDEPFILES=$(addsuffix -builddep.opam, $(addprefix builddep/,$(basename $(OPAMFILES))))
+
+builddep/%-builddep.opam: %.opam Makefile
+	@echo "# Creating builddep package for $<."
+	@mkdir -p builddep
+	@sed <$< -E 's/^(build|install|remove):.*/\1: []/; s/^name: *"(.*)" */name: "\1-builddep"/; s/"(.*)"(.*= *version.*)$$/"\1-builddep"\2/;' >$@
+	@fgrep builddep $@ >/dev/null || (echo "sed failed to fix the package name" && exit 1) # sanity check
 
-build-dep: build-dep/opam phony
+builddep-opamfiles: $(BUILDDEPFILES)
+.PHONY: builddep-opamfiles
+
+builddep: builddep-opamfiles
 	@# We want opam to not just instal the build-deps now, but to also keep satisfying these
 	@# constraints.  Otherwise, `opam upgrade` may well update some packages to versions
 	@# that are incompatible with our build requirements.
 	@# To achieve this, we create a fake opam package that has our build-dependencies as
 	@# dependencies, but does not actually install anything itself.
-	@echo "# Installing build-dep package."
-	@opam install $(OPAMFLAGS) build-dep/
+	@echo "# Installing builddep packages."
+	@opam install $(OPAMFLAGS) $(BUILDDEPFILES)
+.PHONY: builddep
 
-# Some files that do *not* need to be forwarded to Makefile.coq
-Makefile: ;
-_CoqProject: ;
-opam: ;
-Makefile.local: ;
+# Backwards compatibility target
+build-dep: builddep
+.PHONY: build-dep
 
-# Phony wildcard targets
-phony: ;
-.PHONY: phony
+# Some files that do *not* need to be forwarded to Makefile.coq.
+# ("::" lets Makefile.local overwrite this.)
+Makefile Makefile.local _CoqProject $(OPAMFILES):: ;
diff --git a/opam b/coq-stdpp.opam
similarity index 100%
rename from opam
rename to coq-stdpp.opam
-- 
GitLab