forked from jscoq/jscoq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
211 lines (157 loc) · 6.38 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
.PHONY: all clean force
.PHONY: jscoq jscoq_worker links links-clean
.PHONY: dist dist-upload dist-release server
-include ./config.inc
# Coq Version
COQ_VERSION:=v8.11
JSCOQ_BRANCH:=
JSCOQ_VERSION:=$(COQ_VERSION)
ifdef JSCOQ_BRANCH
JSCOQ_VERSION:=$(JSCOQ_VERSION)-$(JSCOQ_BRANCH)
endif
WORD_SIZE ?= 32
OS := ${shell uname}
ARCH := $(OS)/$(WORD_SIZE)
ifeq ($(WORD_SIZE),64)
DUNE_WORKSPACE = $(current_dir)/dune-workspace-64
VARIANT = +64bit
else
VARIANT = +32bit
endif
BUILD_CONTEXT = jscoq$(VARIANT)
# ugly but I couldn't find a better way
current_dir := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
# Directory where the Coq sources and developments are.
ADDONS_PATH := $(current_dir)/_vendor+$(COQ_VERSION)$(VARIANT)
COQSRC := $(ADDONS_PATH)/coq/
# Directories where Dune builds and installs Coq
COQBUILDDIR_REL := _vendor+$(COQ_VERSION)$(VARIANT)/coq
COQBUILDDIR := $(current_dir)/_build/$(BUILD_CONTEXT)/$(COQBUILDDIR_REL)
COQDIR := $(current_dir)/_build/install/$(BUILD_CONTEXT)
COQPKGS_ROOT := $(current_dir)/_build/$(BUILD_CONTEXT)/coq-pkgs
DUNE_FLAGS := ${if $(DUNE_WORKSPACE), --workspace=$(DUNE_WORKSPACE),}
NJOBS ?= 4
export NJOBS
export BUILD_CONTEXT
export COQDIR
export COQBUILDDIR
export COQBUILDDIR_REL
export ADDONS_PATH
export COQPKGS_ROOT
# Addons supported in jsCoq 0.11
ADDONS = mathcomp # extlib simpleio quickchick elpi equations dsp
all:
@echo "Welcome to jsCoq makefile. Targets are:"
@echo ""
@echo " jscoq: build jscoq [javascript and libraries]"
@echo ""
@echo " links: create links that allow to serve pages from the source tree"
@echo ""
@echo " dist: create a distribution suitable for a web server"
@echo " coq: download and build Coq and addon libraries"
jscoq: force
ADDONS="$(ADDONS)" dune build @jscoq $(DUNE_FLAGS)
jscoq_worker:
ADDONS="$(ADDONS)" dune build @jscoq_worker $(DUNE_FLAGS)
links:
ln -sf _build/$(BUILD_CONTEXT)/coq-pkgs .
ln -sf ../_build/$(BUILD_CONTEXT)/coq-js/jscoq_worker.bc.js coq-js/jscoq_worker.js
# ln -sf ../_build/$(BUILD_CONTEXT)/ui-js/coq-build.browser.js ui-js
links-clean:
rm -f coq-pkgs coq-js/jscoq_worker.js
# ui-js/coq-build.browser.js
# Build symbol database files for autocomplete
coq-pkgs/%.symb: coq-pkgs/%.json
node --max-old-space-size=2048 ui-js/coq-cli.js --require-pkg $< --inspect $@
libs-symb: ${patsubst %.json, %.symb, coq-pkgs/init.json ${wildcard coq-pkgs/coq-*.json}}
########################################################################
# Clean #
########################################################################
clean:
dune clean
########################################################################
# Dists #
########################################################################
BUILDDIR=_build/$(BUILD_CONTEXT)
BUILDOBJ=${addprefix $(BUILDDIR)/./, \
coq-js/jscoq_worker.bc.js coq-pkgs \
ui-js ui-css ui-images examples \
node_modules ui-external/CodeMirror-TeX-input}
DISTOBJ = README.md index.html package.json package-lock.json $(BUILDOBJ)
DISTDIR=_build/dist
PACKAGE_VERSION = ${shell node -p 'require("./package.json").version'}
dist: jscoq
mkdir -p $(DISTDIR)
rsync -apR --delete $(DISTOBJ) $(DISTDIR)
TAREXCLUDE = --exclude node_modules --exclude '*.cma' \
${foreach dir, Coq Ltac2 mathcomp, \
--exclude '${dir}/**/*.vo' --exclude '${dir}/**/*.cma.js'}
dist-tarball: dist
# Hack to make the tar contain a jscoq-x.x directory
@rm -f _build/jscoq-$(PACKAGE_VERSION)
ln -fs dist _build/jscoq-$(PACKAGE_VERSION)
tar zcf /tmp/jscoq-$(PACKAGE_VERSION).tar.gz \
-C _build $(TAREXCLUDE) --exclude '*.bak' --exclude '*.tar.gz' \
--dereference jscoq-$(PACKAGE_VERSION)
mv /tmp/jscoq-$(PACKAGE_VERSION).tar.gz $(DISTDIR)
@rm -f _build/jscoq-$(PACKAGE_VERSION)
NPMOBJ = ${filter-out %/node_modules %/index.html, $(DISTOBJ)}
NPMSTAGEDIR = _build/package
NPMEXCLUDE = --delete-excluded --exclude '*.cma' \
${foreach dir, Coq Ltac2 mathcomp, \
--exclude '${dir}/**/*.vo' --exclude '${dir}/**/*.cma.js'}
dist-npm:
mkdir -p $(NPMSTAGEDIR) $(DISTDIR)
rsync -apR --delete $(NPMEXCLUDE) $(NPMOBJ) $(NPMSTAGEDIR)
cp docs/npm-landing.html $(NPMSTAGEDIR)/index.html
sed -i.bak 's/\(is_npm:\) false/\1 true/' $(NPMSTAGEDIR)/ui-js/jscoq-loader.js
tar zcf $(DISTDIR)/jscoq-$(PACKAGE_VERSION)-npm.tar.gz \
-C ${dir $(NPMSTAGEDIR)} --exclude '*.bak' ${notdir $(NPMSTAGEDIR)}
########################################################################
# Local stuff and distributions
########################################################################
# Private paths, for releases and local builds.
WEB_DIR=~/x80/jscoq-builds/$(JSCOQ_VERSION)/
RELEASE_DIR=~/research/jscoq-builds/
dist-upload: dist
rsync -avzp --delete $(DISTDIR)/ $(WEB_DIR)
dist-release: dist
rsync -avzp --delete --exclude=README.md --exclude=get-hashes.sh --exclude=.git $(DISTDIR)/ $(RELEASE_DIR)
# all-dist: dist dist-release dist-upload
all-dist: dist dist-release dist-upload
########################################################################
# Externals
########################################################################
.PHONY: coq coq-get coq-get-latest coq-build
COQ_BRANCH=V8.11.1
COQ_BRANCH_LATEST=v8.11
COQ_REPOS=https://github.com/coq/coq.git
COQ_PATCHES = trampoline cps timeout $(COQ_PATCHES|$(WORD_SIZE)) $(COQ_PATCHES|$(ARCH))
COQ_PATCHES|64 = coerce-32bit
COQ_PATCHES|Darwin/32 = byte-only
$(COQSRC):
git clone --depth=1 -b $(COQ_BRANCH) $(COQ_REPOS) $@
cd $@ && git apply ${foreach p,$(COQ_PATCHES),$(current_dir)/etc/patches/$p.patch}
coq-get: $(COQSRC)
cd $(COQSRC) && ./configure -prefix $(COQDIR) -native-compiler no -bytecode-compiler no -coqide no
dune build @vodeps $(DUNE_FLAGS)
cd $(COQSRC) && dune exec ./tools/coq_dune.exe $(DUNE_FLAGS) --context="$(BUILD_CONTEXT)" $(COQBUILDDIR)/.vfiles.d
coq-get-latest: COQ_BRANCH = $(COQ_BRANCH_LATEST)
coq-get-latest: coq-get
# Coq should be now be built by composition with the Dune setup
coq-build:
true
coq: coq-get coq-build
addon-%-get:
make -f coq-addons/$*.addon get
addon-%-build:
make -f coq-addons/$*.addon build
# make -f coq-addons/$*.addon jscoq-install
addons-get: ${foreach v,$(ADDONS),addon-$(v)-get}
addons-build: ${foreach v,$(ADDONS),addon-$(v)-build}
addons: addons-get addons-build
test:
npx mocha tests/main.js
server:
npx http-server _build/jscoq+32bit &
google-chrome http://127.0.0.1:8080 &