1# Build a library allowing FFI access to the Wasm spec interpreter. 2 3OCAML_FLAGS := -g -keep-locs -runtime-variant _pic 4# By default, we build in a sub-directory but we can override this with `make 5# BUILD_DIR=...`. 6BUILD_DIR := _build 7# Currently the WebAssembly spec interpreter is buried in a Git submodule as is 8# its build directory, `_build`. Cargo may not like that files are changing 9# outside of `target` (TODO). 10SPEC_DIR := spec/interpreter 11SPEC_BUILD_DIR := $(SPEC_DIR)/_build 12SPEC_LIB := $(SPEC_BUILD_DIR)/wasm.cmxa 13 14# A space-separated list of paths that the linker will use to search for libgmp. 15# Override with `make LIBGMP_PATHS=...`. 16LIBGMP_PATHS ?= /usr/lib /usr/lib/x86_64-linux-gnu /lib64 17 18PKGS = zarith 19 20# Build and package the static library, `libinterpret.a`. 21$(BUILD_DIR)/libinterpret.a: $(BUILD_DIR)/interpret.lib.o 22 ar qs $@ $^ 23$(BUILD_DIR)/interpret.lib.o: $(SPEC_LIB) $(BUILD_DIR)/interpret.cmx 24 ocamlfind ocamlopt $(OCAML_FLAGS) -I $(SPEC_BUILD_DIR) -o $@ -output-complete-obj $^ -linkpkg $(PKGS:%=-package %) -cclib "$(LIBGMP_PATHS:%=-L%)" 25$(BUILD_DIR)/interpret.cmx: interpret.ml $(SPEC_BUILD_DIR) $(BUILD_DIR) 26 ocamlfind ocamlopt $(OCAML_FLAGS) -I $(SPEC_BUILD_DIR) -o $@ -c -impl $< -linkpkg $(PKGS:%=-package %) 27$(BUILD_DIR): 28 mkdir -p $@ 29 30 31# We also need to be able to build the spec's `wasm.cmxa`. 32$(SPEC_LIB): 33 make -C $(SPEC_DIR) libopt 34 35 36clean: 37 rm -rf $(BUILD_DIR) 38 make -C $(SPEC_DIR) clean 39