linux.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import common_compiler_flags
  2. from SCons.Tool import clang, clangxx
  3. from SCons.Variables import BoolVariable
  4. def options(opts):
  5. opts.Add(BoolVariable("use_llvm", "Use the LLVM compiler - only effective when targeting Linux", False))
  6. def exists(env):
  7. return True
  8. def generate(env):
  9. if env["use_llvm"]:
  10. clang.generate(env)
  11. clangxx.generate(env)
  12. elif env.use_hot_reload:
  13. # Required for extensions to truly unload.
  14. env.Append(CXXFLAGS=["-fno-gnu-unique"])
  15. env.Append(CCFLAGS=["-fPIC", "-Wwrite-strings"])
  16. env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"])
  17. if env["arch"] == "x86_64":
  18. # -m64 and -m32 are x86-specific already, but it doesn't hurt to
  19. # be clear and also specify -march=x86-64. Similar with 32-bit.
  20. env.Append(CCFLAGS=["-m64", "-march=x86-64"])
  21. env.Append(LINKFLAGS=["-m64", "-march=x86-64"])
  22. elif env["arch"] == "x86_32":
  23. env.Append(CCFLAGS=["-m32", "-march=i686"])
  24. env.Append(LINKFLAGS=["-m32", "-march=i686"])
  25. elif env["arch"] == "arm64":
  26. env.Append(CCFLAGS=["-march=armv8-a"])
  27. env.Append(LINKFLAGS=["-march=armv8-a"])
  28. elif env["arch"] == "rv64":
  29. env.Append(CCFLAGS=["-march=rv64gc"])
  30. env.Append(LINKFLAGS=["-march=rv64gc"])
  31. env.Append(CPPDEFINES=["LINUX_ENABLED", "UNIX_ENABLED"])
  32. # Refer to https://github.com/godotengine/godot/blob/master/platform/linuxbsd/detect.py
  33. if env["lto"] == "auto":
  34. env["lto"] = "full"
  35. common_compiler_flags.generate(env)