-
Notifications
You must be signed in to change notification settings - Fork 25
/
Makefile.wasm
47 lines (33 loc) · 1.47 KB
/
Makefile.wasm
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
EMCC = emcc
SRC_DIR = src
OBJ_DIR = obj_wasm
BUILD_DIR = build_wasm
OUTPUT = emuframe
.PHONY: all
SOURCES := $(wildcard $(SRC_DIR)/*.cpp) $(wildcard $(SRC_DIR)/sdl/*.cpp) \
$(wildcard $(SRC_DIR)/lite/*.cpp) $(wildcard $(SRC_DIR)/wasm/*.cpp)
SOURCES := $(filter-out $(SRC_DIR)/sdl/sdlPalFile.cpp, $(SOURCES))
TARGETS := $(BUILD_DIR)/$(OUTPUT).js $(BUILD_DIR)/$(OUTPUT).wasm
PRE_JS := $(SRC_DIR)/wasm/prejs.js
SRC_WEB_FILES := index.html emu80.js emuframe.html dummyframe.html const.js emu80.css readme.txt
EMFLAGS := -c -g2 -O3 -std=c++11 -DPAL_SDL -DPAL_LITE -DPAL_WASM -sUSE_SDL=2
LDFLAGS := -sUSE_SDL=2 -sFETCH=1 -sASYNCIFY=1 -sEXPORTED_RUNTIME_METHODS=ccall --pre-js $(PRE_JS)
OBJECTS := $(patsubst $(SRC_DIR)/%,$(OBJ_DIR)/%,$(SOURCES:.cpp=.o))
DEPENDS := $(patsubst $(SRC_DIR)/%,$(OBJ_DIR)/%,$(SOURCES:.cpp=.d))
SRC_WEB_FILES := $(foreach file,$(SRC_WEB_FILES),$(SRC_DIR)/wasm/web/$(file))
WEB_FILES := $(foreach file,$(SRC_WEB_FILES),$(BUILD_DIR)/$(notdir $(file)))
all: $(TARGETS) $(WEB_FILES)
$(TARGETS): $(OBJECTS)
@mkdir -p $(dir $@)
$(EMCC) $(OBJECTS) $(LDFLAGS) -o $(BUILD_DIR)/$(OUTPUT).js
$(OBJECTS): $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(OBJ_DIR)/%.d
$(EMCC) $(EMFLAGS) $< -o $@
$(DEPENDS): $(OBJ_DIR)/%.d: $(SRC_DIR)/%.cpp
@mkdir -p $(dir $@)
$(EMCC) -MM -MP -MT"$(@:.d=.o)" $(EMFLAGS) $< > $@
$(WEB_FILES): $(SRC_WEB_FILES)
@mkdir -p $(BUILD_DIR)
cp -f $(SRC_WEB_FILES) $(BUILD_DIR)
clean:
-rm -f $(OBJECTS) $(DEPENDS) $(TARGETS) $(WEB_FILES)
-include $(DEPENDS)