-
Notifications
You must be signed in to change notification settings - Fork 1
/
subdir.mk
122 lines (95 loc) · 2.76 KB
/
subdir.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
## Make rules for subdirectories
# The including Makefile is expected to set the following variables:
#
# FILES List of coq source files
#
# Additionally, the user may set the following variables:
#
# CROSSDEP warn|ignore|rebuild
#
# Figure out where we are
TOPDIR= $(dir $(CURDIR))
SUBDIR= $(notdir $(CURDIR))
# Set the COQPATH environment variable to the top-level directory
COQPATH= $(TOPDIR)
export COQPATH
# Default values for parameters
CROSSDEP = warn
# TIMELOG = .timelog
# Toolchain
COQC= coqc
COQTOP= coqtop
COQDOC= coqdoc
OCAMLBUILD= ocamlbuild
# Hookable targets: subdir Makefiles can extend them by adding dependencies.
all: all-vo
clean: clean-vo
## Compiling Coq sources files
# Compile all of them
all-vo: $(FILES:.v=.vo)
# Compile one of them
ifeq ($(TIMELOG),)
%.vo: %.v
# $(COQC) $*
@echo $(COQC) $*
@(printf $* && printf " " && (/usr/bin/time -p $(COQC) $*)) > [email protected] 2>&1
@cat [email protected] >> timelog
@$(RM) [email protected]
else
# Keep a log of compilation times: if $(TIMELOG) is defined,
# we write an entry there each time we build a .vo file.
GITREV := $(shell git rev-parse --short HEAD)
GITMOD := $(shell git status --porcelain --untracked=no | grep -q . && echo +)
TIME = /usr/bin/time -o [email protected] -f "$(GITREV)$(GITMOD):$(SUBDIR)/$< %U %S %E %P"
%.vo: %.v
@echo $(COQC) $*
@$(TIME) -o [email protected] $(COQC) $*
@cat [email protected] >> ../$(TIMELOG)
@$(RM) [email protected]
endif
# Cleanup
clean-vo:
$(RM) $(FILES:.v=.vo) $(FILES:.v=.glob) $(FILES:.v=.vo.time)
## Out-of-date files in other subdirectories
# The way we handle out-of-date files from other subdirectories depend on the
# value of the variables $(CROSSDEP). If it is 'ignore', then we do nothing.
# If it is 'warn' (the default), we emit a warning but do not try to rebuild
# them either. If it is 'build', then we attempt to rebuild it as if it were
# one of our files.
ifeq ($(CROSSDEP),ignore)
../%.vo:
else
ifneq ($(CROSSDEP),build)
../%.vo:
@echo "W: $@ seems out of date, you may want to rebuild"
endif
endif
## Dependency handling
# Print a list of all our .v files
.PHONY: listfiles
listfiles:
for f in $(FILES); do \
echo $$f; \
done
# The top-level Makefile will use the previous rule to build a global .depend
# file. We specialize the global .depend for our specific subdirectory.
.depend: ../.depend
sed 's_../$(SUBDIR)/__g' $< >[email protected]
mv [email protected] $@
# If it exists, load the result.
-include .depend
## Documentation
.PHONY: documentation
documentation: html
clean: clean-html
# FIXME: we may want a global thing instead of a per-directory one, so that
# hyperlinks can take us anywhere and there is one complete set of HTML files.
html: $(FILES:.v=.vo)
$(RM) -r [email protected]
mkdir [email protected]
$(COQDOC) -R . $(SUBDIR) --html -d [email protected] --toc --utf8 $(FILES)
$(RM) -r $@
mv [email protected] $@
.PHONY: clean-html
clean-html:
$(RM) -r html