90 lines
1.9 KiB
Python
90 lines
1.9 KiB
Python
# -*- python -*-
|
|
|
|
from pathlib import Path
|
|
|
|
#
|
|
# File lists
|
|
#
|
|
|
|
build_dir = "build/"
|
|
variant_dir = build_dir + "default/"
|
|
src_dir = "src/"
|
|
|
|
program_sources = ["src/main.c"]
|
|
lib_srcs = [
|
|
"src/arena.c",
|
|
"src/builtins.c",
|
|
"src/evaluate.c",
|
|
"src/memory.c",
|
|
"src/special.c",
|
|
"src/scope.c",
|
|
"src/utility.c",
|
|
"src/parse.c",
|
|
]
|
|
lib_includes = ["src/"]
|
|
|
|
|
|
test_srcs = [
|
|
"test/test_arena.c",
|
|
"test/test_e2e.c",
|
|
"test/test_parse.c",
|
|
"test/test_scope.c",
|
|
"test/test_utility.c",
|
|
]
|
|
test_lib_srcs = ["third-party/unity/src/unity.c"]
|
|
test_lib_includes = ["third-party/unity/src/"]
|
|
|
|
#
|
|
# Construct Environments
|
|
#
|
|
|
|
VariantDir(variant_dir, ".", duplicate=0)
|
|
# Minimization flags for later:
|
|
# CCFLAGS = ["-Oz", "-flto", "-ffunction-sections", "-fdata-sections", "-Wl,--gc-sections", "-lreadline"]
|
|
CCFLAGS = ["-ggdb", "-O0"]
|
|
env = Environment(
|
|
CPPPATH=lib_includes, COMPILATIONDB_USE_ABSPATH=True, CCFLAGS=CCFLAGS
|
|
)
|
|
env.Tool("compilation_db")
|
|
env.CompilationDatabase()
|
|
|
|
test_env = env.Clone()
|
|
test_env.Append(CPPPATH=test_lib_includes)
|
|
|
|
|
|
#
|
|
# Construct Environments
|
|
#
|
|
|
|
# Generate REPL
|
|
|
|
|
|
lib_objs = [env.Object(p) for p in lib_srcs]
|
|
env.Program(variant_dir + "uclisp", lib_objs + program_sources, LIBS=["readline"])
|
|
|
|
# Generate unit test executables
|
|
|
|
test_lib_objs = [
|
|
test_env.Object(variant_dir + p, CPPPATH=lib_includes + test_lib_includes)
|
|
for p in test_lib_srcs
|
|
]
|
|
test_deps = test_lib_objs + lib_objs
|
|
tests = [test_env.Program(variant_dir + p, [p] + test_deps) for p in test_srcs]
|
|
|
|
#
|
|
# Generate Test Runner script
|
|
#
|
|
|
|
env.Substfile(
|
|
"run_tests.sh.in",
|
|
SUBST_DICT={
|
|
"@tests@": " ".join(str(Path(str(test[0])).resolve()) for test in tests)
|
|
},
|
|
)
|
|
|
|
env.Command(variant_dir + "run_tests", "run_tests.sh", Chmod("run_tests.sh", 0o755))
|
|
|
|
# Copy default build compile commands to root, which is where tools seem to want
|
|
# it.
|
|
Copy("compile_commands.json", variant_dir + "compile_commands.json")
|