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 partest
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
4335
44- # Building JavaScript library
36+ .PHONY : $( NAME ) $( JSLIB )
4537
46- $(JSLIB ) : $(BUILDDIR ) /$(JSLIB )
47- cp $< $@
38+ $(NAME ) :
39+ rm -f $@
40+ dune build $@ .exe
41+ ln $(BUILDDIR ) /$@ .exe $@
4842
49- $(BUILDDIR ) /$(JSLIB ) :
50- dune build $(JSLIB )
43+ $(JSLIB ) :
44+ rm -f $@
45+ dune build $(@:%.js=%.bc.js )
46+ ln $(BUILDDIR ) /$(@:%.js=%.bc.js ) $@
5147
52- # Executing test suite
48+
49+ # Test suite
5350
5451TESTDIR = ../test/core
55- # Skip _output directory, since that's a tmp directory, and list all other wast files.
56- TESTFILES = $(shell cd $(TESTDIR ) ; ls * .wast; ls [a-z]* /* .wast)
52+ TESTFILES = $(shell cd $(TESTDIR ) > /dev/null; ls * .wast; ls [a-z]* /* .wast)
5753TESTS = $(TESTFILES:%.wast=% )
5854
59- .PHONY : test partest dune-test
55+ .PHONY : test partest quiettest
56+
57+ test : $(NAME )
58+ $(TESTDIR ) /run.py --wasm ` pwd` /$(NAME ) $(if $(JS ) ,--js '$(JS ) ',)
59+
60+ test/% : $(NAME )
61+ $(TESTDIR ) /run.py --wasm ` pwd` /$(NAME ) $(if $(JS ) ,--js '$(JS ) ',) $(TESTDIR ) /$* .wast
6062
61- test : $(OPT ) smallint
62- $(TESTDIR ) /run.py --wasm ` pwd` /$(BUILDDIR ) /$(OPT ) $(if $(JS ) ,--js '$(JS ) ',)
63- dune exec ./smallint.exe
63+ run/% : $(NAME )
64+ ./$(NAME ) $(TESTDIR ) /$* .wast
6465
65- test/ % : $( OPT )
66- $( TESTDIR ) /run.py --wasm ` pwd ` / $( BUILDDIR ) / $( OPT ) $( if $( JS ) ,--js ' $( JS ) ',) $( TESTDIR ) / $* .wast
66+ partest : $( NAME )
67+ make -j10 quiettest
6768
68- run/ % : $( OPT )
69- ./ $( OPT ) $( TESTDIR ) / $* .wast
69+ quiettest : $( TESTS:%=quiettest/% )
70+ @echo All tests passed.
7071
71- partest : $(TESTS:%=quiettest/% )
72- @echo All tests passed.
72+ quiettest/% : $(NAME )
73+ @ ( \
74+ $(TESTDIR ) /run.py 2> $(@F ) .out --wasm ` pwd` /$(NAME ) $(if $(JS ) ,--js '$(JS ) ',) $(TESTDIR ) /$* .wast && \
75+ rm $(@F ) .out \
76+ ) || \
77+ (cat $( @F) .out && rm $( @F) .out && exit 1)
7378
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
8079
81- smallinttest : smallint
82- dune exec ./smallint.exe
80+ # Packaging
8381
84- dunetest :
85- dune test
82+ .PHONY : install
8683
8784install :
8885 dune build -p $(NAME ) @install
@@ -101,15 +98,16 @@ opam-release/%:
10198 rm opam-$* .zip
10299 @echo Created file ./opam, submit to github opam-repository/packages/wasm/wasm.$* /opam
103100
104- # Miscellaneous targets
105-
106- .PHONY : clean
107-
108101$(ZIP ) :
109102 git archive --format=zip --prefix=$(NAME ) / -o $@ HEAD
110103
104+
105+ # Cleanup
106+
107+ .PHONY : clean distclean
108+
111109clean :
112110 dune clean
113111
114112distclean : clean
115- rm -f $(NAME ) $(JSLIB )
113+ rm -f $(NAME ) $(JSLIB ) $( ZIP )
0 commit comments