rt/SConstruct

148 lines
3.3 KiB
Python
Raw Normal View History

2022-08-02 02:21:14 -07:00
import os
import sys
llvm_flags = [
2023-09-01 00:30:02 -07:00
"-pthread",
"-Weverything",
"-Werror",
"-Wno-padded",
"-Wno-poison-system-directories",
"-Wno-declaration-after-statement",
"-Wno-disabled-macro-expansion",
"-Wno-bad-function-cast",
"-Wno-gcc-compat",
"-Wno-missing-noreturn",
"-Wno-gnu-zero-variadic-macro-arguments",
2022-09-22 00:47:45 -07:00
"-g3",
2022-08-02 02:21:14 -07:00
"-ffunction-sections",
"-fdata-sections",
]
2023-07-06 23:58:09 -07:00
AddOption(
"--sanitize",
dest="sanitize",
default=False,
action="store_true",
help="enable sanitizers",
)
AddOption(
"--log",
dest="log",
default=False,
action="store_true",
help="enable console log",
)
2023-07-06 23:58:09 -07:00
if GetOption("sanitize"):
llvm_flags.append("-fsanitize=address,undefined")
AddOption(
"--debug-optimization",
dest="debug-optimization",
default=False,
action="store_true",
help="optimize for debug",
)
if GetOption("debug-optimization"):
llvm_flags.extend(["-Og"])
else:
llvm_flags.extend(["-O3", "-flto"])
2023-03-19 22:28:44 -07:00
def ld_emitter(target, source, env):
map_file = os.path.splitext(str(target[0]))[0] + ".map"
return target + [map_file], source
2022-08-02 02:21:14 -07:00
env = Environment(
CPPPATH=[Dir("include").srcnode()],
CCFLAGS=llvm_flags,
2022-08-18 09:22:03 -07:00
CFLAGS=["-std=c17"],
2022-08-02 02:21:14 -07:00
LINKFLAGS=llvm_flags,
2023-03-19 22:28:44 -07:00
PROGEMITTER=ld_emitter,
2023-09-16 13:59:08 -07:00
CCCOMSTR="cc $TARGET",
CXXCOMSTR="c++ $TARGET",
ASCOMSTR="as $TARGET",
ASPPCOMSTR="as $TARGET",
LINKCOMSTR="ld $TARGET",
ARCOMSTR="ar $TARGET",
RANLIBCOMSTR="ranlib $TARGET",
2022-08-02 02:21:14 -07:00
)
if GetOption("log"):
env.Append(CPPDEFINES={"RT_LOG_ENABLE": 1})
2023-03-19 22:28:44 -07:00
if sys.platform == "darwin":
env["LINKCOM"] = (
"$LINK -o ${TARGETS[0]} -Wl,-map,${TARGETS[1]}"
+ " $LINKFLAGS $SOURCES $_LIBDIRFLAGS $_LIBFLAGS"
)
else:
env["LINKCOM"] = (
"$LINK -o ${TARGETS[0]} -Wl,-Map,${TARGETS[1]}"
+ " $LINKFLAGS $SOURCES $_LIBDIRFLAGS"
+ " -Wl,--start-group $_LIBFLAGS -Wl,--end-group"
)
2022-08-02 02:21:14 -07:00
# for color terminal output when available
if "TERM" in os.environ:
env["ENV"]["TERM"] = os.environ["TERM"]
env["CC"] = "clang"
2023-07-06 23:55:29 -07:00
env["CXX"] = "clang++"
2023-09-01 00:30:02 -07:00
env.Append(CPPPATH=[Dir("arch/pthread/include").srcnode()])
2022-08-02 02:21:14 -07:00
if "darwin" in sys.platform:
env.Append(
LINKFLAGS=["-dead_strip"],
)
elif "linux" in sys.platform:
2022-08-04 21:44:38 -07:00
env["RANLIB"] = "llvm-ranlib"
env["AR"] = "llvm-ar"
2022-08-02 02:21:14 -07:00
env.Append(
CPPDEFINES={"_POSIX_C_SOURCE": "200809L"}, LINKFLAGS=["-Wl,--gc-sections"]
)
librt = SConscript(
dirs="src", variant_dir="build/lib", duplicate=False, exports=["env"]
)
2023-07-08 13:47:09 -07:00
librt_pthread = SConscript(
2022-09-11 19:33:42 -07:00
"arch/pthread/SConscript",
variant_dir="build/lib/pthread",
2018-08-23 02:43:03 -07:00
duplicate=False,
2023-03-19 22:28:44 -07:00
exports={"env": env},
2022-08-02 02:21:14 -07:00
)
2023-03-19 22:28:44 -07:00
example_env = env.Clone()
example_env.Append(
2023-07-08 13:47:09 -07:00
LIBS=[librt, librt_pthread],
)
2022-08-02 02:21:14 -07:00
SConscript(
dirs="examples", variant_dir="build", duplicate=False, exports={"env": example_env}
2018-08-23 02:43:03 -07:00
)
2023-07-06 23:55:29 -07:00
cxx_example_env = example_env.Clone()
cxx_example_env.Append(
CPPPATH=[Dir("cxx/include").srcnode()],
CXXFLAGS=[
"-std=gnu++17",
"-stdlib=libc++",
"-Wno-c++98-compat-pedantic",
"-Wno-c99-designator",
"-Wno-c11-extensions",
"-Wno-global-constructors",
"-Wno-old-style-cast",
],
)
SConscript(
dirs="cxx/examples",
variant_dir="build/cxx",
duplicate=False,
exports={"env": cxx_example_env},
)