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