Makefile.emscripten 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #
  2. # Makefile to use with SDL+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 -f Makefile.emscripten` 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. CC = emcc
  16. CXX = em++
  17. WEB_DIR = web
  18. EXE = $(WEB_DIR)/index.html
  19. IMGUI_DIR = ../..
  20. SOURCES = main.cpp
  21. 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
  22. SOURCES += $(IMGUI_DIR)/backends/imgui_impl_sdl2.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp
  23. OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
  24. UNAME_S := $(shell uname -s)
  25. CPPFLAGS =
  26. LDFLAGS =
  27. EMS =
  28. ##---------------------------------------------------------------------
  29. ## EMSCRIPTEN OPTIONS
  30. ##---------------------------------------------------------------------
  31. # ("EMS" options gets added to both CPPFLAGS and LDFLAGS, whereas some options are for linker only)
  32. EMS += -s USE_SDL=2
  33. EMS += -s DISABLE_EXCEPTION_CATCHING=1
  34. LDFLAGS += -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1
  35. # Uncomment next line to fix possible rendering bugs with Emscripten version older then 1.39.0 (https://github.com/ocornut/imgui/issues/2877)
  36. #EMS += -s BINARYEN_TRAP_MODE=clamp
  37. #EMS += -s SAFE_HEAP=1 ## Adds overhead
  38. # Emscripten allows preloading a file or folder to be accessible at runtime.
  39. # The Makefile for this example project suggests embedding the misc/fonts/ folder into our application, it will then be accessible as "/fonts"
  40. # See documentation for more details: https://emscripten.org/docs/porting/files/packaging_files.html
  41. # (Default value is 0. Set to 1 to enable file-system and include the misc/fonts/ folder as part of the build.)
  42. USE_FILE_SYSTEM ?= 0
  43. ifeq ($(USE_FILE_SYSTEM), 0)
  44. LDFLAGS += -s NO_FILESYSTEM=1
  45. CPPFLAGS += -DIMGUI_DISABLE_FILE_FUNCTIONS
  46. endif
  47. ifeq ($(USE_FILE_SYSTEM), 1)
  48. LDFLAGS += --no-heap-copy --preload-file ../../misc/fonts@/fonts
  49. endif
  50. ##---------------------------------------------------------------------
  51. ## FINAL BUILD FLAGS
  52. ##---------------------------------------------------------------------
  53. CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
  54. #CPPFLAGS += -g
  55. CPPFLAGS += -Wall -Wformat -Os $(EMS)
  56. LDFLAGS += --shell-file ../libs/emscripten/shell_minimal.html
  57. LDFLAGS += $(EMS)
  58. ##---------------------------------------------------------------------
  59. ## BUILD RULES
  60. ##---------------------------------------------------------------------
  61. %.o:%.cpp
  62. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
  63. %.o:$(IMGUI_DIR)/%.cpp
  64. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
  65. %.o:$(IMGUI_DIR)/backends/%.cpp
  66. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
  67. all: $(EXE)
  68. @echo Build complete for $(EXE)
  69. $(WEB_DIR):
  70. mkdir $@
  71. serve: all
  72. python3 -m http.server -d $(WEB_DIR)
  73. $(EXE): $(OBJS) $(WEB_DIR)
  74. $(CXX) -o $@ $(OBJS) $(LDFLAGS)
  75. clean:
  76. rm -rf $(OBJS) $(WEB_DIR)