|
| 1 | +# -*- Makefile -*- |
| 2 | + |
| 3 | +###################################################################### |
| 4 | +# USAGE: # |
| 5 | +# The rules this-config::, this-build::, this-distclean::, # |
| 6 | +# pre-makefile::, this-clean:: and __always__:: may be extended # |
| 7 | +# Additionally, the following variables may be customized: # |
| 8 | +SUBDIRS?= |
| 9 | +COQBIN?=$(dir $(shell which coqtop)) |
| 10 | +COQMAKEFILE?=$(COQBIN)coq_makefile |
| 11 | +COQDEP?=$(COQBIN)coqdep |
| 12 | +COQPROJECT?=_CoqProject |
| 13 | +COQMAKEOPTIONS?= |
| 14 | +COQMAKEFILEOPTIONS?= |
| 15 | +V?= |
| 16 | +VERBOSE?=V |
| 17 | +###################################################################### |
| 18 | + |
| 19 | +# local context: ----------------------------------------------------- |
| 20 | +.PHONY: all config build clean distclean __always__ |
| 21 | +.SUFFIXES: |
| 22 | + |
| 23 | +H:= $(if $(VERBOSE),,@) # not used yet |
| 24 | +TOP = $(dir $(lastword $(MAKEFILE_LIST))) |
| 25 | +COQMAKE = $(MAKE) -f Makefile.coq $(COQMAKEOPTIONS) |
| 26 | +BRANCH_coq:= $(shell $(COQBIN)coqtop -v | head -1 | grep -E '(trunk|master)' \ |
| 27 | + | wc -l | sed 's/ *//g') |
| 28 | + |
| 29 | +# coq version: |
| 30 | +ifneq "$(BRANCH_coq)" "0" |
| 31 | +COQVVV:= dev |
| 32 | +else |
| 33 | +COQVVV:=$(shell $(COQBIN)coqtop --print-version | cut -d" " -f1) |
| 34 | +endif |
| 35 | + |
| 36 | +COQV:= $(shell echo $(COQVVV) | cut -d"." -f1) |
| 37 | +COQVV:= $(shell echo $(COQVVV) | cut -d"." -f1-2) |
| 38 | + |
| 39 | +# all: --------------------------------------------------------------- |
| 40 | +all: config build |
| 41 | + |
| 42 | +# Makefile.coq: ------------------------------------------------------ |
| 43 | +.PHONY: pre-makefile |
| 44 | + |
| 45 | +Makefile.coq: pre-makefile $(COQPROJECT) Makefile |
| 46 | + $(COQMAKEFILE) $(COQMAKEFILEOPTIONS) -f $(COQPROJECT) -o Makefile.coq |
| 47 | + |
| 48 | +# Global config, build, clean and distclean -------------------------- |
| 49 | +config: sub-config this-config |
| 50 | + |
| 51 | +build: sub-build this-build |
| 52 | + |
| 53 | +clean: sub-clean this-clean |
| 54 | + |
| 55 | +distclean: sub-distclean this-distclean |
| 56 | + |
| 57 | +# Local config, build, clean and distclean --------------------------- |
| 58 | +.PHONY: this-config this-build this-distclean this-clean |
| 59 | + |
| 60 | +this-config:: __always__ |
| 61 | + |
| 62 | +this-build:: this-config Makefile.coq |
| 63 | + +$(COQMAKE) |
| 64 | + |
| 65 | +this-distclean:: this-clean |
| 66 | + rm -f Makefile.coq Makefile.coq.conf Makefile.coq |
| 67 | + |
| 68 | +this-clean:: __always__ |
| 69 | + @if [ -f Makefile.coq ]; then $(COQMAKE) cleanall; fi |
| 70 | + |
| 71 | +# Install target ----------------------------------------------------- |
| 72 | +.PHONY: install |
| 73 | + |
| 74 | +install: __always__ Makefile.coq |
| 75 | + $(COQMAKE) install |
| 76 | +# counting lines of Coq code ----------------------------------------- |
| 77 | +.PHONY: count |
| 78 | + |
| 79 | +COQFILES = $(shell grep '.v$$' $(COQPROJECT)) |
| 80 | + |
| 81 | +count: |
| 82 | + @coqwc $(COQFILES) | tail -1 | \ |
| 83 | + awk '{printf ("%d (spec=%d+proof=%d)\n", $$1+$$2, $$1, $$2)}' |
| 84 | +# Additionally cleaning backup (*~) files ---------------------------- |
| 85 | +this-distclean:: |
| 86 | + rm -f $(shell find . -name '*~') |
| 87 | + |
| 88 | +# Make in SUBDIRS ---------------------------------------------------- |
| 89 | +ifdef SUBDIRS |
| 90 | +sub-%: __always__ |
| 91 | + @set -e; for d in $(SUBDIRS); do +$(MAKE) -C $$d $(@:sub-%=%); done |
| 92 | +else |
| 93 | +sub-%: __always__ |
| 94 | + @true |
| 95 | +endif |
| 96 | + |
| 97 | +# Make of individual .vo --------------------------------------------- |
| 98 | +%.vo: __always__ Makefile.coq |
| 99 | + +$(COQMAKE) $@ |
0 commit comments