forked from gruppe-adler/grad_aff_wasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
71 lines (53 loc) · 1.95 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
SOURCES = grad_aff_paa.c
OUT_NAME = grad_aff_paa
OUT_DIR := release
COMPILERFLAGS :=
LDFLAGS :=
LIBS := grad_aff squish lzokay
EXPORTS = free malloc encode decode free_encoded_data get_last_aff_exception
# ###################################################################################################################
# Add default include dir if none was specified
ifeq ($(filter -I%,$(COMPILERFLAGS)),)
COMPILERFLAGS += -I/usr/local/include
endif
# Add default ibrary search path if none was specified
ifeq ($(filter -L%,$(COMPILERFLAGS)),)
COMPILERFLAGS += -L/usr/local/lib
endif
# General compiler flags
COMPILERFLAGS += -s STANDALONE_WASM
COMPILERFLAGS += -s ALLOW_MEMORY_GROWTH
COMPILERFLAGS += -Os
# General linker flags
LDFLAGS += --import-memory
LDFLAGS += --no-entry
# ###################################################################################################################
# Add ibraries to compiler flags
COMPILERFLAGS += $(addprefix -l, $(LIBS))
# Add expots to linker flags
LDFLAGS += $(addprefix --export=, $(EXPORTS))
# Add linker flags to clang flags with prefix "-Wl,"; clang will automatically pass them to the linker
comma := ,
COMPILERFLAGS += $(addprefix -Wl$(comma), $(LDFLAGS))
OUT_PATH := $(OUT_DIR)/$(OUT_NAME)
# ###################################################################################################################
all: $(OUT_DIR) $(OUT_PATH).wasm $(OUT_DIR)/index.html $(OUT_DIR)/index.js
clean:
rm -rf $(OUT_DIR)
# release directory
$(OUT_DIR):
mkdir -p $(OUT_DIR)
# optimized wasm
$(OUT_PATH).wasm : $(OUT_PATH)_unoptimized.wasm
wasm-opt -Oz $(OUT_PATH)_unoptimized.wasm -o $(OUT_PATH).wasm
# unoptimized wasm
$(OUT_PATH)_unoptimized.wasm : $(SOURCES)
emcc $(SOURCES) -o $(OUT_PATH)_unoptimized.wasm $(COMPILERFLAGS);
# index.html
$(OUT_DIR)/index.html: index.html
rm -f $(OUT_DIR)/index.html
cp index.html $(OUT_DIR)
# javascript
$(OUT_DIR)/index.js: index.ts tsconfig.json
tsc
cp index.ts $(OUT_DIR)