config-emscripten.mk 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. CC = emcc -c
  2. CXX = em++ -c
  3. LD = em++
  4. AR = emar
  5. LINK.cc = em++ $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH)
  6. EMSCRIPTEN_TARGET?=default
  7. EMSCRIPTEN_THREADS?=0
  8. EMSCRIPTEN_PORTS?=0
  9. ifneq ($(STDCXX),)
  10. CXXFLAGS_STDCXX = -std=$(STDCXX)
  11. else
  12. ifeq ($(shell printf '\n' > bin/empty.cpp ; if $(CXX) -std=c++17 -c bin/empty.cpp -o bin/empty.out > /dev/null 2>&1 ; then echo 'c++17' ; fi ), c++17)
  13. CXXFLAGS_STDCXX = -std=c++17
  14. endif
  15. endif
  16. CFLAGS_STDC = -std=c99
  17. CXXFLAGS += $(CXXFLAGS_STDCXX)
  18. CFLAGS += $(CFLAGS_STDC)
  19. CPPFLAGS +=
  20. CXXFLAGS += -fPIC
  21. CFLAGS += -fPIC
  22. LDFLAGS +=
  23. LDLIBS +=
  24. ARFLAGS := rcs
  25. ifeq ($(EMSCRIPTEN_THREADS),1)
  26. CXXFLAGS += -pthread
  27. CFLAGS += -pthread
  28. LDFLAGS += -pthread
  29. endif
  30. ifeq ($(EMSCRIPTEN_PORTS),1)
  31. CXXFLAGS += -s USE_ZLIB=1 -sUSE_MPG123=1 -sUSE_OGG=1 -sUSE_VORBIS=1 -DMPT_WITH_ZLIB -DMPT_WITH_MPG123 -DMPT_WITH_VORBIS -DMPT_WITH_VORBISFI
  32. CFLAGS += -s USE_ZLIB=1 -sUSE_MPG123=1 -sUSE_OGG=1 -sUSE_VORBIS=1 -DMPT_WITH_ZLIB -DMPT_WITH_MPG123 -DMPT_WITH_VORBIS -DMPT_WITH_VORBISFI
  33. LDFLAGS += -s USE_ZLIB=1 -sUSE_MPG123=1 -sUSE_OGG=1 -sUSE_VORBIS=1
  34. NO_MINIZ=1
  35. NO_MINIMP3=1
  36. NO_STBVORBIS=1
  37. endif
  38. CXXFLAGS += -Oz
  39. CFLAGS += -Oz
  40. LDFLAGS += -Oz
  41. # Enable LTO as recommended by Emscripten
  42. #CXXFLAGS += -flto=thin
  43. #CFLAGS += -flto=thin
  44. #LDFLAGS += -flto=thin -Wl,--thinlto-jobs=all
  45. # As per recommendation in <https://github.com/emscripten-core/emscripten/issues/15638#issuecomment-982772770>,
  46. # thinLTO is not as well tested as full LTO. Stick to full LTO for now.
  47. CXXFLAGS += -flto
  48. CFLAGS += -flto
  49. LDFLAGS += -flto
  50. ifeq ($(EMSCRIPTEN_TARGET),default)
  51. # emits whatever is emscripten's default, currently (1.38.8) this is the same as "wasm" below.
  52. CPPFLAGS += -DMPT_BUILD_WASM
  53. CXXFLAGS +=
  54. CFLAGS +=
  55. LDFLAGS +=
  56. LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
  57. else ifeq ($(EMSCRIPTEN_TARGET),all)
  58. # emits native wasm AND javascript with full wasm optimizations.
  59. CPPFLAGS += -DMPT_BUILD_WASM
  60. CXXFLAGS +=
  61. CFLAGS +=
  62. LDFLAGS += -s WASM=2 -s LEGACY_VM_SUPPORT=1 -Wno-transpile
  63. LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
  64. else ifeq ($(EMSCRIPTEN_TARGET),audioworkletprocessor)
  65. # emits an es6 module in a single file suitable for use in an AudioWorkletProcessor
  66. CPPFLAGS += -DMPT_BUILD_WASM -DMPT_BUILD_AUDIOWORKLETPROCESSOR
  67. CXXFLAGS +=
  68. CFLAGS +=
  69. LDFLAGS += -s WASM=1 -s WASM_ASYNC_COMPILATION=0 -s MODULARIZE=1 -s EXPORT_ES6=1 -s SINGLE_FILE=1
  70. LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
  71. else ifeq ($(EMSCRIPTEN_TARGET),wasm)
  72. # emits native wasm.
  73. CPPFLAGS += -DMPT_BUILD_WASM
  74. CXXFLAGS +=
  75. CFLAGS +=
  76. LDFLAGS += -s WASM=1
  77. LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
  78. else ifeq ($(EMSCRIPTEN_TARGET),js)
  79. # emits only plain javascript with plain javascript focused optimizations.
  80. CPPFLAGS += -DMPT_BUILD_ASMJS
  81. CXXFLAGS +=
  82. CFLAGS +=
  83. LDFLAGS += -s WASM=0 -s LEGACY_VM_SUPPORT=1 -Wno-transpile
  84. LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
  85. endif
  86. CXXFLAGS += -s DISABLE_EXCEPTION_CATCHING=0
  87. CFLAGS += -s DISABLE_EXCEPTION_CATCHING=0 -fno-strict-aliasing
  88. LDFLAGS += -s DISABLE_EXCEPTION_CATCHING=0 -s ERROR_ON_UNDEFINED_SYMBOLS=1 -s ERROR_ON_MISSING_LIBRARIES=1 -s EXPORT_NAME="'libopenmpt'"
  89. include build/make/warnings-clang.mk
  90. REQUIRES_RUNPREFIX=1
  91. EXESUFFIX=.js
  92. SOSUFFIX=.js
  93. RUNPREFIX=node
  94. TEST_LDFLAGS= --pre-js build/make/test-pre.js -lnodefs.js
  95. ifeq ($(EMSCRIPTEN_THREADS),1)
  96. RUNPREFIX+=--experimental-wasm-threads --experimental-wasm-bulk-memory
  97. endif
  98. DYNLINK=0
  99. SHARED_LIB=1
  100. STATIC_LIB=0
  101. EXAMPLES=1
  102. OPENMPT123=0
  103. SHARED_SONAME=0
  104. NO_SHARED_LINKER_FLAG=1
  105. # Disable the generic compiler optimization flags as emscripten is sufficiently different.
  106. # Optimization flags are hard-coded for emscripten in this file.
  107. DEBUG=0
  108. OPTIMIZE=0
  109. OPTIMIZE_SIZE=0
  110. IS_CROSS=1
  111. ifeq ($(ALLOW_LGPL),1)
  112. LOCAL_ZLIB=1
  113. LOCAL_MPG123=1
  114. LOCAL_OGG=1
  115. LOCAL_VORBIS=1
  116. else
  117. NO_ZLIB=1
  118. NO_MPG123=1
  119. NO_OGG=1
  120. NO_VORBIS=1
  121. NO_VORBISFILE=1
  122. endif
  123. NO_LTDL=1
  124. NO_DL=1
  125. NO_PORTAUDIO=1
  126. NO_PORTAUDIOCPP=1
  127. NO_PULSEAUDIO=1
  128. NO_SDL=1
  129. NO_SDL2=1
  130. NO_FLAC=1
  131. NO_SNDFILE=1