linux.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. opts.Add(BoolVariable("use_static_cpp", "Link libgcc and libstdc++ statically for better portability", True))
  7. def exists(env):
  8. return True
  9. def generate(env):
  10. if env["use_llvm"]:
  11. clang.generate(env)
  12. clangxx.generate(env)
  13. elif env.use_hot_reload:
  14. # Required for extensions to truly unload.
  15. env.Append(CXXFLAGS=["-fno-gnu-unique"])
  16. env.Append(CCFLAGS=["-fPIC", "-Wwrite-strings"])
  17. env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"])
  18. if env["arch"] == "x86_64":
  19. # -m64 and -m32 are x86-specific already, but it doesn't hurt to
  20. # be clear and also specify -march=x86-64. Similar with 32-bit.
  21. env.Append(CCFLAGS=["-m64", "-march=x86-64"])
  22. env.Append(LINKFLAGS=["-m64", "-march=x86-64"])
  23. elif env["arch"] == "x86_32":
  24. env.Append(CCFLAGS=["-m32", "-march=i686"])
  25. env.Append(LINKFLAGS=["-m32", "-march=i686"])
  26. elif env["arch"] == "arm64":
  27. env.Append(CCFLAGS=["-march=armv8-a"])
  28. env.Append(LINKFLAGS=["-march=armv8-a"])
  29. elif env["arch"] == "rv64":
  30. env.Append(CCFLAGS=["-march=rv64gc"])
  31. env.Append(LINKFLAGS=["-march=rv64gc"])
  32. # Link statically for portability
  33. if env["use_static_cpp"]:
  34. env.Append(LINKFLAGS=["-static-libgcc", "-static-libstdc++"])
  35. env.Append(CPPDEFINES=["LINUX_ENABLED", "UNIX_ENABLED"])
  36. # Refer to https://github.com/godotengine/godot/blob/master/platform/linuxbsd/detect.py
  37. if env["lto"] == "auto":
  38. env["lto"] = "full"
  39. common_compiler_flags.generate(env)