Makefile (3033B)
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 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.html 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_sdl.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.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_SDL=2 -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 # Uncomment next line to fix possible rendering bugs with Emscripten version older then 1.39.0 (https://github.com/ocornut/imgui/issues/2877) 37 #EMS += -s BINARYEN_TRAP_MODE=clamp 38 #EMS += -s SAFE_HEAP=1 ## Adds overhead 39 40 # Emscripten allows preloading a file or folder to be accessible at runtime. 41 # The Makefile for this example project suggests embedding the misc/fonts/ folder into our application, it will then be accessible as "/fonts" 42 # See documentation for more details: https://emscripten.org/docs/porting/files/packaging_files.html 43 # (Default value is 0. Set to 1 to enable file-system and include the misc/fonts/ folder as part of the build.) 44 USE_FILE_SYSTEM ?= 0 45 ifeq ($(USE_FILE_SYSTEM), 0) 46 EMS += -s NO_FILESYSTEM=1 -DIMGUI_DISABLE_FILE_FUNCTIONS 47 endif 48 ifeq ($(USE_FILE_SYSTEM), 1) 49 LDFLAGS += --no-heap-copy --preload-file ../../misc/fonts@/fonts 50 endif 51 52 ##--------------------------------------------------------------------- 53 ## FINAL BUILD FLAGS 54 ##--------------------------------------------------------------------- 55 56 CPPFLAGS = -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends 57 #CPPFLAGS += -g 58 CPPFLAGS += -Wall -Wformat -Os 59 CPPFLAGS += $(EMS) 60 LIBS += $(EMS) 61 LDFLAGS += --shell-file shell_minimal.html 62 63 ##--------------------------------------------------------------------- 64 ## BUILD RULES 65 ##--------------------------------------------------------------------- 66 67 %.o:%.cpp 68 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< 69 70 %.o:$(IMGUI_DIR)/%.cpp 71 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< 72 73 %.o:$(IMGUI_DIR)/backends/%.cpp 74 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< 75 76 %.o:../libs/gl3w/GL/%.c 77 $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< 78 79 all: $(EXE) 80 @echo Build complete for $(EXE) 81 82 $(WEB_DIR): 83 mkdir $@ 84 85 serve: all 86 python3 -m http.server -d $(WEB_DIR) 87 88 $(EXE): $(OBJS) $(WEB_DIR) 89 $(CXX) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) 90 91 clean: 92 rm -rf $(OBJS) $(WEB_DIR)