detect.py 3.4 KB

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