forked from technoblogy/ulisp-esp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wasm.mk
64 lines (50 loc) · 1.36 KB
/
wasm.mk
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
# Build uLisp for WebAssembly: wasm/ulisp.html, ulisp.js, ulisp.wasm
###############################################################################
# Typical Compile to WebAssembly with emscripten
# emcc hello.c -s WASM=1 -o hello.html
# WebAssembly C and C++ Source Files
WASM_CSRCS := src/ulisp.c
# Build uLisp app: wasm/ulisp.html, ulisp.js, ulisp.wasm
TARGETS:= wasm/ulisp
DEPS :=
# Use emscripten compiler
CC := emcc
CPP := em++
# Options for emscripten. We specify the C WebAssembly
# functions to be exported.
CCFLAGS := \
-g \
-I include \
-s WASM=1 \
-s "EXPORTED_FUNCTIONS=[ '_setup_ulisp', '_execute_ulisp' ]" \
-s "EXTRA_EXPORTED_RUNTIME_METHODS=[ 'cwrap', 'allocate', 'intArrayFromString' ]"
LDFLAGS :=
MAINS := $(addsuffix .o, $(TARGETS) )
OBJ := \
$(MAINS) \
$(CSRCS:.c=.o) \
$(WASM_CSRCS:.c=.o)
.PHONY: all clean
all: $(TARGETS)
clean:
rm *.o || true
rm wasm/*.o || true
rm wasm/*.wasm || true
rm wasm/*.js || true
rm wasm/*.txt || true
rm -r $(HOME)/.emscripten_cache || true
$(OBJ): %.o : %.c $(DEPS)
$(CC) -c -o $@ $< $(CCFLAGS)
# TODO: Build C++ files with em++
# $(OBJ): %.o : %.cpp $(DEPS)
# $(CPP) -c -o $@ $< $(CCFLAGS)
$(TARGETS): % : $(filter-out $(MAINS), $(OBJ)) %.o
$(CC) -o $@.html \
-Wl,--start-group \
$(LIBS) \
$^ \
-Wl,--end-group \
$(CCFLAGS) \
$(LDFLAGS)
cp wasm/ulisp.js docs
cp wasm/ulisp.wasm docs