Makefile 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. # - example_emscripten_opengl3.html
  11. # - example_emscripten_opengl3.js
  12. # - example_emscripten_opengl3.wasm
  13. #
  14. # All three are needed to run the demo.
  15. CC = emcc
  16. CXX = em++
  17. EXE = example_emscripten_opengl3.html
  18. IMGUI_DIR = ../..
  19. SOURCES = main.cpp
  20. SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_widgets.cpp
  21. SOURCES += $(IMGUI_DIR)/backends/imgui_impl_sdl.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp
  22. OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES))))
  23. UNAME_S := $(shell uname -s)
  24. ##---------------------------------------------------------------------
  25. ## EMSCRIPTEN OPTIONS
  26. ##---------------------------------------------------------------------
  27. EMS += -s USE_SDL=2 -s WASM=1
  28. EMS += -s ALLOW_MEMORY_GROWTH=1
  29. EMS += -s DISABLE_EXCEPTION_CATCHING=1 -s NO_EXIT_RUNTIME=0
  30. EMS += -s ASSERTIONS=1
  31. # Uncomment next line to fix possible rendering bugs with Emscripten version older then 1.39.0 (https://github.com/ocornut/imgui/issues/2877)
  32. #EMS += -s BINARYEN_TRAP_MODE=clamp
  33. #EMS += -s SAFE_HEAP=1 ## Adds overhead
  34. # Emscripten allows preloading a file or folder to be accessible at runtime.
  35. # The Makefile for this example project suggests embedding the misc/fonts/ folder into our application, it will then be accessible as "/fonts"
  36. # See documentation for more details: https://emscripten.org/docs/porting/files/packaging_files.html
  37. # (Default value is 0. Set to 1 to enable file-system and include the misc/fonts/ folder as part of the build.)
  38. USE_FILE_SYSTEM ?= 0
  39. ifeq ($(USE_FILE_SYSTEM), 0)
  40. EMS += -s NO_FILESYSTEM=1 -DIMGUI_DISABLE_FILE_FUNCTIONS
  41. endif
  42. ifeq ($(USE_FILE_SYSTEM), 1)
  43. LDFLAGS += --no-heap-copy --preload-file ../../misc/fonts@/fonts
  44. endif
  45. ##---------------------------------------------------------------------
  46. ## FINAL BUILD FLAGS
  47. ##---------------------------------------------------------------------
  48. CPPFLAGS = -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
  49. #CPPFLAGS += -g
  50. CPPFLAGS += -Wall -Wformat -Os
  51. CPPFLAGS += $(EMS)
  52. LIBS += $(EMS)
  53. LDFLAGS += --shell-file shell_minimal.html
  54. ##---------------------------------------------------------------------
  55. ## BUILD RULES
  56. ##---------------------------------------------------------------------
  57. %.o:%.cpp
  58. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
  59. %.o:$(IMGUI_DIR)/%.cpp
  60. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
  61. %.o:$(IMGUI_DIR)/backends/%.cpp
  62. $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
  63. %.o:../libs/gl3w/GL/%.c
  64. $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
  65. all: $(EXE)
  66. @echo Build complete for $(EXE)
  67. $(EXE): $(OBJS)
  68. $(CXX) -o $@ $^ $(LIBS) $(LDFLAGS)
  69. clean:
  70. rm -f $(EXE) $(OBJS) *.js *.wasm *.wasm.pre