Update Makefile to support different release environments.

pull/9/head
Joshua Potter 2023-11-26 08:40:55 -07:00
parent 36f5bf1dfc
commit 0f3d5b26b1
5 changed files with 93 additions and 15 deletions

2
.gitignore vendored
View File

@ -2,5 +2,5 @@
.direnv/ .direnv/
bootstrap bootstrap
compile_commands.json compile_commands.json
dist/
docs/ docs/
test/test

View File

@ -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 := debug
@${BUILD} PREFIX := ${CURDIR}/dist/${BUILD}
OUT := bootstrap
bear: include/*.h src/*.c CCFLAGS.debug := -DDEBUG -g -Og
@bear -- ${BUILD} 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 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 test: dist/test/suites
clang -I include src/*.c test/*.c -o test/test -lm 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 .PHONY: test

View File

@ -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 any functionality (or lack thereof) reflects my own needs as I have come across
them. them.
### Testing
TODO
### Documentation ### Documentation
We use [doxygen](https://www.doxygen.nl/index.html) for documentation We use [doxygen](https://www.doxygen.nl/index.html) for documentation

View File

@ -18,6 +18,22 @@
''; '';
in 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 { devShells.default = pkgs.mkShell.override {
# https://nixos.wiki/wiki/Using_Clang_instead_of_GCC # https://nixos.wiki/wiki/Using_Clang_instead_of_GCC
stdenv = pkgs.clangStdenv; stdenv = pkgs.clangStdenv;
@ -28,9 +44,6 @@
codelldb codelldb
doxygen doxygen
]; ];
buildInputs = with pkgs; [
ncurses
];
shellHook = '' shellHook = ''
export BOOTSTRAP_ROOT_DIR="${./specs}" export BOOTSTRAP_ROOT_DIR="${./specs}"
''; '';