Makefile (2845B)
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 16 CC = emcc 17 CXX = em++ 18 WEB_DIR = web 19 EXE = $(WEB_DIR)/index.js 20 IMGUI_DIR = ../.. 21 SOURCES = main.cpp 22 SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp 23 SOURCES += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_wgpu.cpp 24 OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) 25 UNAME_S := $(shell uname -s) 26 27 ##--------------------------------------------------------------------- 28 ## EMSCRIPTEN OPTIONS 29 ##--------------------------------------------------------------------- 30 31 EMS += -s USE_GLFW=3 -s USE_WEBGPU=1 -s WASM=1 32 EMS += -s ALLOW_MEMORY_GROWTH=1 33 EMS += -s DISABLE_EXCEPTION_CATCHING=1 -s NO_EXIT_RUNTIME=0 34 EMS += -s ASSERTIONS=1 35 36 # Emscripten allows preloading a file or folder to be accessible at runtime. 37 # The Makefile for this example project suggests embedding the misc/fonts/ folder into our application, it will then be accessible as "/fonts" 38 # See documentation for more details: https://emscripten.org/docs/porting/files/packaging_files.html 39 # (Default value is 0. Set to 1 to enable file-system and include the misc/fonts/ folder as part of the build.) 40 USE_FILE_SYSTEM ?= 0 41 ifeq ($(USE_FILE_SYSTEM), 0) 42 EMS += -s NO_FILESYSTEM=1 -DIMGUI_DISABLE_FILE_FUNCTIONS 43 endif 44 ifeq ($(USE_FILE_SYSTEM), 1) 45 LDFLAGS += --no-heap-copy --preload-file ../../misc/fonts@/fonts 46 endif 47 48 ##--------------------------------------------------------------------- 49 ## FINAL BUILD FLAGS 50 ##--------------------------------------------------------------------- 51 52 CPPFLAGS = -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends 53 #CPPFLAGS += -g 54 CPPFLAGS += -Wall -Wformat -Os 55 CPPFLAGS += $(EMS) 56 LIBS += $(EMS) 57 #LDFLAGS += --shell-file shell_minimal.html 58 59 ##--------------------------------------------------------------------- 60 ## BUILD RULES 61 ##--------------------------------------------------------------------- 62 63 %.o:%.cpp 64 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< 65 66 %.o:$(IMGUI_DIR)/%.cpp 67 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< 68 69 %.o:$(IMGUI_DIR)/backends/%.cpp 70 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< 71 72 all: $(EXE) 73 @echo Build complete for $(EXE) 74 75 $(WEB_DIR): 76 mkdir $@ 77 78 serve: all 79 python3 -m http.server -d $(WEB_DIR) 80 81 $(EXE): $(OBJS) $(WEB_DIR) 82 $(CXX) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) 83 84 clean: 85 rm -f $(EXE) $(OBJS) $(WEB_DIR)/*.js $(WEB_DIR)/*.wasm $(WEB_DIR)/*.wasm.pre