diff --git a/.gitignore b/.gitignore index 38562b5..6d068cc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ .direnv/ bootstrap compile_commands.json +dist/ docs/ -test/test diff --git a/Makefile b/Makefile index a49458a..2899f48 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,81 @@ -BUILD=clang -Og -g -I include src/*.c main.c -o bootstrap -lm +# ============================================================ +# Configuration +# ============================================================ -all: build bear +# To create a release build, run `make BUILD=release`. -build: include/*.h src/*.c - @${BUILD} +BUILD := debug +PREFIX := ${CURDIR}/dist/${BUILD} +OUT := bootstrap -bear: include/*.h src/*.c - @bear -- ${BUILD} +CCFLAGS.debug := -DDEBUG -g -Og +CCFLAGS.release := -DNDEBUG +LDFLAGS := -lm -docs: +# ============================================================ +# Build +# ============================================================ + +COMPILE := ${CC} ${CCFLAGS.${BUILD}} -I include src/*.c main.c -o ${PREFIX}/${OUT} ${LDFLAGS} + +all: build all.${BUILD} +all.debug: bear +all.release: + +build: ${PREFIX}/${OUT} + +${PREFIX}/${OUT}: ${PREFIX} include/*.h src/*.c + ${COMPILE} + +${PREFIX}: + mkdir -p $@ + +# ============================================================ +# Compilation Database +# +# Generate a compilation database using [Bear](https://github.com/rizsotto/Bear). +# ============================================================ + +bear: compile_commands.json + +compile_commands.json: include/*.h src/*.c main.c +# This file is only constructed in debug mode. If interested in expanding this +# generation to other build types, add a release-specific dependency. +ifeq ($(BUILD), debug) + mkdir -p dist/debug + bear -- ${COMPILE} +endif + +# ============================================================ +# Documentation. +# +# Generate documentation using [Doxygen](https://www.doxygen.nl/index.html). +# ============================================================ + +docs: docs/index.html + +# The `index.html` file is regenerated on each invocation of `doxygen`. +docs/index.html: Doxyfile include/*.h src/*.c doxygen -test: test/test - $^ +# ============================================================ +# Testing. +# +# We use [Sput](https://www.use-strict.de/sput-unit-testing/) to run tests. +# ============================================================ -test/test: include/*.h src/*.c test/*.h test/*.c - clang -I include src/*.c test/*.c -o test/test -lm +test: dist/test/suites + dist/test/suites + +dist/test/suites: include/*.h src/*.c test/*.h test/*.c + mkdir -p dist/test + ${CC} ${CCFLAGS.debug} -I include src/*.c test/*.c -o dist/test/suites ${LDFLAGS} + +# ============================================================ +# Other +# ============================================================ + +clean: + rm -r ${PREFIX} .PHONY: test diff --git a/README.md b/README.md index 8030d46..1cadedc 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,10 @@ Keep in mind this tool was originally written for personal usage and as such, any functionality (or lack thereof) reflects my own needs as I have come across them. +### Testing + +TODO + ### Documentation We use [doxygen](https://www.doxygen.nl/index.html) for documentation diff --git a/flake.nix b/flake.nix index 24d1813..016b66d 100644 --- a/flake.nix +++ b/flake.nix @@ -18,6 +18,22 @@ ''; in { + packages = { + bootstrap = pkgs.stdenv.mkDerivation { + pname = "bootstrap"; + src = ./.; + version = "0.1.0"; + nativeBuildInputs = with pkgs; [ + clang + ]; + + buildPhase = '' + make release + ''; + }; + + default = self.packages.${system}.bootstrap; + }; devShells.default = pkgs.mkShell.override { # https://nixos.wiki/wiki/Using_Clang_instead_of_GCC stdenv = pkgs.clangStdenv; @@ -28,9 +44,6 @@ codelldb doxygen ]; - buildInputs = with pkgs; [ - ncurses - ]; shellHook = '' export BOOTSTRAP_ROOT_DIR="${./specs}" ''; diff --git a/test/test.c b/test/suites.c similarity index 100% rename from test/test.c rename to test/suites.c