-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakefile
99 lines (68 loc) · 2.13 KB
/
makefile
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# makefile - build system for CARVE
#
# Common targets:
#
# * `make`: Builds
#
#
#
# @author: Cade Brown <[email protected]>
# -*- Programs -*-
# Emscripten compiler, assumes you have loaded the Emscripten SDK through
# your dotfiles, or via `source /path/to/emsdk/emsdk_env.sh`
EMCC := emcc
# -*- Checks -*-
# Check for Emscripten (EMCC)
ifneq ($(shell $(EMCC) --version > /dev/null; echo $$?),0)
$(error Emscripten is not installed or loaded ($$(EMCC)=$(EMCC)). Try loading the environment variables, or setting `EMCC` to the Emscripten compiler)
endif
# -*- Options -*-
# Emscripten compiler flags
EMCC_CFLAGS := -sASSERTIONS=1 -sSAFE_HEAP=1 -sDEMANGLE_SUPPORT=1 -sNO_EXIT_RUNTIME=0
# Emscripten linker flags (for final compilation)
EMCC_LDFLAGS := -sWASM=1 -sFORCE_FILESYSTEM=1 \
-sEXTRA_EXPORTED_RUNTIME_METHODS=[\"ccall\",\"cwrap\",\"stringToUTF8\",\"UTF8ToString\"] \
-sEXPORTED_FUNCTIONS=[\"_malloc\",\"_free\"]
CXXFLAGS += -g
# -*- Files -*-
src_CC := $(sort $(wildcard src/*.cc) $(wildcard src/impl/*.cc) src/insts.cc src/exec.cc)
src_HH := $(wildcard src/*.hh)
src_O := $(patsubst %.cc,build/%.o,$(src_CC))
src_EMCCO := $(patsubst %.cc,build/%.emcco,$(src_CC))
out_LIB_JS := docs/js/lib/libcarve.js
out_CLI := carve
# -*- Rules -*-
.PHONY: default all clean lib bin update
default: lib bin
update: lib bin
all: lib bin
clean:
rm -rf $(wildcard $(src_O) $(src_EMCCO) $(out_LIB_JS) $(out_CLI))
lib: $(out_LIB_JS)
bin: $(out_CLI)
# Generated files
src/insts.cc: tools/geninsts.py tools/riscvdata.py
$< > $@
src/exec.cc: tools/genexec.py tools/riscvdata.py
$< > $@
src/dsmblr.cc: tools/gendsmblr.py tools/riscvdata.py
$< > $@
$(out_LIB_JS): $(src_EMCCO) src/pre.js
@mkdir -p $(dir $@)
$(EMCC) \
$(EMCC_LDFLAGS) \
-sMODULARIZE=1 -sEXPORT_NAME='loadlibcarve' \
$(src_EMCCO) \
--pre-js src/pre.js \
-o $@
$(out_CLI): $(src_O) build/src/cli/main.o
@mkdir -p $(dir $@)
$(CXX) \
$^ \
-o $@
build/%.o: %.cc $(src_H)
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -Isrc $< -c -fPIC -o $@
build/%.emcco: %.cc $(src_H)
@mkdir -p $(dir $@)
$(EMCC) $(EMCC_CFLAGS) -Isrc $< -c -fPIC -o $@