From 33d09be340ec13cd02735dbcfe4fc810c4ad5902 Mon Sep 17 00:00:00 2001 From: nodist Date: Sun, 13 Sep 2026 12:06:49 -0400 Subject: set up make --- .gitignore | 4 ++++ Makefile | 39 ++++++++++++++++++++++++++++++++++++ README | 30 ++++++++++++++++++++++++++++ TESTING | 1 + include/kpl.h | 2 ++ include/kpl_test.h | 4 ++++ source/kpl.c | 8 ++++++++ test/README | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test.c | 6 ++++++ 9 files changed, 152 insertions(+) create mode 100644 Makefile create mode 100644 include/kpl.h create mode 100644 include/kpl_test.h create mode 100644 source/kpl.c create mode 100644 test/README create mode 100644 test/test.c diff --git a/.gitignore b/.gitignore index 1750fe8..6612c23 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ qemu +kpl +kpl_test +source/*.o +test/*.o diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e239bc4 --- /dev/null +++ b/Makefile @@ -0,0 +1,39 @@ + +.PHONY: clean + +MAKEFLAGS := -j$(shell nproc) + +INCLUDE_DIR := "./include" +SOURCE_DIR := "./source" +TEST_DIR := "./test" + +CC := gcc +OO := -g -Og +FFLAGS := -fno-omit-frame-pointer -fhardened +WFLAGS := -Wall -Wextra -Wstack-protector +CFLAGS = -std=gnu99 $(FLAGS) -I$(INCLUDE_DIR) $(OO) $(FFLAGS) $(WFLAGS) +CCOBJ = $(CC) -o $@ $^ $(CFLAGS) + +OBJECTS := $(patsubst %.c, %.o, $(wildcard ./source/*.c)) + +kpl: OO := -O2 +kpl: WFLAGS += -Werror +kpl: FLAGS += -DKPL_MAIN +kpl: $(OBJECTS) + $(CCOBJ) + +TEST_OBJECTS := $(patsubst %.c, %.o, $(wildcard ./test/*.c)) + +kpl_test: $(OBJECTS) $(TEST_OBJECTS) + $(CCOBJ) + +kpl_test_error: FFLAGS += -fsanitize=address,leak,undefined +kpl_test_error: kpl_test + +kpl_test_thread: FFLAGS += -fsanitize=thread +kpl_test_thread: kpl_test + +clean: + @rm -fv kpl + @rm -fv kpl_test + @find -type f -name "*.o" -exec rm -v {} \; diff --git a/README b/README index a5945df..f6037f9 100644 --- a/README +++ b/README @@ -1 +1,31 @@ KPL + +--- + +Requirements: + +Linux 6+ +GCC 14+ +make + +--- + +Building: + +make + +--- + +Running: + +./kpl [OPTIONS] ./path/to/file.kpl # Run File +./kpl [OPTIONS] # Start REPL +./kpl -h # See OPTIONS + +--- + +Testing: + +See TESTING + +--- diff --git a/TESTING b/TESTING index 77b9150..a413c07 100644 --- a/TESTING +++ b/TESTING @@ -71,3 +71,4 @@ Cleaning: ./vm.sh -clean # Remove the testing environment +--- diff --git a/include/kpl.h b/include/kpl.h new file mode 100644 index 0000000..99ddf32 --- /dev/null +++ b/include/kpl.h @@ -0,0 +1,2 @@ + +#pragma once diff --git a/include/kpl_test.h b/include/kpl_test.h new file mode 100644 index 0000000..1a61a30 --- /dev/null +++ b/include/kpl_test.h @@ -0,0 +1,4 @@ + +#pragma once + +#include "kpl.h" diff --git a/source/kpl.c b/source/kpl.c new file mode 100644 index 0000000..904c14b --- /dev/null +++ b/source/kpl.c @@ -0,0 +1,8 @@ + +#include "kpl.h" + +#ifdef KPL_MAIN +int main(void) { + return 1; +} +#endif diff --git a/test/README b/test/README new file mode 100644 index 0000000..80d57e6 --- /dev/null +++ b/test/README @@ -0,0 +1,58 @@ +Testing + +--- + +File Layout: + +The test files mirror the src files, so a function in src/file.c would have a test in test/file.c + +--- + +Includes: + +#include "kpl_test.h" + +This is the only include a .c file in the test folder needs + +--- + +Writing Tests: + +TEST(test_name) { + // TEST CODE +} + +Tests pass by default + +--- + +Asserting: + +ASSERT(CONDITION, FAIL_MESSAGE); + +--- + +Failing: + +FAIL(FAIL_MESSAGE); + +--- + +Building: + +make kpl_test # build test exec +make kpl_test_error # build test exec with address, leak and undefined sanitizer +make kpl_test_thread # build test exec with thread sanitizer + +All objects need to be built with the same sanitizer and do not run valgrind when sanitizers are added + +--- + +Running: + +./kpl_test [OPTIONS] # Run all tests +./kpl_test [OPTIONS] NAME # Run test named NAME +./kpl_test [OPTIONS] NAME1 NAME2 ... # Run selected tests named NAM1 NAME2 ... +./kpl_test -h # Show OPTIONS + +--- diff --git a/test/test.c b/test/test.c new file mode 100644 index 0000000..f12ee6e --- /dev/null +++ b/test/test.c @@ -0,0 +1,6 @@ + +#include "kpl_test.h" + +int main(void) { + return 2; +} -- cgit v1.2.3