-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
50 lines (38 loc) · 1.12 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
# Build-time dependencies
CC = emcc
WASM_OPT = "$(EMSDK)/upstream/bin/wasm-opt"
ROLLUP = npx rollup
TERSER = npx terser
BUILD_DIR ?= ./build
SRC_DIRS ?= ./src
RELEASE=1
ifeq ($(RELEASE),1)
OPT_FLAGS = -O2
else
OPT_FLAGS = -g4 --source-map-base "http://0.0.0.0:7001/build/" # -s DEMANGLE_SUPPORT=1
endif
LDFLAGS = $(OPT_FLAGS) --no-entry -s WASM=1 -s ERROR_ON_UNDEFINED_SYMBOLS=0
CFLAGS ?= $(INC_FLAGS) -MMD -MP $(OPT_FLAGS) -W -Wall -Wextra
SRCS := $(shell find $(SRC_DIRS) -name "*.c")
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
all: $(BUILD_DIR)/webuxn.wasm $(BUILD_DIR)/webuxn.min.js
$(BUILD_DIR)/webuxn.wasm: $(OBJS)
$(CC) $(OBJS) -o $@ $(LDFLAGS)
ifeq ($(RELEASE),1)
$(WASM_OPT) -O4 $@ -o [email protected]
mv [email protected] $@
endif
$(BUILD_DIR)/%.wat: $(BUILD_DIR)/%.wasm
$(WASM_DIS) $< -o $@
$(BUILD_DIR)/%.c.o: %.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/%.min.js: %.js
$(ROLLUP) $< --format iife --output.name webuxn | $(TERSER) --compress --mangle > $@
.PHONY: clean
clean:
$(RM) -r $(BUILD_DIR)
-include $(DEPS)