detect.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_mpc_enabled', 'no'),
  20. ('module_theora_enabled', 'no'),
  21. ]
  22. def create(env):
  23. # remove Windows' .exe suffix
  24. return env.Clone(tools=['textfile', 'zip'], PROGSUFFIX='')
  25. def escape_sources_backslashes(target, source, env, for_signature):
  26. return [path.replace('\\','\\\\') for path in env.GetBuildPath(source)]
  27. def escape_target_backslashes(target, source, env, for_signature):
  28. return env.GetBuildPath(target[0]).replace('\\','\\\\')
  29. def configure(env):
  30. env['ENV'] = os.environ
  31. env.Append(CPPPATH=['#platform/javascript'])
  32. env.PrependENVPath('PATH', os.environ['EMSCRIPTEN_ROOT'])
  33. env['CC'] = 'emcc'
  34. env['CXX'] = 'em++'
  35. env['LINK'] = 'emcc'
  36. env['RANLIB'] = 'emranlib'
  37. # Emscripten's ar has issues with duplicate file names, so use cc
  38. env['AR'] = 'emcc'
  39. env['ARFLAGS'] = '-o'
  40. if (os.name == 'nt'):
  41. # use TempFileMunge on Windows since some commands get too long for
  42. # cmd.exe even with spawn_fix
  43. # need to escape backslashes for this
  44. env['ESCAPED_SOURCES'] = escape_sources_backslashes
  45. env['ESCAPED_TARGET'] = escape_target_backslashes
  46. env['ARCOM'] = '${TEMPFILE("%s")}' % env['ARCOM'].replace('$SOURCES', '$ESCAPED_SOURCES').replace('$TARGET', '$ESCAPED_TARGET')
  47. env['OBJSUFFIX'] = '.bc'
  48. env['LIBSUFFIX'] = '.bc'
  49. if (env["target"] == "release"):
  50. env.Append(CCFLAGS=['-O2'])
  51. elif (env["target"] == "release_debug"):
  52. env.Append(CCFLAGS=['-O2', '-DDEBUG_ENABLED'])
  53. elif (env["target"] == "debug"):
  54. #env.Append(CCFLAGS=['-D_DEBUG', '-Wall', '-O2', '-DDEBUG_ENABLED'])
  55. env.Append(CCFLAGS=['-D_DEBUG', '-Wall', '-g3', '-DDEBUG_ENABLED'])
  56. env.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC'])
  57. env.Append(LINKFLAGS=['--profiling-funcs'])
  58. # TODO: Move that to opus module's config
  59. if("module_opus_enabled" in env and env["module_opus_enabled"] != "no"):
  60. env.opus_fixed_point = "yes"
  61. # These flags help keep the file size down
  62. env.Append(CPPFLAGS=["-fno-exceptions", '-DNO_SAFE_CAST', '-fno-rtti'])
  63. env.Append(CPPFLAGS=['-DJAVASCRIPT_ENABLED', '-DUNIX_ENABLED', '-DPTHREAD_NO_RENAME', '-DNO_FCNTL', '-DMPC_FIXED_POINT', '-DTYPED_METHOD_BIND', '-DNO_THREADS'])
  64. env.Append(CPPFLAGS=['-DGLES3_ENABLED'])
  65. if env['wasm'] == 'yes':
  66. env.Append(LINKFLAGS=['-s', 'BINARYEN=1'])
  67. # Maximum memory size is baked into the WebAssembly binary during
  68. # compilation, so we need to enable memory growth to allow setting
  69. # TOTAL_MEMORY at runtime. The value set at runtime must be higher than
  70. # what is set during compilation, check TOTAL_MEMORY in Emscripten's
  71. # src/settings.js for the default.
  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. env.Append(LINKFLAGS=['-O2'])
  80. env.Append(LINKFLAGS=['-s', 'USE_WEBGL2=1'])
  81. # env.Append(LINKFLAGS=['-g4'])
  82. import methods