2
0

detect.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. # Use -Os to prioritize optimizing for reduced file size. This is
  31. # particularly valuable for the web platform because it directly
  32. # decreases download time.
  33. # -Os reduces file size by around 5 MiB over -O3. -Oz only saves about
  34. # 100 KiB over -Os, which does not justify the negative impact on
  35. # run-time performance.
  36. env.Append(CCFLAGS=['-Os'])
  37. env.Append(LINKFLAGS=['-Os'])
  38. elif (env["target"] == "release_debug"):
  39. env.Append(CCFLAGS=['-O2', '-DDEBUG_ENABLED'])
  40. env.Append(LINKFLAGS=['-O2', '-s', 'ASSERTIONS=1'])
  41. # retain function names at the cost of file size, for backtraces and profiling
  42. env.Append(LINKFLAGS=['--profiling-funcs'])
  43. elif (env["target"] == "debug"):
  44. env.Append(CCFLAGS=['-O1', '-D_DEBUG', '-g', '-DDEBUG_ENABLED'])
  45. env.Append(LINKFLAGS=['-O1', '-g'])
  46. ## Compiler configuration
  47. env['ENV'] = os.environ
  48. if ("EMSCRIPTEN_ROOT" in os.environ):
  49. env.PrependENVPath('PATH', os.environ['EMSCRIPTEN_ROOT'])
  50. elif ("EMSCRIPTEN" in os.environ):
  51. env.PrependENVPath('PATH', os.environ['EMSCRIPTEN'])
  52. env['CC'] = 'emcc'
  53. env['CXX'] = 'em++'
  54. env['LINK'] = 'emcc'
  55. env['RANLIB'] = 'emranlib'
  56. # Emscripten's ar has issues with duplicate file names, so use cc
  57. env['AR'] = 'emcc'
  58. env['ARFLAGS'] = '-o'
  59. if (os.name == 'nt'):
  60. # use TempFileMunge on Windows since some commands get too long for
  61. # cmd.exe even with spawn_fix
  62. # need to escape backslashes for this
  63. env['ESCAPED_SOURCES'] = escape_sources_backslashes
  64. env['ESCAPED_TARGET'] = escape_target_backslashes
  65. env['ARCOM'] = '${TEMPFILE("%s")}' % env['ARCOM'].replace('$SOURCES', '$ESCAPED_SOURCES').replace('$TARGET', '$ESCAPED_TARGET')
  66. env['OBJSUFFIX'] = '.bc'
  67. env['LIBSUFFIX'] = '.bc'
  68. ## Compile flags
  69. env.Append(CPPPATH=['#platform/javascript'])
  70. env.Append(CPPFLAGS=['-DJAVASCRIPT_ENABLED', '-DUNIX_ENABLED', '-DPTHREAD_NO_RENAME', '-DTYPED_METHOD_BIND', '-DNO_THREADS'])
  71. env.Append(CPPFLAGS=['-DGLES3_ENABLED'])
  72. # These flags help keep the file size down
  73. env.Append(CPPFLAGS=["-fno-exceptions", '-DNO_SAFE_CAST', '-fno-rtti'])
  74. if env['javascript_eval']:
  75. env.Append(CPPFLAGS=['-DJAVASCRIPT_EVAL_ENABLED'])
  76. ## Link flags
  77. env.Append(LINKFLAGS=['-s', 'BINARYEN=1'])
  78. env.Append(LINKFLAGS=['-s', 'ALLOW_MEMORY_GROWTH=1'])
  79. env.Append(LINKFLAGS=['-s', 'USE_WEBGL2=1'])
  80. env.Append(LINKFLAGS=['-s', 'EXTRA_EXPORTED_RUNTIME_METHODS="[\'FS\']"'])
  81. env.Append(LINKFLAGS=['-s', 'INVOKE_RUN=0'])
  82. env.Append(LINKFLAGS=['-s', 'NO_EXIT_RUNTIME=1'])
  83. # TODO: Move that to opus module's config
  84. if 'module_opus_enabled' in env and env['module_opus_enabled']:
  85. env.opus_fixed_point = "yes"