Switch to Makefile for build system

This commit is contained in:
2026-02-03 18:55:00 +00:00
parent 6ec0108566
commit 0162dcc709
4 changed files with 54 additions and 44 deletions

View File

@@ -1,6 +1,6 @@
;;; Directory Local Variables -*- no-byte-compile: t -*- ;;; Directory Local Variables -*- no-byte-compile: t -*-
;;; For more information see (info "(emacs) Directory Variables") ;;; For more information see (info "(emacs) Directory Variables")
((nil . ((compile-command . "sh build.sh") ((nil . ((compile-command . "make MODE=debug")
(+license/license-choice . "Unlicense"))) (+license/license-choice . "Unlicense")))
(c-mode . ((mode . clang-format)))) (c-mode . ((mode . clang-format))))

5
.gitignore vendored
View File

@@ -1,5 +1,4 @@
*.o build/
*.out
.cache/ .cache/
compile_commands.json compile_commands.json
TAGS TAGS

51
Makefile Normal file
View File

@@ -0,0 +1,51 @@
CC=cc
DIST=build
OUT=$(DIST)/alisp.out
UNITS=main.c $(shell find ./runtime -type 'f')
OBJECTS:=$(patsubst %.c, $(DIST)/%.o, $(UNITS))
LDFLAGS=
GFLAGS=-Wall -Wextra -Wpedantic -std=c23 -I./
DFLAGS=-ggdb -fsanitize=address -fsanitize=undefined
RFLAGS=-O3
MODE=release
ifeq ($(MODE), release)
CFLAGS=$(GFLAGS) $(RFLAGS)
else
CFLAGS=$(GFLAGS) $(DFLAGS)
endif
# Dependency generation
DEPFLAGS=-MT $@ -MMD -MP -MF
DEPDIR=$(DIST)/deps
$(OUT): $(OBJECTS) | $(DIST)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
$(DIST)/%.o: %.c | $(DIST) $(DEPDIR)
$(CC) $(CFLAGS) $(DEPFLAGS) $(DEPDIR)/$*.d -c -o $@ $<
$(DIST):
mkdir -p $(DIST) $(DIST)/runtime
$(DEPDIR):
mkdir -p $(DEPDIR)
mkdir -p $(DEPDIR)/runtime
clangd: compile_commands.json
compile_commands.json: Makefile
bear -- $(MAKE) -B MODE=debug
.PHONY: run clean examples
ARGS=
run: $(OUT)
./$^ $(ARGS)
clean:
rm -rf $(DIST)
DEPS:=$(patsubst %.c,$(DEPDIR)/%.d, $(UNITS))
include $(wildcard $(DEPS))

View File

@@ -1,40 +0,0 @@
#!/usr/bin/env sh
set -xe
CFLAGS="-Wall -Wextra -std=c11 -ggdb -fsanitize=address -fsanitize=undefined -Wswitch -Wswitch-enum"
LDFLAGS="-lc"
LIB=$(find "./runtime" -type 'f')
OUT="build/alisp.out"
build() {
mkdir -p build;
cc $CFLAGS -o $OUT $LIB main.c $LDFLAGS;
cc $CFLAGS -o build/test.out $LIB test/test.c $LDFLAGS;
}
clean() {
rm -v $OUT test.out;
}
run() {
./$OUT;
}
test() {
./build/test.out
}
build
if [ "$1" = "run" ]
then
run
elif [ "$1" = "test" ]
then
test
elif [ "$1" = "clean" ]
then
clean
fi