detect.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 or "EMSCRIPTEN" in os.environ)
  10. def get_opts():
  11. from SCons.Variables import BoolVariable
  12. return [
  13. BoolVariable('javascript_eval', 'Enable JavaScript eval interface', True),
  14. ]
  15. def get_flags():
  16. return [
  17. ('tools', False),
  18. ('module_theora_enabled', False),
  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. if ("EMSCRIPTEN_ROOT" in os.environ):
  43. env.PrependENVPath('PATH', os.environ['EMSCRIPTEN_ROOT'])
  44. elif ("EMSCRIPTEN" in os.environ):
  45. env.PrependENVPath('PATH', os.environ['EMSCRIPTEN'])
  46. env['CC'] = 'emcc'
  47. env['CXX'] = 'em++'
  48. env['LINK'] = 'emcc'
  49. env['RANLIB'] = 'emranlib'
  50. # Emscripten's ar has issues with duplicate file names, so use cc
  51. env['AR'] = 'emcc'
  52. env['ARFLAGS'] = '-o'
  53. if (os.name == 'nt'):
  54. # use TempFileMunge on Windows since some commands get too long for
  55. # cmd.exe even with spawn_fix
  56. # need to escape backslashes for this
  57. env['ESCAPED_SOURCES'] = escape_sources_backslashes
  58. env['ESCAPED_TARGET'] = escape_target_backslashes
  59. env['ARCOM'] = '${TEMPFILE("%s")}' % env['ARCOM'].replace('$SOURCES', '$ESCAPED_SOURCES').replace('$TARGET', '$ESCAPED_TARGET')
  60. env['OBJSUFFIX'] = '.bc'
  61. env['LIBSUFFIX'] = '.bc'
  62. ## Compile flags
  63. env.Append(CPPPATH=['#platform/javascript'])
  64. env.Append(CPPFLAGS=['-DJAVASCRIPT_ENABLED', '-DUNIX_ENABLED', '-DPTHREAD_NO_RENAME', '-DTYPED_METHOD_BIND', '-DNO_THREADS'])
  65. env.Append(CPPFLAGS=['-DGLES3_ENABLED'])
  66. # These flags help keep the file size down
  67. env.Append(CPPFLAGS=["-fno-exceptions", '-DNO_SAFE_CAST', '-fno-rtti'])
  68. if env['javascript_eval']:
  69. env.Append(CPPFLAGS=['-DJAVASCRIPT_EVAL_ENABLED'])
  70. ## Link flags
  71. env.Append(LINKFLAGS=['-s', 'EXTRA_EXPORTED_RUNTIME_METHODS="[\'FS\']"'])
  72. env.Append(LINKFLAGS=['-s', 'USE_WEBGL2=1'])
  73. env.Append(LINKFLAGS=['-s', 'BINARYEN=1'])
  74. # In contrast to asm.js, enabling memory growth on WebAssembly has no
  75. # major performance impact, and causes only a negligible increase in
  76. # memory size.
  77. env.Append(LINKFLAGS=['-s', 'ALLOW_MEMORY_GROWTH=1'])
  78. # TODO: Move that to opus module's config
  79. if 'module_opus_enabled' in env and env['module_opus_enabled']:
  80. env.opus_fixed_point = "yes"