-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
196 lines (143 loc) · 6.42 KB
/
Makefile
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
.PHONY: all theories clightgen clean deepclean
all: theories
#
# meta
#
PUBLISHER=appliedfm
PROJECT=Int63
#
# configure
#
J?=4
BITSIZE?=opam
COQC?=coqc
SHA256SUM?=sha256sum
VSUTOOL?=vsu
-include CONFIGURE
VSU_INCLUDE_DIR=$(shell $(VSUTOOL) -I)
CLIGHTGEN64?=$(shell $(VSUTOOL) --show-tool-path=coq-compcert/clightgen)
CLIGHTGEN32?=$(shell $(VSUTOOL) --show-tool-path=coq-compcert-32/clightgen)
TARGET=x86_64-linux
VARIANT=
COMPCERT_PACKAGE=coq-compcert
VST_PACKAGE=coq-vst
COQLIB=$(shell $(COQC) -where | tr -d '\r' | tr '\\' '/')
COQLIBINSTALL=$(COQLIB)/user-contrib
COQ_INSTALL_DIR?=$(COQLIBINSTALL)/$(PUBLISHER)/$(PROJECT)
ifeq ($(BITSIZE),64) # This is an alias for BITSIZE=opam
else ifeq ($(BITSIZE),32)
TARGET=x86_32-linux
COMPCERT_PACKAGE=coq-compcert-32
VST_PACKAGE=coq-vst-32
COQLIBINSTALL=$(COQLIB)/../coq-variant
VARIANT=32/
endif
COQ_INSTALL_DIR=$(COQLIBINSTALL)/$(PUBLISHER)/$(VARIANT)$(PROJECT)
CLIGHT_TARGETS=theories/$(PROJECT)/vst/clightgen/$(TARGET)/int63.v
ifeq ($(SUBPROJECT),model)
SKIP_VST=1
CLIGHT_TARGETS=
else ifeq ($(SUBPROJECT),vst)
SKIP_MODEL=1
endif
#
# clightgen
#
ifeq ($(SRC),opam)
C_INCLUDE_PATH?=$(VSU_INCLUDE_DIR)
else
C_INCLUDE_PATH?=src/c/include
endif
theories/$(PROJECT)/vst/clightgen/x86_64-linux/int63.v: \
$(C_INCLUDE_PATH)/coq-vsu-int63/src/int63.c \
$(C_INCLUDE_PATH)/coq-vsu-int63/int63.h
theories/$(PROJECT)/vst/clightgen/x86_32-linux/int63.v: \
$(C_INCLUDE_PATH)/coq-vsu-int63/src/int63.c \
$(C_INCLUDE_PATH)/coq-vsu-int63/int63.h
theories/$(PROJECT)/vst/clightgen/x86_64-linux/%.v:
mkdir -p `dirname $@`
$(CLIGHTGEN64) -Wall -Wno-unused-variable -I`$(VSUTOOL) -I` -normalize -o $@ $<
echo "(*\nInput hashes (sha256):\n\n`$(SHA256SUM) $^`\n*)" >> $@
theories/$(PROJECT)/vst/clightgen/x86_32-linux/%.v:
mkdir -p `dirname $@`
$(CLIGHTGEN32) -Wall -Wno-unused-variable -I`$(VSUTOOL) -I` -normalize -o $@ $<
echo "(*\nInput hashes (sha256):\n\n`$(SHA256SUM) $^`\n*)" >> $@
clightgen: \
theories/$(PROJECT)/vst/clightgen/x86_64-linux/int63.v \
theories/$(PROJECT)/vst/clightgen/x86_32-linux/int63.v
#
# theories
#
_CoqProject: $(CLIGHT_TARGETS)
echo "# $(TARGET)" > $@
echo `$(VSUTOOL) -Q $(COMPCERT_PACKAGE)` >> $@
echo `$(VSUTOOL) -Q $(VST_PACKAGE)` >> $@
[ -n "$(SKIP_MODEL)" ] || echo "-Q theories/$(PROJECT)/model $(PUBLISHER).$(PROJECT).model" >> $@
[ -n "$(SKIP_MODEL)" ] || find theories/$(PROJECT)/model -name "*.v" | sort >> $@
[ -n "$(SKIP_VST)" ] || echo "-Q theories/$(PROJECT)/vst/ast $(PUBLISHER).$(PROJECT).vst.ast" >> $@
[ -n "$(SKIP_VST)" ] || find theories/$(PROJECT)/vst/ast -name "*.v" | sort >> $@
[ -n "$(SKIP_VST)" ] || echo "-Q theories/$(PROJECT)/vst/clightgen/$(TARGET) $(PUBLISHER).$(PROJECT).vst.clightgen" >> $@
[ -n "$(SKIP_VST)" ] || find theories/$(PROJECT)/vst/clightgen/$(TARGET) -name "*.v" | sort >> $@
[ -n "$(SKIP_VST)" ] || echo "-Q theories/$(PROJECT)/vst/verif $(PUBLISHER).$(PROJECT).vst.verif" >> $@
[ -n "$(SKIP_VST)" ] || find theories/$(PROJECT)/vst/verif -name "*.v" | sort >> $@
[ -n "$(SKIP_VST)" ] || echo "-Q theories/$(PROJECT)/vst/spec $(PUBLISHER).$(PROJECT).vst.spec" >> $@
[ -n "$(SKIP_VST)" ] || find theories/$(PROJECT)/vst/spec -name "*.v" | sort >> $@
Makefile.coq: Makefile _CoqProject
cat _CoqProject
coq_makefile -f _CoqProject -o Makefile.coq
theories: Makefile.coq
$(MAKE) -f Makefile.coq -j$(J)
#
# install
#
.PHONY: install install-src install-model install-vst
C_SOURCES= \
$(shell find src/c/include -name "*.c" | sort | cut -d'/' -f4-) \
$(shell find src/c/include -name "*.h" | sort | cut -d'/' -f4-)
install-src:
install -d "$(VSU_INCLUDE_DIR)"
for d in $(sort $(dir $(C_SOURCES))); do install -d "$(VSU_INCLUDE_DIR)/$$d"; done
for f in $(C_SOURCES); do install -m 0644 src/c/include/$$f "$(VSU_INCLUDE_DIR)/$$(dirname $$f)"; done
tree "$(VSU_INCLUDE_DIR)" || true
COQ_SOURCES_MODEL= \
$(shell find theories/$(PROJECT)/model -name "*.v" | cut -d'/' -f3-)
COQ_COMPILED_MODEL=$(COQ_SOURCES_MODEL:%.v=%.vo)
install-model: theories
install -d "$(COQ_INSTALL_DIR)"
for d in $(sort $(dir $(COQ_SOURCES_MODEL) $(COQ_COMPILED_MODEL))); do install -d "$(COQ_INSTALL_DIR)/$$d"; done
for f in $(COQ_SOURCES_MODEL) $(COQ_COMPILED_MODEL); do install -m 0644 theories/$(PROJECT)/$$f "$(COQ_INSTALL_DIR)/$$(dirname $$f)"; done
tree "$(COQ_INSTALL_DIR)" || true
COQ_SOURCES_VST= \
$(shell find theories/$(PROJECT)/vst/ast -name "*.v" | sort | cut -d'/' -f3-) \
$(shell find theories/$(PROJECT)/vst/clightgen/$(TARGET) -name "*.v" | sort | cut -d'/' -f3-) \
$(shell find theories/$(PROJECT)/vst/verif -name "*.v" | sort | cut -d'/' -f3-) \
$(shell find theories/$(PROJECT)/vst/spec -name "*.v" | sort | cut -d'/' -f3-)
COQ_COMPILED_VST=$(COQ_SOURCES_VST:%.v=%.vo)
install-vst: theories
[ -z $(PACKAGE_NAME) ] || echo "{" > install-meta.json
[ -z $(PACKAGE_NAME) ] || echo " \"coq-library-name\": \"$(PUBLISHER).$(PROJECT)\"," >> install-meta.json
[ -z $(PACKAGE_NAME) ] || echo " \"coq-library-path\": \"$(COQ_INSTALL_DIR)\"" >> install-meta.json
[ -z $(PACKAGE_NAME) ] || echo "}" >> install-meta.json
[ -z $(PACKAGE_NAME) ] || install -d `$(VSUTOOL) --show-unit-metadata-path`
[ -z $(PACKAGE_NAME) ] || install -m 0644 install-meta.json `$(VSUTOOL) --show-unit-metadata-path`/$(PACKAGE_NAME).json
install -d "$(COQ_INSTALL_DIR)"
for d in $(sort $(dir $(COQ_COMPILED_VST) $(COQ_COMPILED_VST))); do install -d "$(COQ_INSTALL_DIR)/$$d"; done
for f in $(COQ_COMPILED_VST) $(COQ_COMPILED_VST); do install -m 0644 theories/$(PROJECT)/$$f "$(COQ_INSTALL_DIR)/$$(dirname $$f)"; done
mv $(COQ_INSTALL_DIR)/vst/clightgen/$(TARGET)/* $(COQ_INSTALL_DIR)/vst/clightgen/
rmdir $(COQ_INSTALL_DIR)/vst/clightgen/$(TARGET)
tree "$(COQ_INSTALL_DIR)" || true
#
# clean
#
clean:
[ ! -f Makefile.coq ] || $(MAKE) -f Makefile.coq clean
rm -f install-meta.json
rm -f `find ./ -name "*Makefile.coq*"`
rm -f `find ./ -name ".*.cache"`
rm -f `find ./ -name "*.aux"`
rm -f `find ./ -name "*.glob"`
rm -f `find ./ -name "*.vo*"`
deepclean: clean
rm -f _CoqProject
verydeepclean: deepclean
rm -rf theories/$(PROJECT)/vst/clightgen