Makefile.emscripten 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # IMPORTANT: SDL3 IS IN DEVELOPMENT, AS OF 2023-05-30, EMSCRIPTEN DOESN'T SUPPORT SDL3 YET.
  2. # WE ARE LEAVING THIS MAKEFILE AROUND FOR THE DAY IT WILL SUPPORT IT.
  3. #
  4. # Makefile to use with SDL+emscripten
  5. # See https://emscripten.org/docs/getting_started/downloads.html
  6. # for installation instructions.
  7. #
  8. # This Makefile assumes you have loaded emscripten's environment.
  9. # (On Windows, you may need to execute emsdk_env.bat or encmdprompt.bat ahead)
  10. #
  11. # Running `make -f Makefile.emscripten` will produce three files:
  12. # - web/index.html
  13. # - web/index.js
  14. # - web/index.wasm
  15. #
  16. # All three are needed to run the demo.
  17. CC = emcc
  18. CXX = em++
  19. WEB_DIR = web
  20. EXE = $(WEB_DIR)/index.html
  21. IMGUI_DIR = ../..
  22. SOURCES = main.cpp
  23. 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
  24. SOURCES += $(IMGUI_DIR)/backends/imgui_impl_sdl3.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp
  25. OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
  26. UNAME_S := $(shell uname -s)
  27. CPPFLAGS =
  28. LDFLAGS =
  29. EMS =
  30. ##---------------------------------------------------------------------
  31. ## EMSCRIPTEN OPTIONS
  32. ##---------------------------------------------------------------------
  33. # ("EMS" options gets added to both CPPFLAGS and LDFLAGS, whereas some options are for linker only)
  34. EMS += -s USE_SDL=2
  35. EMS += -s DISABLE_EXCEPTION_CATCHING=1
  36. LDFLAGS += -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1
  37. # Uncomment next line to fix possible rendering bugs with Emscripten version older then 1.39.0 (https://github.com/ocornut/imgui/issues/2877)
  38. #EMS += -s BINARYEN_TRAP_MODE=clamp
  39. #EMS += -s SAFE_HEAP=1 ## Adds overhead
  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. LDFLAGS += -s NO_FILESYSTEM=1
  47. CPPFLAGS += -DIMGUI_DISABLE_FILE_FUNCTIONS
  48. endif
  49. ifeq ($(USE_FILE_SYSTEM), 1)
  50. LDFLAGS += --no-heap-copy --preload-file ../../misc/fonts@/fonts
  51. endif
  52. ##---------------------------------------------------------------------
  53. ## FINAL BUILD FLAGS
  54. ##---------------------------------------------------------------------
  55. CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
  56. #CPPFLAGS += -g
  57. CPPFLAGS += -Wall -Wformat -Os $(EMS)
  58. LDFLAGS += --shell-file ../libs/emscripten/shell_minimal.html
  59. LDFLAGS += $(EMS)
  60. ##---------------------------------------------------------------------
  61. ## BUILD RULES
  62. ##---------------------------------------------------------------------
  63. %.o:%.cpp
  64. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
  65. %.o:$(IMGUI_DIR)/%.cpp
  66. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
  67. %.o:$(IMGUI_DIR)/backends/%.cpp
  68. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
  69. all: $(EXE)
  70. @echo Build complete for $(EXE)
  71. $(WEB_DIR):
  72. mkdir $@
  73. serve: all
  74. python3 -m http.server -d $(WEB_DIR)
  75. $(EXE): $(OBJS) $(WEB_DIR)
  76. $(CXX) -o $@ $(OBJS) $(LDFLAGS)
  77. clean:
  78. rm -rf $(OBJS) $(WEB_DIR)