148 lines
3.3 KiB
Python
148 lines
3.3 KiB
Python
import os
|
|
import sys
|
|
|
|
llvm_flags = [
|
|
"-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",
|
|
"-g3",
|
|
"-ffunction-sections",
|
|
"-fdata-sections",
|
|
]
|
|
|
|
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",
|
|
)
|
|
|
|
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"])
|
|
|
|
|
|
def ld_emitter(target, source, env):
|
|
map_file = os.path.splitext(str(target[0]))[0] + ".map"
|
|
return target + [map_file], source
|
|
|
|
|
|
env = Environment(
|
|
CPPPATH=[Dir("include").srcnode()],
|
|
CCFLAGS=llvm_flags,
|
|
CFLAGS=["-std=c17"],
|
|
LINKFLAGS=llvm_flags,
|
|
PROGEMITTER=ld_emitter,
|
|
CCCOMSTR="cc $TARGET",
|
|
CXXCOMSTR="c++ $TARGET",
|
|
ASCOMSTR="as $TARGET",
|
|
ASPPCOMSTR="as $TARGET",
|
|
LINKCOMSTR="ld $TARGET",
|
|
ARCOMSTR="ar $TARGET",
|
|
RANLIBCOMSTR="ranlib $TARGET",
|
|
)
|
|
|
|
if GetOption("log"):
|
|
env.Append(CPPDEFINES={"RT_LOG_ENABLE": 1})
|
|
|
|
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"
|
|
)
|
|
|
|
# for color terminal output when available
|
|
if "TERM" in os.environ:
|
|
env["ENV"]["TERM"] = os.environ["TERM"]
|
|
|
|
env["CC"] = "clang"
|
|
env["CXX"] = "clang++"
|
|
env.Append(CPPPATH=[Dir("arch/pthread/include").srcnode()])
|
|
|
|
if "darwin" in sys.platform:
|
|
env.Append(
|
|
LINKFLAGS=["-dead_strip"],
|
|
)
|
|
elif "linux" in sys.platform:
|
|
env["RANLIB"] = "llvm-ranlib"
|
|
env["AR"] = "llvm-ar"
|
|
env.Append(
|
|
CPPDEFINES={"_POSIX_C_SOURCE": "200809L"}, LINKFLAGS=["-Wl,--gc-sections"]
|
|
)
|
|
|
|
librt = SConscript(
|
|
dirs="src", variant_dir="build/lib", duplicate=False, exports=["env"]
|
|
)
|
|
|
|
librt_pthread = SConscript(
|
|
"arch/pthread/SConscript",
|
|
variant_dir="build/lib/pthread",
|
|
duplicate=False,
|
|
exports={"env": env},
|
|
)
|
|
|
|
example_env = env.Clone()
|
|
example_env.Append(
|
|
LIBS=[librt, librt_pthread],
|
|
)
|
|
|
|
SConscript(
|
|
dirs="examples", variant_dir="build", duplicate=False, exports={"env": example_env}
|
|
)
|
|
|
|
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},
|
|
)
|