Skip to content

Commit c662ff9

Browse files
Use more explicit architecture compiler options on Linux
Co-authored-by: Joaquim Monteiro <[email protected]>
1 parent 9d84f3d commit c662ff9

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

platform/linuxbsd/detect.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,31 @@ def configure(env: "SConsEnvironment"):
8383
# gdb works fine without it though, so maybe our crash handler could too.
8484
env.Append(LINKFLAGS=["-rdynamic"])
8585

86-
# Cross-compilation
87-
# TODO: Support cross-compilation on architectures other than x86.
88-
host_is_64_bit = sys.maxsize > 2**32
89-
if host_is_64_bit and env["arch"] == "x86_32":
90-
env.Append(CCFLAGS=["-m32"])
91-
env.Append(LINKFLAGS=["-m32"])
92-
elif not host_is_64_bit and env["arch"] == "x86_64":
93-
env.Append(CCFLAGS=["-m64"])
94-
env.Append(LINKFLAGS=["-m64"])
95-
9686
# CPU architecture flags.
97-
if env["arch"] == "rv64":
87+
# TODO: Support cross-compilation on architectures other than x86.
88+
if env["arch"] == "x86_64":
89+
# CFLAGS and CXXFLAGS have a lower priority than CCFLAGS, so don't use CCFLAGS, instead
90+
# use duplicate CFLAGS and CXXFLAGS, allowing the user to override the arch flags if needed.
91+
env.Prepend(CFLAGS=["-m64", "-march=x86-64"])
92+
env.Prepend(CXXFLAGS=["-m64", "-march=x86-64"])
93+
env.Prepend(LINKFLAGS=["-m64", "-march=x86-64"])
94+
elif env["arch"] == "x86_32":
95+
env.Prepend(CFLAGS=["-m32", "-march=i686"])
96+
env.Prepend(CXXFLAGS=["-m32", "-march=i686"])
97+
env.Prepend(LINKFLAGS=["-m32", "-march=i686"])
98+
elif env["arch"] == "arm64":
99+
env.Prepend(CFLAGS=["-march=armv8-a"])
100+
env.Prepend(CXXFLAGS=["-march=armv8-a"])
101+
env.Prepend(LINKFLAGS=["-march=armv8-a"])
102+
elif env["arch"] == "arm32":
103+
env.Prepend(CFLAGS=["-march=armv7-a"])
104+
env.Prepend(CXXFLAGS=["-march=armv7-a"])
105+
env.Prepend(LINKFLAGS=["-march=armv7-a"])
106+
elif env["arch"] == "rv64":
98107
# G = General-purpose extensions, C = Compression extension (very common).
99-
env.Append(CCFLAGS=["-march=rv64gc"])
108+
env.Prepend(CFLAGS=["-march=rv64gc"])
109+
env.Prepend(CXXFLAGS=["-march=rv64gc"])
110+
env.Prepend(LINKFLAGS=["-march=rv64gc"])
100111

101112
## Compiler configuration
102113

0 commit comments

Comments
 (0)