Makefile 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #
  2. # Copyright (C) 2014-2017 Eitan Isaacson
  3. # Copyright (C) 2016-2017 Alberto Pettarin
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, see: <http://www.gnu.org/licenses/>.
  17. #
  18. # NOTE: variables specific to espeak-ng + emscripten starts with "EM_"
  19. # NOTE: set to 1 to debug or to speed emscripten up while developing.
  20. # If the EM_DEBUG environment variable is set,
  21. # the value specified here will be ignored.
  22. EM_DEBUG ?= 0
  23. ifneq ($(EM_DEBUG), 1)
  24. CXXFLAGS+=-O3
  25. endif
  26. ###############################################################################
  27. # WARNING: modify code below this line at your own risk!
  28. ###############################################################################
  29. # NOTE: sanity check
  30. ifndef EMSCRIPTEN
  31. $(error EMSCRIPTEN var not set. You must use emmake to run this Makefile!)
  32. endif
  33. # NOTE: in the emscripten virtual FS,
  34. # this is the location of the eSpeak-ng data files,
  35. # if we configure with "./configure --prefix=/usr"
  36. EM_VIRTUAL_PATH_ESPEAKNG_DATA=/usr/share/espeak-ng-data
  37. # NOTE: emmake will replace EMSCRIPTEN with the actual root directory
  38. # of the emscripten tools inside the emscripten SDK directory
  39. EM_WEBIDL_BINDER=python $(EMSCRIPTEN)/tools/webidl_binder.py
  40. EM_FILE_PACKAGER=python $(EMSCRIPTEN)/tools/file_packager.py
  41. # NOTE: libespeak-ng.so (Linux) or libespeak-ng.dylib (macOS) compiled to LLVM IR code
  42. EM_LIBESPEAKNG_SO=$(wildcard ../src/.libs/libespeak-ng.so)
  43. EM_LIBESPEAKNG_DYLIB=$(wildcard ../src/.libs/libespeak-ng.dylib)
  44. ifneq ($(EM_LIBESPEAKNG_DYLIB),)
  45. EM_LIBESPEAKNG=$(EM_LIBESPEAKNG_DYLIB)
  46. else ifneq ($(EM_LIBESPEAKNG_SO),)
  47. EM_LIBESPEAKNG=$(EM_LIBESPEAKNG_SO)
  48. endif
  49. # NOTE: glue code files
  50. EM_GLUE_PREFIX=glue
  51. EM_GLUE_IDL=espeakng_glue.idl
  52. EM_GLUE_OBJ=espeakng_glue.o
  53. EM_GLUE_CPP=espeakng_glue.cpp
  54. EM_GLUE_AUTOGEN_CPP=glue.cpp
  55. EM_GLUE_AUTOGEN_JS=glue.js
  56. # NOTE: preload espeak-ng-data directory...
  57. EM_DATA_DIR=../espeak-ng-data
  58. # NOTE: ... but exclude these subdirectories/files
  59. EM_EXCLUDE_DATA=../espeak-ng-data/mbrola_ph ../espeak-ng-data/phondata-manifest
  60. # NOTE: pre/post JS files
  61. EM_PRE_JS=pre.js
  62. EM_POST_JS=post.js
  63. # NOTE: output files
  64. EM_ESPEAKNG_DATA_PACKAGE_JS=espeakng_data_package.js
  65. EM_WORKER_DATA=js/espeakng.worker.data
  66. EM_WORKER_JS=js/espeakng.worker.js
  67. EM_PTHREAD_MAIN_JS=js/pthread-main.js
  68. # NOTE: intermediate objects
  69. EM_ALL_PRE_JS=$(EM_PRE_JS) $(EM_ESPEAKNG_DATA_PACKAGE_JS)
  70. EM_ALL_POST_JS=$(EM_GLUE_AUTOGEN_JS) $(EM_POST_JS)
  71. # NOTE: compile without async, i.e. with synchronous output
  72. #
  73. # ./emconfigure ./configure --prefix=/usr --without-async
  74. # ./emmake make
  75. CXXFLAGS+=-DESPEAK_DATA_PATH=\"$(EM_VIRTUAL_PATH_ESPEAKNG_DATA)\"
  76. CXXFLAGS+=-I ./ -I ../ -I ../src/include/espeak-ng
  77. # NOTE: so far, pthread is not supported in any browser
  78. # except Firefox Nightly.
  79. # If we want to enable pthread in the future,
  80. # we must append "-s USE_PTHREADS=1" to CXXFLAGS
  81. # and pass that to emconfigure and emmake.
  82. # If enabled, js/pthread-main.js will be created as well.
  83. #
  84. #CXXFLAGS+=-s USE_PTHREADS=1
  85. # NOTE: extra flags for emscripten
  86. EM_CXXFLAGS=-s RESERVED_FUNCTION_POINTERS=2 --memory-init-file 0
  87. ###############################################################################
  88. # NOTE: actual targets
  89. ###############################################################################
  90. all: $(EM_WORKER_JS)
  91. $(EM_WORKER_DATA):
  92. $(EM_FILE_PACKAGER) $@ \
  93. --js-output=$(EM_ESPEAKNG_DATA_PACKAGE_JS) \
  94. --preload $(EM_DATA_DIR)@$(EM_VIRTUAL_PATH_ESPEAKNG_DATA) \
  95. $(patsubst %,--exclude %,$(EM_EXCLUDE_DATA))
  96. $(EM_ESPEAKNG_DATA_PACKAGE_JS): $(EM_WORKER_DATA)
  97. $(EM_GLUE_AUTOGEN_CPP): $(EM_GLUE_IDL)
  98. $(EM_WEBIDL_BINDER) $(EM_GLUE_IDL) $(EM_GLUE_PREFIX)
  99. $(EM_GLUE_AUTOGEN_JS): $(EM_GLUE_AUTOGEN_CPP)
  100. $(EM_GLUE_OBJ): $(EM_GLUE_CPP)
  101. $(EM_WORKER_JS): $(EM_GLUE_AUTOGEN_CPP) $(EM_GLUE_OBJ) $(EM_ALL_PRE_JS) $(EM_ALL_POST_JS)
  102. ifeq ($(EM_LIBESPEAKNG),)
  103. $(error Unable to find ../src/.libs/libespeak-ng .so or .dylib. Aborting!)
  104. endif
  105. $(CXX) $(CXXFLAGS) \
  106. $(EM_CXXFLAGS) \
  107. $(EM_GLUE_OBJ) \
  108. $(EM_LIBESPEAKNG) \
  109. $(patsubst %,--pre-js %,$(EM_ALL_PRE_JS)) \
  110. $(patsubst %,--post-js %,$(EM_ALL_POST_JS)) \
  111. -o $@
  112. clean-intermediate:
  113. rm -f *.o *.out *.pkl $(EM_GLUE_AUTOGEN_CPP) $(EM_GLUE_AUTOGEN_JS) $(EM_ESPEAKNG_DATA_PACKAGE_JS)
  114. clean: clean-intermediate
  115. rm -f $(EM_WORKER_DATA) $(EM_WORKER_JS) $(EM_PTHREAD_MAIN_JS)
  116. help:
  117. echo "Available targets: all clean clean-intermediate help"