|
2 | 2 | # package manager to build. However, Opam package management is available
|
3 | 3 | # optionally through the check/install/uninstall targets.
|
4 | 4 | #
|
5 |
| -# The $(JSLIB) target requires node.js and BuckleScript. |
| 5 | +# The wast.js target requires node.js and BuckleScript. |
6 | 6 | #
|
7 | 7 | # See README.me for instructions.
|
8 | 8 |
|
9 | 9 |
|
10 | 10 | # Configuration
|
11 | 11 |
|
12 |
| -NAME = wasm |
13 |
| -UNOPT = $(NAME).debug |
14 |
| -OPT = $(NAME) |
15 |
| -LIB = $(NAME) |
16 |
| -ZIP = $(NAME).zip |
17 |
| -JSLIB = wast.js |
18 |
| -WINMAKE = winmake.bat |
19 |
| - |
20 |
| -DIRS = util syntax binary text valid runtime exec script host main tests |
21 |
| -LIBS = bigarray |
22 |
| -FLAGS = -lexflags -ml -cflags '-w +a-4-27-42-44-45 -warn-error +a-3' |
23 |
| -OCBA = ocamlbuild $(FLAGS) $(DIRS:%=-I %) |
24 |
| -OCB = $(OCBA) $(LIBS:%=-libs %) |
25 |
| -JS = # set to JS shell command to run JS tests |
26 |
| - |
| 12 | +BUILDDIR = _build/default |
| 13 | +UNOPT = $(BUILDDIR)/main/main.bc |
| 14 | +OPT = $(BUILDDIR)/main/main.exe |
| 15 | +JS = # set to JS shell command to run JS tests |
| 16 | +TESTDIR = ../test/core |
| 17 | +# Skip _output directory, since that's a tmp directory, and list all other wast files. |
| 18 | +TESTFILES = $(shell cd $(TESTDIR); ls *.wast; ls [a-z]*/*.wast) |
27 | 19 |
|
28 | 20 | # Main targets
|
29 | 21 |
|
30 |
| -.PHONY: default opt unopt libopt libunopt jslib all land zip smallint |
31 |
| - |
32 |
| -default: opt |
33 |
| -debug: unopt |
34 |
| -opt: $(OPT) |
35 |
| -unopt: $(UNOPT) |
36 |
| -libopt: _build/$(LIB).cmx _build/$(LIB).cmxa |
37 |
| -libunopt: _build/$(LIB).cmo _build/$(LIB).cma |
38 |
| -jslib: $(JSLIB) |
39 |
| -all: unopt opt libunopt libopt test |
40 |
| -land: $(WINMAKE) all |
41 |
| -zip: $(ZIP) |
42 |
| -smallint: smallint.native |
43 |
| - |
44 |
| - |
45 |
| -# Building executable |
46 |
| - |
47 |
| -empty = |
48 |
| -space = $(empty) $(empty) |
49 |
| -comma = , |
50 |
| - |
51 |
| -.INTERMEDIATE: _tags |
52 |
| -_tags: |
53 |
| - echo >$@ "true: bin_annot" |
54 |
| - echo >>$@ "true: debug" |
55 |
| - echo >>$@ "<{$(subst $(space),$(comma),$(DIRS))}/*.cmx>: for-pack($(PACK))" |
56 |
| - |
57 |
| -$(UNOPT): main.byte |
58 |
| - mv $< $@ |
59 |
| - |
60 |
| -$(OPT): main.native |
61 |
| - mv $< $@ |
62 |
| - |
63 |
| -.PHONY: main.byte main.native |
64 |
| -main.byte: _tags |
65 |
| - $(OCB) -quiet $@ |
66 |
| - |
67 |
| -main.native: _tags |
68 |
| - $(OCB) -quiet $@ |
69 |
| - |
70 |
| -.PHONY: smallint.byte smallint.native |
71 |
| -smallint.byte: _tags |
72 |
| - $(OCB) -quiet $@ |
73 |
| -smallint.native: _tags |
74 |
| - $(OCB) -quiet $@ |
75 |
| - |
76 |
| - |
77 |
| -# Building library |
78 |
| - |
79 |
| -FILES = $(shell ls $(DIRS:%=%/*) | grep '[.]ml[^.]*$$') |
80 |
| -PACK = $(shell echo `echo $(LIB) | sed 's/^\(.\).*$$/\\1/g' | tr [:lower:] [:upper:]``echo $(LIB) | sed 's/^.\(.*\)$$/\\1/g'`) |
| 22 | +.PHONY: default jslib all land zip |
81 | 23 |
|
82 |
| -.INTERMEDIATE: $(LIB).mlpack |
83 |
| -$(LIB).mlpack: $(DIRS) |
84 |
| - ls $(FILES) \ |
85 |
| - | sed 's:\(.*/\)\{0,1\}\(.*\)\.[^\.]*:\2:' \ |
86 |
| - | grep -v main \ |
87 |
| - | sort | uniq \ |
88 |
| - >$@ |
89 |
| -
|
90 |
| -.INTERMEDIATE: $(LIB).mllib |
91 |
| -$(LIB).mllib: |
92 |
| - echo Wasm >$@ |
93 |
| -
|
94 |
| -_build/$(LIB).cmo: $(FILES) $(LIB).mlpack _tags Makefile |
95 |
| - $(OCB) -quiet $(LIB).cmo |
96 |
| -
|
97 |
| -_build/$(LIB).cmx: $(FILES) $(LIB).mlpack _tags Makefile |
98 |
| - $(OCB) -quiet $(LIB).cmx |
99 |
| -
|
100 |
| -_build/$(LIB).cma: $(FILES) $(LIB).mllib _tags Makefile |
101 |
| - $(OCBA) -quiet $(LIB).cma |
102 |
| -
|
103 |
| -_build/$(LIB).cmxa: $(FILES) $(LIB).mllib _tags Makefile |
104 |
| - $(OCBA) -quiet $(LIB).cmxa |
105 |
| -
|
106 |
| -
|
107 |
| -# Building JavaScript library |
108 |
| -
|
109 |
| -.PHONY: $(JSLIB) |
110 |
| -$(JSLIB): $(UNOPT) |
111 |
| - mkdir -p _build/jslib/src |
112 |
| - cp meta/jslib/* _build/jslib |
113 |
| - cp $(DIRS:%=_build/%/*.ml*) meta/jslib/*.ml _build/jslib/src |
114 |
| - rm _build/jslib/src/*.ml[^i] |
115 |
| - (cd _build/jslib; ./build.sh ../../$@) |
116 |
| -
|
117 |
| -
|
118 |
| -# Building Windows build file |
119 |
| -
|
120 |
| -$(WINMAKE): clean |
121 |
| - echo rem Auto-generated from Makefile! >$@ |
122 |
| - echo set NAME=$(NAME) >>$@ |
123 |
| - echo if \'%1\' neq \'\' set NAME=%1 >>$@ |
124 |
| - $(OCB) main.byte \ |
125 |
| - | grep -v ocamldep \ |
126 |
| - | grep -v mkdir \ |
127 |
| - | sed s:`which ocaml`:ocaml:g \ |
128 |
| - | sed s:main/main.d.byte:%NAME%.exe: \ |
129 |
| - >>$@ |
| 24 | +default: $(OPT) |
| 25 | +debug: $(UNOPT) |
| 26 | +jslib: $(BUILDDIR)/jslib/wasm.bc.js |
| 27 | +all: $(UNOPT) $(OPT) test |
| 28 | +land: all |
| 29 | +zip: wasm.zip |
130 | 30 |
|
| 31 | +$(BUILDDIR)/%: |
| 32 | + dune build $* |
131 | 33 |
|
132 | 34 | # Executing test suite
|
133 | 35 |
|
134 |
| -TESTDIR = ../test/core |
135 |
| -# Skip _output directory, since that's a tmp directory, and list all other wast files. |
136 |
| -TESTFILES = $(shell cd $(TESTDIR); ls *.wast; ls [a-z]*/*.wast) |
137 |
| -TESTS = $(TESTFILES:%.wast=%) |
| 36 | +.PHONY: test debugtest partest winmake.bat |
138 | 37 |
|
139 |
| -.PHONY: test debugtest partest |
| 38 | +winmake.bat: |
| 39 | + dune clean |
| 40 | + dune build main/main.bc |
| 41 | + cat _build/log | grep -v "^#" | sed s:`which ocaml`:ocaml:g | sed s:_build/default:_build/:g |
140 | 42 |
|
141 |
| -test: $(OPT) smallint |
142 |
| - $(TESTDIR)/run.py --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',) |
143 |
| - ./smallint.native |
144 |
| -debugtest: $(UNOPT) smallint |
145 |
| - $(TESTDIR)/run.py --wasm `pwd`/$(UNOPT) $(if $(JS),--js '$(JS)',) |
146 |
| - ./smallint.native |
| 43 | +test/%: $(OPT) |
| 44 | + $(TESTDIR)/run.py --wasm `pwd`/$< $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast |
| 45 | +debugtest/%: $(UNOPT) |
| 46 | + $(TESTDIR)/run.py --wasm `pwd`/$< $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast |
147 | 47 |
|
148 |
| -test/%: $(OPT) |
149 |
| - $(TESTDIR)/run.py --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast |
150 |
| -debugtest/%: $(UNOPT) |
151 |
| - $(TESTDIR)/run.py --wasm `pwd`/$(UNOPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast |
| 48 | +test: $(OPT) smallinttest |
| 49 | + $(TESTDIR)/run.py --wasm `pwd`/$< $(if $(JS),--js '$(JS)',) |
| 50 | +debugtest: $(UNOPT) smallinttest |
| 51 | + $(TESTDIR)/run.py --wasm `pwd`/$< $(if $(JS),--js '$(JS)',) |
152 | 52 |
|
153 |
| -run/%: $(OPT) |
154 |
| - ./$(OPT) $(TESTDIR)/$*.wast |
155 |
| -debug/%: $(UNOPT) |
156 |
| - ./$(UNOPT) $(TESTDIR)/$*.wast |
| 53 | +run/%: |
| 54 | + dune exec -- main/main.exe $(TESTDIR)/$*.wast |
| 55 | +debug/%: |
| 56 | + dune exec -- main/main.bc $(TESTDIR)/$*.wast |
157 | 57 |
|
158 |
| -partest: $(TESTS:%=quiettest/%) |
| 58 | +partest: $(TESTFILES:%.wast=quiettest/%) |
159 | 59 | @echo All tests passed.
|
160 | 60 |
|
161 |
| -quiettest/%: $(OPT) |
| 61 | +quiettest/%: $(OPT) |
162 | 62 | @ ( \
|
163 |
| - $(TESTDIR)/run.py 2>$(@F).out --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast && \ |
| 63 | + $(TESTDIR)/run.py 2>$(@F).out --wasm `pwd`/$< $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast && \ |
164 | 64 | rm $(@F).out \
|
165 | 65 | ) || \
|
166 | 66 | cat $(@F).out || rm $(@F).out || exit 1
|
167 | 67 |
|
168 |
| -smallinttest: smallint |
169 |
| - @./smallint.native |
| 68 | +smallinttest: |
| 69 | + dune runtest |
170 | 70 |
|
171 | 71 | # Miscellaneous targets
|
172 | 72 |
|
173 |
| -.PHONY: clean |
174 |
| -
|
175 |
| -$(ZIP): $(WINMAKE) |
176 |
| - git archive --format=zip --prefix=$(NAME)/ -o $@ HEAD |
| 73 | +wasm.zip: |
| 74 | + git archive --format=zip --prefix=wasm/ -o $@ HEAD |
177 | 75 |
|
178 | 76 | clean:
|
179 |
| - rm -rf _build/jslib $(LIB).mlpack _tags |
180 |
| - $(OCB) -clean |
181 |
| -
|
| 77 | + dune clean |
182 | 78 |
|
183 | 79 | # Opam support
|
184 | 80 |
|
185 |
| -.PHONY: check install uninstall |
186 |
| -
|
187 |
| -check: |
188 |
| - # Check that we can find all relevant libraries |
189 |
| - # when using ocamlfind |
190 |
| - ocamlfind query $(LIBS) |
191 |
| -
|
192 |
| -install: _build/$(LIB).cmx _build/$(LIB).cmo |
193 |
| - ocamlfind install $(LIB) meta/findlib/META _build/$(LIB).o \ |
194 |
| - $(wildcard _build/$(LIB).cm*) \ |
195 |
| - $(wildcard $(DIRS:%=%/*.mli)) |
| 81 | +install: |
| 82 | + dune install |
196 | 83 |
|
197 | 84 | uninstall:
|
198 |
| - ocamlfind remove $(LIB) |
| 85 | + dune uninstall |
0 commit comments