3.3 KB、95行 生 Blame 履歴
1#
2# Makefile to use with GLFW+emscripten
3# See https://emscripten.org/docs/getting_started/downloads.html
4# for installation instructions.
5#
6# This Makefile assumes you have loaded emscripten's environment.
7# (On Windows, you may need to execute emsdk_env.bat or encmdprompt.bat ahead)
8#
9# Running `make -f Makefile.emscripten` will produce three files:
10# - web/index.html
11# - web/index.js
12# - web/index.wasm
13#
14# All three are needed to run the demo.
15
16CC = emcc
17CXX = em++
18WEB_DIR = web
19EXE = $(WEB_DIR)/index.html
20IMGUI_DIR = ../..
21SOURCES = main.cpp
22SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp
23SOURCES += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp
24OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
25UNAME_S := $(shell uname -s)
26CPPFLAGS =
27LDFLAGS =
28EMS =
29
30##---------------------------------------------------------------------
31## EMSCRIPTEN OPTIONS
32##---------------------------------------------------------------------
33
34# ("EMS" options gets added to both CPPFLAGS and LDFLAGS, whereas some options are for linker only)
35# Note: For glfw, we use emscripten-glfw port (contrib.glfw3) instead of ('-s USE_GLFW=3' in LDFLAGS) to get a better support for High DPI displays.
36EMS += -s DISABLE_EXCEPTION_CATCHING=1 --use-port=contrib.glfw3
37LDFLAGS += -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1
38
39# Build as single file (binary text encoded in .html file)
40#LDFLAGS += -sSINGLE_FILE
41
42# Uncomment next line to fix possible rendering bugs with Emscripten version older then 1.39.0 (https://github.com/ocornut/imgui/issues/2877)
43#EMS += -s BINARYEN_TRAP_MODE=clamp
44#EMS += -s SAFE_HEAP=1 ## Adds overhead
45
46# Emscripten allows preloading a file or folder to be accessible at runtime.
47# The Makefile for this example project suggests embedding the misc/fonts/ folder into our application, it will then be accessible as "/fonts"
48# See documentation for more details: https://emscripten.org/docs/porting/files/packaging_files.html
49# (Default value is 0. Set to 1 to enable file-system and include the misc/fonts/ folder as part of the build.)
50USE_FILE_SYSTEM ?= 0
51ifeq ($(USE_FILE_SYSTEM), 0)
52LDFLAGS += -s NO_FILESYSTEM=1
53CPPFLAGS += -DIMGUI_DISABLE_FILE_FUNCTIONS
54endif
55ifeq ($(USE_FILE_SYSTEM), 1)
56LDFLAGS += --no-heap-copy --preload-file ../../misc/fonts@/fonts
57endif
58
59##---------------------------------------------------------------------
60## FINAL BUILD FLAGS
61##---------------------------------------------------------------------
62
63CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
64#CPPFLAGS += -g
65CPPFLAGS += -Wall -Wformat -Os $(EMS)
66LDFLAGS += --shell-file ../libs/emscripten/shell_minimal.html
67LDFLAGS += $(EMS)
68
69##---------------------------------------------------------------------
70## BUILD RULES
71##---------------------------------------------------------------------
72
73%.o:%.cpp
74 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
75
76%.o:$(IMGUI_DIR)/%.cpp
77 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
78
79%.o:$(IMGUI_DIR)/backends/%.cpp
80 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
81
82all: $(EXE)
83 @echo Build complete for $(EXE)
84
85$(WEB_DIR):
86 mkdir $@
87
88serve: all
89 python3 -m http.server -d $(WEB_DIR)
90
91$(EXE): $(OBJS) $(WEB_DIR)
92 $(CXX) -o $@ $(OBJS) $(LDFLAGS)
93
94clean:
95 rm -rf $(OBJS) $(WEB_DIR)