-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile.in
286 lines (200 loc) · 7.66 KB
/
Makefile.in
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#
# Usage:
# make all # not implemented yet, will build everything
# make full # build *.log.js, *.unlog.js, *.token.js
# make lineof # build lineof.js
# make interp # build interp.js
#
###############################################################
all: jsjsref mljsref
###############################################################
##### Tools
OPAMLIBDIR = @OPAMLIBDIR@
# FILL this path to fjs_of_fml project when it's not in path
GENERATOR_DIR = @GENERATOR_DIR@
# FIXME/TODO
# Uncomment this path if you are not installing throw opam
# STDLIB_DIR := $(GENERATOR_DIR)/src/stdlib_ml
STDLIB_DIR := $(OPAMLIBDIR)/fjs_of_fml/stdlib_fml
OCAMLDEP := ocamldep -one-line
OCAMLPAR := OCAMLRUNPARAM="l=200M"
LINEOF_BIN := $(GENERATOR_DIR)/lineof.byte
LINEOF := $(OCAMLPAR) $(LINEOF_BIN)
PPX_BIN := $(GENERATOR_DIR)/monad_ppx.byte
PPX_FLAG := -ppx $(PPX_BIN)
MLTOJS_BIN := $(GENERATOR_DIR)/fjs_of_fml.byte
MLTOJS := $(OCAMLPAR) $(MLTOJS_BIN) $(PPX_FLAG)
# -dsource is automatically considered by fjs_of_fml.byte
ASSEMBLY_BIN := $(GENERATOR_DIR)/assembly.byte
ASSEMBLY := $(ASSEMBLY_BIN)
DISPLAYGEN_BIN := $(GENERATOR_DIR)/displayed_sources.byte
DISPLAYGEN := $(OCAMLPAR) $(DISPLAYGEN_BIN)
OCAMLDOT_DIR := ../tools/ocamldot
OCAMLDOT := $(OCAMLDOT_DIR)/ocamldot
ESDOCGEN := ../tools/esdocgen/esdocgen.cmo
# Warn if buildtools are missing
$(MLTOJS_BIN) $(LINEOF_BIN) $(PPX_BIN) $(ASSEMBLY_BIN) $(DISPLAYGEN_BIN) $(ESDOCGEN):
$(error Missing generator tools, build from project root, or set paths.)
###############################################################
##### Dependencies
# Avoid dependency generation for non-jsjsref build targets
ifeq ($(filter clean%,$(MAKECMDGOALS)),)
include .depends
endif
.depends: $(JSREF_ML) $(PPX_BIN)
$(OCAMLDEP) -ppx $(PPX_BIN) -I . -all * > $@
###############################################################
###############################################################
# JS-JSRef
JSREF_ML := $(wildcard *.ml)
JSREF_MLI := $(wildcard *.mli)
STDLIB_FLAG := -I $(STDLIB_DIR) -open Stdlib_fml
REPLACE_STDLIB := -nopervasives -nostdlib $(STDLIB_FLAG)
# ASSEMBLY_JS_FILES must respect dependencies order
ASSEMBLY_JS_FILES := \
Datatypes.unlog.js \
LibList.unlog.js \
LibOption.unlog.js \
LibProd.unlog.js \
StdMap.unlog.js \
Heap.unlog.js \
HeapInt.unlog.js \
HeapStr.unlog.js \
HeapList.unlog.js \
Shared.unlog.js \
Compare.js \
JsNumber.js \
JsSyntax.unlog.js \
JsSyntaxAux.unlog.js \
HeapObj.unlog.js \
Translate_syntax.js \
JsCommon.unlog.js \
JsCommonAux.unlog.js \
JsInit.unlog.js \
Prheap.js \
Debug.js \
JsInterpreterMonads.unlog.js \
JsInterpreter.log.js \
JsInterpreterUtils.unlog.js \
ModuleExport.js
ASSEMBLY_JS := \
$(STDLIB_DIR)/stdlib_fml.js \
$(ASSEMBLY_JS_FILES)
###############################################################
DISPLAYED := \
JsInterpreter.ml
ALL_DISPLAYED := $(DISPLAYED:.ml=.unlog.js) $(DISPLAYED:.ml=.pseudo.js) $(DISPLAYED)
ALL_LINEOF := $(DISPLAYED:.ml=.token.js) $(DISPLAYED:.ml=.mlloc.js) $(DISPLAYED:.ml=.ptoken.js)
###############################################################
ocamldot :
$(MAKE) -C $(OCAMLDOT_DIR)
archi : all ocamldot
$(OCAMLDEP) *.ml > .depend
cat .depend | $(OCAMLDOT) | dot -Tpdf > archi_jsref.pdf
###############################################################
# Rules
##### Rule for cmi
# Ordering of these rules is important, mli rule must be first.
%.cmi: %.mli
ocamlc $(REPLACE_STDLIB) $(OCAMLCFLAGS) $<
%.cmi: %.ml $(MLTOJS_BIN)
$(MLTOJS) -mode cmi -I $(STDLIB_DIR) $<
##### Rule for log/unlog/token
%.log.js: %.ml %.cmi $(MLTOJS_BIN)
$(MLTOJS) -mode log -I $(STDLIB_DIR) $<
%.unlog.js: %.ml %.cmi $(MLTOJS_BIN)
$(MLTOJS) -mode unlog -I $(STDLIB_DIR) $<
%.token.js %.mlloc.js: %.ml %.cmi $(MLTOJS_BIN)
$(MLTOJS) -mode token -I $(STDLIB_DIR) $<
%.pseudo.js: %.ml %.cmi $(MLTOJS_BIN)
$(MLTOJS) -mode pseudo -I $(STDLIB_DIR) $<
%.ptoken.js: %.ml %.cmi $(MLTOJS_BIN)
$(MLTOJS) -mode ptoken -I $(STDLIB_DIR) $<
##### Rule for lineof.js
lineof.js: $(ALL_LINEOF) $(LINEOF_BIN)
$(LINEOF) -o $@ $(ALL_LINEOF)
##### Rule for assembly.js
#--LATER (optional) add as dependencies the unlog files: $(JSREF_ML:.ml=.unlog.js)
assembly.js: $(ASSEMBLY_JS) $(ASEMBLY_BIN)
$(ASSEMBLY) -o $@ $(ASSEMBLY_JS)
##### Rule for displayed_sources.js
displayed_sources.js: $(ALL_DISPLAYED) $(DISPLAYGEN_BIN)
$(DISPLAYGEN) -o $@ $(ALL_DISPLAYED)
###############################################################
# Short targets
jsjsref: assembly lineof display
cmi: $(JSREF_ML:.ml=.cmi) $(JSREF_MLI:.mli=.cmi)
gen: $(JSREF_ML:.ml=.log.js) $(JSREF_ML:.ml=.unlog.js) $(JSREF_ML:.ml=.token.js)
ref: JsInterpreter.log.js JsInterpreter.unlog.js JsInterpreter.token.js
pseudo: JsInterpreter.pseudo.js JsInterpreter.ptoken.js
log: $(JSREF_ML:.ml=.log.js) $(JSREF_ML:.ml=.token.js)
unlog: $(JSREF_ML:.ml=.unlog.js)
lineof: lineof.js
assembly: assembly.js
display: displayed_sources.js
clean_jsjsref:
rm -f lineof.js assembly.js displayed_sources.js
rm -f *.log.js *.unlog.js *.token.js *.pseudo.js *.ptoken.js *.mlloc.js
.PHONY: jsjsref cmi gen ref pseudo log unlog lineof assembly display clean_jsjsref
###############################################################
###############################################################
# ML-JSRef
OCAMLCFLAGS=
# Strip all extensions of $(ASSEMBLY_JS) and replace with .cmo
ASSEMBLY_ML_FILES := \
$(addsuffix .cmo,$(basename $(basename $(ASSEMBLY_JS_FILES)))) \
Run_js.cmo
ASSEMBLY_ML := \
$(STDLIB_DIR)/stdlib_fml.cmo \
$(ASSEMBLY_ML_FILES)
mljsref: fjs_of_fml.byte
mljsref_debug: OCAMLCFLAGS+=-g
mljsref_debug: mljsref
fjs_of_fml.byte: $(ASSEMBLY_ML)
ocamlfind ocamlc -linkpkg -package JS_Parser -o $@ $(OCAMLCFLAGS) $^
Run_js.cmo: Run_js.ml Run_js.mli Run_js.cmi
ocamlfind ocamlc -c -package JS_Parser $(OCAMLCFLAGS) $<
Translate_syntax.cmo: Translate_syntax.ml Translate_syntax.mli Translate_syntax.cmi
ocamlfind ocamlc -c -package JS_Parser $(OCAMLCFLAGS) $<
# Ordering of the .cmo rules is important. mli dependency forces "standard" compilation
%.cmo: %.ml %.mli %.cmi $(PPX_BIN)
ocamlc -c $(PPX_FLAG) $(OCAMLCFLAGS) $<
# Standalone .ml files
%.cmo: %.ml %.cmi $(PPX_BIN)
ocamlc -c $(REPLACE_STDLIB) $(PPX_FLAG) $(OCAMLCFLAGS) $<
clean_mljsref:
rm -f ./*.cmo
rm -f ./*.byte
.PHONY: mljsref clean_mljsref
##############################################################
##############################################################
# OCamlDocs
DOC_DIR = doc_build
# A dump file is used so indexes are correctly created with separate compilation
# Dump file cannot have a module twice, so must be recreated each run.
DUMP_FILE = $(DOC_DIR)/odoc.dump
DUMP = -dump $(DUMP_FILE) -load $(DUMP_FILE)
ODOC_FLAGS = -html -d $(DOC_DIR) $(DUMP) $(PPX_FLAG) -g $(ESDOCGEN)
doc: $(addprefix doc_build/,$(addsuffix .html,$(basename $(ASSEMBLY_ML_FILES))))
rm -f $(DUMP_FILE)
touch $(DOC_DIR)
$(DOC_DIR):
mkdir -p $@
$(DUMP_FILE): $(DOC_DIR)
ocamldoc -html -d $(DOC_DIR) -dump $(DUMP_FILE)
$(DOC_DIR)/%.html $(DOC_DIR)/type_%.html: %.ml %.mli %.cmi $(PPX_BIN) $(ESDOCGEN) $(DUMP_FILE)
ocamlfind ocamldoc $(ODOC_FLAGS) -package JS_Parser $(*F).ml $(*F).mli
$(DOC_DIR)/%.html $(DOC_DIR)/type_%.html: %.ml %.cmi $(PPX_BIN) $(ESDOCGEN) $(DUMP_FILE)
ocamldoc $(ODOC_FLAGS) $(STDLIB_FLAG) $<
.PHONY: doc
##############################################################
##############################################################
# Global options
clean: clean_jsjsref clean_mljsref
rm -f *.cmi *.cmo *.unlog.js .depend archi_jsref.pdf *.url.js
rm -Rf $(DOC_DIR)
$(MAKE) -C $(OCAMLDOT_DIR) clean
# Phony global targets
.PHONY: all clean
.SECONDARY: # Do not delete intermediate files.
.NOTPARALLEL: # Ordered execution expected due to ocamlc writing out cmi files.