11# This Makefile uses dune but does not rely on ocamlfind or the Opam
22# package manager to build. However, Opam package management is available
3- # optionally through the check/ install/uninstall targets .
3+ # optionally through the install target .
44#
55# The $(JSLIB).js target requires Js_of_ocaml (using ocamlfind).
66#
99
1010# Configuration
1111
12- NAME = wasm
13- OPT = $(NAME ) .exe
14- ZIP = $(NAME ) .zip
12+ NAME = wasm
13+ LIB = $(NAME )
1514JSLIB = wast.js
15+ ZIP = $(NAME ) .zip
1616
17- BUILDDIR = _build/default
17+ BUILDDIR = _build/default
1818
1919JS = # set to JS shell command to run JS tests, empty to skip
2020
2121
2222# Main targets
2323
24- .PHONY : default opt jslib all zip smallint
24+ .PHONY : default all ci jslib zip
25+
26+ default : $(NAME )
27+ all : default test
28+ ci : all jslib zip
2529
26- default : $(OPT )
2730jslib : $(JSLIB )
28- all : $(OPT ) test
2931zip : $(ZIP )
30- smallint : smallint.exe
31- ci : all jslib
3232
33- # Building executable
34- .PHONY : $(NAME ) .exe
35- $(NAME ) .exe :
36- rm -f $(NAME )
37- dune build $@
38- cp $(BUILDDIR ) /$(OPT ) $(NAME )
3933
40- .PHONY : smallint.exe
41- smallint.exe :
42- dune build $@
34+ # Building
35+
36+ $(NAME ) :
37+ rm -f $@
38+ dune build $@ .exe
39+ ln $(BUILDDIR ) /$@ .exe $@
40+
41+ $(JSLIB ) :
42+ rm -f $@
43+ dune build $(@:%.js=%.bc.js )
44+ ln $(BUILDDIR ) /$(@:%.js=%.bc.js ) $@
45+
46+
47+ # Unit tests
48+
49+ UNITTESTDIR = unittest
50+ UNITTESTFILES = $(shell cd $(UNITTESTDIR ) ; ls * .ml)
51+ UNITTESTS = $(UNITTESTFILES:%.ml=% )
4352
44- # Building JavaScript library
53+ .PHONY : unittest
4554
46- $(JSLIB ) : $(BUILDDIR ) /$(JSLIB )
47- cp $< $@
55+ unittest : $(UNITTESTS:%=unittest/% )
4856
49- $(BUILDDIR ) /$(JSLIB ) :
50- dune build $(JSLIB )
57+ unittest/% :
58+ dune build $(@F ) .exe
59+ dune exec ./$(@F ) .exe
5160
52- # Executing test suite
61+
62+ # Test suite
5363
5464TESTDIR = ../test/core
55- # Skip _output directory, since that's a tmp directory, and list all other wast files.
5665TESTFILES = $(shell cd $(TESTDIR ) ; ls * .wast; ls [a-z]* /* .wast)
5766TESTS = $(TESTFILES:%.wast=% )
5867
59- .PHONY : test partest dune-test
68+ .PHONY : test partest quiettest
69+
70+ test : $(NAME ) unittest
71+ $(TESTDIR ) /run.py --wasm ` pwd` /$(NAME ) $(if $(JS ) ,--js '$(JS ) ',)
6072
61- test : $(OPT ) smallint
62- $(TESTDIR ) /run.py --wasm ` pwd` /$(BUILDDIR ) /$(OPT ) $(if $(JS ) ,--js '$(JS ) ',)
63- dune exec ./smallint.exe
73+ test/% : $(NAME )
74+ $(TESTDIR ) /run.py --wasm ` pwd` /$(NAME ) $(if $(JS ) ,--js '$(JS ) ',) $(TESTDIR ) /$* .wast
6475
65- test /% : $( OPT )
66- $( TESTDIR ) /run.py --wasm ` pwd ` /$(BUILDDIR ) / $( OPT ) $( if $( JS ) ,--js ' $( JS ) ', ) $(TESTDIR ) /$* .wast
76+ run /% : $( NAME )
77+ . /$(NAME ) $(TESTDIR ) /$* .wast
6778
68- run/ % : $( OPT )
69- ./ $( OPT ) $( TESTDIR ) / $* .wast
79+ partest : $( NAME )
80+ make -j10 quiettest
7081
71- partest : $(TESTS:%=quiettest/% )
72- @echo All tests passed.
82+ quiettest : $(TESTS:%=quiettest/% )
83+ @echo All tests passed.
7384
74- quiettest/% : $( OPT )
75- @ ( \
76- $(TESTDIR ) /run.py 2> $(@F ) .out --wasm ` pwd` /$(BUILDDIR ) / $( OPT ) $(if $(JS ) ,--js '$(JS ) ',) $(TESTDIR ) /$* .wast && \
77- rm $(@F ) .out \
78- ) || \
79- cat $(@F ) .out || rm $(@F ) .out || exit 1
85+ quiettest/% : $( NAME )
86+ @ ( \
87+ $(TESTDIR ) /run.py 2> $(@F ) .out --wasm ` pwd` /$(NAME ) $(if $(JS ) ,--js '$(JS ) ',) $(TESTDIR ) /$* .wast && \
88+ rm $(@F ) .out \
89+ ) || \
90+ cat $(@F ) .out || rm $(@F ) .out || exit 1
8091
81- smallinttest : smallint
82- dune exec ./smallint.exe
8392
84- dunetest :
85- dune test
93+ # Packaging
94+
95+ .PHONY : install
8696
8797install :
8898 dune build -p $(NAME ) @install
@@ -101,15 +111,16 @@ opam-release/%:
101111 rm opam-$* .zip
102112 @echo Created file ./opam, submit to github opam-repository/packages/wasm/wasm.$* /opam
103113
104- # Miscellaneous targets
105-
106- .PHONY : clean
107-
108114$(ZIP ) :
109115 git archive --format=zip --prefix=$(NAME ) / -o $@ HEAD
110116
117+
118+ # Cleanup
119+
120+ .PHONY : clean distclean
121+
111122clean :
112123 dune clean
113124
114125distclean : clean
115- rm -f $(NAME ) $(JSLIB )
126+ rm -f $(NAME ) $(JSLIB ) $( ZIP )
0 commit comments