-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
136 lines (114 loc) · 2.64 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# if you are using windows, please comment line 3 and uncomment line 4 and 5
SRCDIR := src
SRCS := $(shell find $(SRCDIR) -name "*.cpp")
#SRCS := $(patsubst "%",%,$(shell FORFILES /P "$(SRCDIR)" /S /M *.cpp /C "CMD /C ECHO @relpath"))
#SRCS := $(subst \,/,$(SRCS:.\\%=$(SRCDIR)\\%))
# additional headers to include
HEADERS = \
node_modules/asm-dom/cpp/asm-dom.hpp
# additional files to compile
FILES = \
node_modules/asm-dom/cpp/asm-dom.cpp
# options used to compile the C++ code
CFLAGS = \
-O3 \
-Wall \
-Werror \
-Wall \
-Wno-deprecated \
-Wno-parentheses \
-Wno-format
# C++ => .wasm options
WASM_OPTIONS = \
-O3 \
--bind \
--memory-init-file 1 \
--llvm-lto 3 \
--llvm-opts 3 \
--js-opts 1 \
--closure 1 \
-s MODULARIZE=1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s AGGRESSIVE_VARIABLE_ELIMINATION=1 \
-s ABORTING_MALLOC=1 \
-s NO_EXIT_RUNTIME=1 \
-s NO_FILESYSTEM=1 \
-s DISABLE_EXCEPTION_CATCHING=2 \
-s BINARYEN=1 \
-s EXPORTED_RUNTIME_METHODS=[\'UTF8ToString\'] \
-s BINARYEN_TRAP_MODE=\'allow\'
# C++ => .asm.js options
ASMJS_OPTIONS = \
-O3 \
--bind \
--memory-init-file 1 \
--llvm-lto 3 \
--llvm-opts 3 \
--js-opts 1 \
--closure 1 \
-s MODULARIZE=1 \
-s AGGRESSIVE_VARIABLE_ELIMINATION=1 \
-s ELIMINATE_DUPLICATE_FUNCTIONS=1 \
-s ABORTING_MALLOC=1 \
-s NO_EXIT_RUNTIME=1 \
-s NO_FILESYSTEM=1 \
-s DISABLE_EXCEPTION_CATCHING=2 \
-s EXPORTED_RUNTIME_METHODS=[\'UTF8ToString\']
####### internals #######
OBJDIR := temp/o
DEPDIR := temp/dep
BC := temp/app.bc
INCLUDES := $(HEADERS:%=-include %)
GCCXSRCS := $(SRCS:%.cpp=%.cc)
OBJS := $(SRCS:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
DEPS := $(SRCS:$(SRCDIR)/%.cpp=$(DEPDIR)/%.d)
TREE := $(sort $(patsubst %/,%,$(dir $(OBJS))))
CPPFLAGS = -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d)
.PHONY: all clean install start
all: dist
clean:
npx rimraf dist temp $(GCCXSRCS)
install:
npm install
$(BC): $(OBJS)
emcc \
$(CFLAGS) \
--bind \
$(INCLUDES) \
$(OBJS) \
$(FILES) \
-o $(BC)
dist/wasm: $(BC)
npx mkdirp dist/wasm
emcc \
$(WASM_OPTIONS) \
$(BC) \
-o dist/wasm/app.js
dist/asmjs: $(BC)
npx mkdirp dist/asmjs
emcc \
$(ASMJS_OPTIONS) \
$(BC) \
-o dist/asmjs/app.asm.js
dist: dist/wasm dist/asmjs
npx cross-env NODE_ENV=production parcel build index.html --public-url /
start: dist/wasm dist/asmjs
npx cross-env NODE_ENV=development parcel index.html
$(SRCDIR)/%.cc: $(SRCDIR)/%.cpp
npx gccx $< -o $@
.SECONDEXPANSION:
$(OBJDIR)/%.o: $(SRCDIR)/%.cc | $$(@D)
emcc \
$(CFLAGS) \
--bind \
$(CPPFLAGS) \
$(INCLUDES) \
-c $< \
-o $@
npx rimraf $<
$(TREE): %:
npx mkdirp $@
npx mkdirp $(@:$(OBJDIR)%=$(DEPDIR)%)
ifeq "$(MAKECMDGOALS)" ""
-include $(DEPS)
endif