2019-04-13 23:25:06 +08:00
|
|
|
#
|
|
|
|
# Makefile to use with emscripten
|
|
|
|
# See https://emscripten.org/docs/getting_started/downloads.html
|
2020-01-31 00:15:11 +08:00
|
|
|
# for installation instructions.
|
|
|
|
#
|
|
|
|
# This Makefile assumes you have loaded emscripten's environment.
|
|
|
|
# (On Windows, you may need to execute emsdk_env.bat or encmdprompt.bat ahead)
|
2019-04-13 23:25:06 +08:00
|
|
|
#
|
|
|
|
# Running `make` will produce three files:
|
2021-01-12 01:45:53 +08:00
|
|
|
# - web/index.html
|
|
|
|
# - web/index.js
|
|
|
|
# - web/index.wasm
|
2019-04-13 23:25:06 +08:00
|
|
|
#
|
|
|
|
# All three are needed to run the demo.
|
|
|
|
|
|
|
|
CC = emcc
|
|
|
|
CXX = em++
|
2021-01-12 01:25:15 +08:00
|
|
|
WEB_DIR = web
|
2021-01-12 01:45:53 +08:00
|
|
|
EXE = $(WEB_DIR)/index.html
|
2020-10-12 21:41:57 +08:00
|
|
|
IMGUI_DIR = ../..
|
2019-04-13 23:25:06 +08:00
|
|
|
SOURCES = main.cpp
|
2020-10-07 18:04:28 +08:00
|
|
|
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
|
2020-10-12 21:41:57 +08:00
|
|
|
SOURCES += $(IMGUI_DIR)/backends/imgui_impl_sdl.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp
|
2019-04-13 23:25:06 +08:00
|
|
|
OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
|
|
|
|
UNAME_S := $(shell uname -s)
|
2021-08-18 18:00:15 +08:00
|
|
|
CPPFLAGS =
|
|
|
|
LDFLAGS =
|
|
|
|
EMS =
|
2019-04-13 23:25:06 +08:00
|
|
|
|
2020-01-31 00:15:11 +08:00
|
|
|
##---------------------------------------------------------------------
|
|
|
|
## EMSCRIPTEN OPTIONS
|
|
|
|
##---------------------------------------------------------------------
|
|
|
|
|
2021-08-18 18:00:15 +08:00
|
|
|
# ("EMS" options gets added to both CPPFLAGS and LDFLAGS, whereas some options are for linker only)
|
|
|
|
EMS += -s USE_SDL=2
|
|
|
|
EMS += -s DISABLE_EXCEPTION_CATCHING=1
|
|
|
|
LDFLAGS += -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1
|
2020-01-31 00:15:11 +08:00
|
|
|
|
|
|
|
# Uncomment next line to fix possible rendering bugs with Emscripten version older then 1.39.0 (https://github.com/ocornut/imgui/issues/2877)
|
2019-10-31 05:56:16 +08:00
|
|
|
#EMS += -s BINARYEN_TRAP_MODE=clamp
|
2019-04-15 22:36:14 +08:00
|
|
|
#EMS += -s SAFE_HEAP=1 ## Adds overhead
|
2019-04-13 23:25:06 +08:00
|
|
|
|
2020-01-31 00:15:11 +08:00
|
|
|
# Emscripten allows preloading a file or folder to be accessible at runtime.
|
|
|
|
# The Makefile for this example project suggests embedding the misc/fonts/ folder into our application, it will then be accessible as "/fonts"
|
|
|
|
# See documentation for more details: https://emscripten.org/docs/porting/files/packaging_files.html
|
|
|
|
# (Default value is 0. Set to 1 to enable file-system and include the misc/fonts/ folder as part of the build.)
|
|
|
|
USE_FILE_SYSTEM ?= 0
|
|
|
|
ifeq ($(USE_FILE_SYSTEM), 0)
|
2021-08-18 18:00:15 +08:00
|
|
|
LDFLAGS += -s NO_FILESYSTEM=1
|
|
|
|
CPPFLAGS += -DIMGUI_DISABLE_FILE_FUNCTIONS
|
2020-01-31 00:15:11 +08:00
|
|
|
endif
|
|
|
|
ifeq ($(USE_FILE_SYSTEM), 1)
|
|
|
|
LDFLAGS += --no-heap-copy --preload-file ../../misc/fonts@/fonts
|
|
|
|
endif
|
|
|
|
|
|
|
|
##---------------------------------------------------------------------
|
|
|
|
## FINAL BUILD FLAGS
|
|
|
|
##---------------------------------------------------------------------
|
|
|
|
|
2021-08-18 18:00:15 +08:00
|
|
|
CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
|
2019-04-15 22:36:14 +08:00
|
|
|
#CPPFLAGS += -g
|
2021-08-18 18:00:15 +08:00
|
|
|
CPPFLAGS += -Wall -Wformat -Os $(EMS)
|
|
|
|
LDFLAGS += --shell-file shell_minimal.html $(EMS)
|
2019-04-13 23:25:06 +08:00
|
|
|
|
|
|
|
##---------------------------------------------------------------------
|
|
|
|
## BUILD RULES
|
|
|
|
##---------------------------------------------------------------------
|
|
|
|
|
|
|
|
%.o:%.cpp
|
|
|
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
|
|
|
|
|
2020-10-12 21:41:57 +08:00
|
|
|
%.o:$(IMGUI_DIR)/%.cpp
|
2019-04-13 23:25:06 +08:00
|
|
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
|
|
|
|
|
2020-10-12 21:41:57 +08:00
|
|
|
%.o:$(IMGUI_DIR)/backends/%.cpp
|
2019-04-13 23:25:06 +08:00
|
|
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
|
|
|
|
|
|
|
|
all: $(EXE)
|
|
|
|
@echo Build complete for $(EXE)
|
|
|
|
|
2021-01-12 01:25:15 +08:00
|
|
|
$(WEB_DIR):
|
|
|
|
mkdir $@
|
|
|
|
|
|
|
|
serve: all
|
|
|
|
python3 -m http.server -d $(WEB_DIR)
|
|
|
|
|
|
|
|
$(EXE): $(OBJS) $(WEB_DIR)
|
2021-08-18 18:00:15 +08:00
|
|
|
$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
2019-04-13 23:25:06 +08:00
|
|
|
|
|
|
|
clean:
|
2021-01-12 01:45:53 +08:00
|
|
|
rm -rf $(OBJS) $(WEB_DIR)
|