-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
93 lines (75 loc) · 2.63 KB
/
Copy pathMakefile
File metadata and controls
93 lines (75 loc) · 2.63 KB
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
ifndef WASI_SDK_PATH
$(error Download the WASI SDK (https://github.com/WebAssembly/wasi-sdk) and set $$WASI_SDK_PATH)
endif
CC = "$(WASI_SDK_PATH)/bin/clang" --sysroot="$(WASI_SDK_PATH)/share/wasi-sysroot"
CXX = "$(WASI_SDK_PATH)/bin/clang++" --sysroot="$(WASI_SDK_PATH)/share/wasi-sysroot"
# Optional dependency from binaryen for smaller builds
WASM_OPT = wasm-opt
WASM_OPT_FLAGS = -Oz --zero-filled-memory --strip-producers --enable-bulk-memory
# Whether to build for debugging instead of release
DEBUG = 0
# Compilation flags
CFLAGS = -std=c2y -fblocks -W -Wall -Wextra -Werror -Wno-unused -Wconversion -Wsign-conversion -MMD -MP -fno-exceptions -mbulk-memory
ifeq ($(DEBUG), 1)
CFLAGS += -DDEBUG -O0 -g
else
CFLAGS += -DNDEBUG -Oz -flto
endif
CFLAGS += -I/opt/wasi-sdk/share/wasi-sysroot/include/wasm32-wasi/
# Linker flags
LDFLAGS = -Wl,-zstack-size=14752,--no-entry,--import-memory -mexec-model=reactor \
-Wl,--initial-memory=65536,--max-memory=65536,--stack-first
ifeq ($(DEBUG), 1)
LDFLAGS += -Wl,--export-all,--no-gc-sections
else
LDFLAGS += -Wl,--strip-all,--gc-sections,--lto-O3 -Oz
endif
OBJECTS = $(patsubst src/%.c, build/%.o, $(wildcard src/*.c))
OBJECTS += $(patsubst src/%.cpp, build/%.o, $(wildcard src/*.cpp))
OBJECTS += $(patsubst src/corefw/%.c, build/corefw/%.o, $(wildcard src/corefw/*.c))
OBJECTS += $(patsubst src/Block/%.c, build/Block/%.o, $(wildcard src/Block/*.c))
DEPS = $(OBJECTS:.o=.d)
ifeq '$(findstring ;,$(PATH))' ';'
DETECTED_OS := Windows
else
DETECTED_OS := $(shell uname 2>/dev/null || echo Unknown)
DETECTED_OS := $(patsubst CYGWIN%,Cygwin,$(DETECTED_OS))
DETECTED_OS := $(patsubst MSYS%,MSYS,$(DETECTED_OS))
DETECTED_OS := $(patsubst MINGW%,MSYS,$(DETECTED_OS))
endif
ifeq ($(DETECTED_OS), Windows)
MKDIR_BUILD = if not exist build md build build/corefw build/Block
RMDIR = rd /s /q
else
MKDIR_BUILD = mkdir -p build build/corefw build/Block
RMDIR = rm -rf
endif
all: build/cart.wasm
# Link cart.wasm from all object files and run wasm-opt
build/cart.wasm: $(OBJECTS)
$(CXX) -o $@ $(OBJECTS) $(LDFLAGS)
ifneq ($(DEBUG), 1)
ifeq (, $(shell command -v $(WASM_OPT)))
@echo Tip: $(WASM_OPT) was not found. Install it from binaryen for smaller builds!
else
$(WASM_OPT) $(WASM_OPT_FLAGS) $@ -o $@
endif
endif
# Compile C sources
build/%.o: src/%.c
@$(MKDIR_BUILD)
$(CC) -c $< -o $@ $(CFLAGS)
# Compile C++ sources
build/%.o: src/%.cpp
@$(MKDIR_BUILD)
$(CXX) -c $< -o $@ $(CFLAGS)
build/corefw/%.o: src/corefw/%.c
@$(MKDIR_BUILD/corefw)
$(CC) -c $< -o $@ $(CFLAGS)
build/Block/%.o: src/Block/%.c
@$(MKDIR_BUILD/Block)
$(CC) -c $< -o $@ $(CFLAGS)
.PHONY: clean
clean:
$(RMDIR) build
-include $(DEPS)