detect.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import os
  2. import string
  3. import sys
  4. def is_active():
  5. return True
  6. def get_name():
  7. return "JavaScript"
  8. def can_build():
  9. return ("EMSCRIPTEN_ROOT" in os.environ)
  10. def get_opts():
  11. return [
  12. ['wasm', 'Compile to WebAssembly', 'no'],
  13. ['javascript_eval', 'Enable JavaScript eval interface', 'yes'],
  14. ]
  15. def get_flags():
  16. return [
  17. ('tools', 'no'),
  18. ('module_theora_enabled', 'no'),
  19. ]
  20. def create(env):
  21. # remove Windows' .exe suffix
  22. return env.Clone(tools=['textfile', 'zip'], PROGSUFFIX='')
  23. def escape_sources_backslashes(target, source, env, for_signature):
  24. return [path.replace('\\','\\\\') for path in env.GetBuildPath(source)]
  25. def escape_target_backslashes(target, source, env, for_signature):
  26. return env.GetBuildPath(target[0]).replace('\\','\\\\')
  27. def configure(env):
  28. ## Build type
  29. if (env["target"] == "release"):
  30. env.Append(CCFLAGS=['-O3'])
  31. env.Append(LINKFLAGS=['-O3'])
  32. elif (env["target"] == "release_debug"):
  33. env.Append(CCFLAGS=['-O2', '-DDEBUG_ENABLED'])
  34. env.Append(LINKFLAGS=['-O2', '-s', 'ASSERTIONS=1'])
  35. # retain function names at the cost of file size, for backtraces and profiling
  36. env.Append(LINKFLAGS=['--profiling-funcs'])
  37. elif (env["target"] == "debug"):
  38. env.Append(CCFLAGS=['-O1', '-D_DEBUG', '-g', '-DDEBUG_ENABLED'])
  39. env.Append(LINKFLAGS=['-O1', '-g'])
  40. ## Compiler configuration
  41. env['ENV'] = os.environ
  42. env.PrependENVPath('PATH', os.environ['EMSCRIPTEN_ROOT'])
  43. env['CC'] = 'emcc'
  44. env['CXX'] = 'em++'
  45. env['LINK'] = 'emcc'
  46. env['RANLIB'] = 'emranlib'
  47. # Emscripten's ar has issues with duplicate file names, so use cc
  48. env['AR'] = 'emcc'
  49. env['ARFLAGS'] = '-o'
  50. if (os.name == 'nt'):
  51. # use TempFileMunge on Windows since some commands get too long for
  52. # cmd.exe even with spawn_fix
  53. # need to escape backslashes for this
  54. env['ESCAPED_SOURCES'] = escape_sources_backslashes
  55. env['ESCAPED_TARGET'] = escape_target_backslashes
  56. env['ARCOM'] = '${TEMPFILE("%s")}' % env['ARCOM'].replace('$SOURCES', '$ESCAPED_SOURCES').replace('$TARGET', '$ESCAPED_TARGET')
  57. env['OBJSUFFIX'] = '.bc'
  58. env['LIBSUFFIX'] = '.bc'
  59. ## Compile flags
  60. env.Append(CPPPATH=['#platform/javascript'])
  61. env.Append(CPPFLAGS=['-DJAVASCRIPT_ENABLED', '-DUNIX_ENABLED', '-DPTHREAD_NO_RENAME', '-DTYPED_METHOD_BIND', '-DNO_THREADS'])
  62. env.Append(CPPFLAGS=['-DGLES3_ENABLED'])
  63. # These flags help keep the file size down
  64. env.Append(CPPFLAGS=["-fno-exceptions", '-DNO_SAFE_CAST', '-fno-rtti'])
  65. if env['javascript_eval'] == 'yes':
  66. env.Append(CPPFLAGS=['-DJAVASCRIPT_EVAL_ENABLED'])
  67. ## Link flags
  68. env.Append(LINKFLAGS=['-s', 'USE_WEBGL2=1'])
  69. if (env['wasm'] == 'yes'):
  70. env.Append(LINKFLAGS=['-s', 'BINARYEN=1'])
  71. # In contrast to asm.js, enabling memory growth on WebAssembly has no
  72. # major performance impact, and causes only a negligible increase in
  73. # memory size.
  74. env.Append(LINKFLAGS=['-s', 'ALLOW_MEMORY_GROWTH=1'])
  75. env.extra_suffix = '.webassembly' + env.extra_suffix
  76. else:
  77. env.Append(LINKFLAGS=['-s', 'ASM_JS=1'])
  78. env.Append(LINKFLAGS=['--separate-asm'])
  79. # TODO: Move that to opus module's config
  80. if("module_opus_enabled" in env and env["module_opus_enabled"] != "no"):
  81. env.opus_fixed_point = "yes"