Move to scons, add more infra

This commit is contained in:
2022-10-11 22:00:54 -04:00
parent 54f3ff5a67
commit 9cde08b910
5 changed files with 77 additions and 43 deletions

4
.gitignore vendored
View File

@@ -1 +1,5 @@
build build
compile_commands.json
# scons cruft
.cache
.sconsign.dblite

View File

@@ -1,41 +0,0 @@
TARGET_EXEC ?= nihilipsm
BUILD_DIR ?= ./build
SRC_DIRS ?= ./src
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CPPFLAGS ?= $(INC_FLAGS) -MMD -MP
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
$(CC) $(OBJS) -o $@ $(LDFLAGS)
# assembly
$(BUILD_DIR)/%.s.o: %.s
$(MKDIR_P) $(dir $@)
$(AS) $(ASFLAGS) -c $< -o $@
# c source
$(BUILD_DIR)/%.c.o: %.c
$(MKDIR_P) $(dir $@)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
# c++ source
$(BUILD_DIR)/%.cpp.o: %.cpp
$(MKDIR_P) $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
.PHONY: clean
clean:
$(RM) -r $(BUILD_DIR)
-include $(DEPS)
MKDIR_P ?= mkdir -p

63
SConstruct Normal file
View File

@@ -0,0 +1,63 @@
from pathlib import Path
#
# File lists
#
build_dir = "build/default/"
src_dir = "src/"
program_sources = ["src/main.c"]
lib_srcs = []
lib_includes = ["src/"]
test_srcs = [""]
test_lib_srcs = ["third-party/unity/src/unity.c"]
test_lib_includes = ["third-party/unity/src/"]
#
# Construct Environments
#
VariantDir(build_dir, ".", duplicate=0)
env = Environment(CPPPATH=lib_includes, COMPILATIONDB_USE_ABSPATH=True)
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(build_dir + "nihilispm", lib_objs + program_sources)
# Generate unit test executables
test_lib_objs = [
test_env.Object(build_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(build_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(build_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", build_dir + "compile_commands.json")

7
run_tests.sh.in Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/bash
TESTS=@tests@
for test in $TESTS; do
echo ===========================
echo Test: $test
$test
done

View File

@@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
int main(const char **argv, int argc) { int main(int argc, const char **argv) {
printf("Hello, world!\n"); (void) argc, (void) argv;
return 0; return 0;
} }