diff --git a/.gitignore b/.gitignore index 378eac2..cb330d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ build +compile_commands.json +# scons cruft +.cache +.sconsign.dblite diff --git a/Makefile b/Makefile deleted file mode 100644 index f8a0c88..0000000 --- a/Makefile +++ /dev/null @@ -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 diff --git a/SConstruct b/SConstruct new file mode 100644 index 0000000..3f08374 --- /dev/null +++ b/SConstruct @@ -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") diff --git a/run_tests.sh.in b/run_tests.sh.in new file mode 100755 index 0000000..6ae5cfb --- /dev/null +++ b/run_tests.sh.in @@ -0,0 +1,7 @@ +#!/bin/bash +TESTS=@tests@ +for test in $TESTS; do + echo =========================== + echo Test: $test + $test +done diff --git a/src/main.c b/src/main.c index f3ed1bd..60b8a17 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #include -int main(const char **argv, int argc) { - printf("Hello, world!\n"); +int main(int argc, const char **argv) { + (void) argc, (void) argv; + return 0; }