• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Makefile to use with 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` will produce three files:
10#  - web/index.html (current stored in the repository)
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.js
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_wgpu.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)
35EMS += -s DISABLE_EXCEPTION_CATCHING=1
36LDFLAGS += -s USE_GLFW=3 -s USE_WEBGPU=1
37LDFLAGS += -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1
38
39# Emscripten allows preloading a file or folder to be accessible at runtime.
40# The Makefile for this example project suggests embedding the misc/fonts/ folder into our application, it will then be accessible as "/fonts"
41# See documentation for more details: https://emscripten.org/docs/porting/files/packaging_files.html
42# (Default value is 0. Set to 1 to enable file-system and include the misc/fonts/ folder as part of the build.)
43USE_FILE_SYSTEM ?= 0
44ifeq ($(USE_FILE_SYSTEM), 0)
45LDFLAGS += -s NO_FILESYSTEM=1
46CPPFLAGS += -DIMGUI_DISABLE_FILE_FUNCTIONS
47endif
48ifeq ($(USE_FILE_SYSTEM), 1)
49LDFLAGS += --no-heap-copy --preload-file ../../misc/fonts@/fonts
50endif
51
52##---------------------------------------------------------------------
53## FINAL BUILD FLAGS
54##---------------------------------------------------------------------
55
56CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
57#CPPFLAGS += -g
58CPPFLAGS += -Wall -Wformat -Os $(EMS)
59#LDFLAGS += --shell-file shell_minimal.html
60LDFLAGS += $(EMS)
61
62##---------------------------------------------------------------------
63## BUILD RULES
64##---------------------------------------------------------------------
65
66%.o:%.cpp
67	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
68
69%.o:$(IMGUI_DIR)/%.cpp
70	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
71
72%.o:$(IMGUI_DIR)/backends/%.cpp
73	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
74
75all: $(EXE)
76	@echo Build complete for $(EXE)
77
78$(WEB_DIR):
79	mkdir $@
80
81serve: all
82	python3 -m http.server -d $(WEB_DIR)
83
84$(EXE): $(OBJS) $(WEB_DIR)
85	$(CXX) -o $@ $(OBJS) $(LDFLAGS)
86
87clean:
88	rm -f $(EXE) $(OBJS) $(WEB_DIR)/*.js $(WEB_DIR)/*.wasm $(WEB_DIR)/*.wasm.pre
89