From 0162dcc709ae07713d1ee092b75a76b2f167867a Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 3 Feb 2026 18:55:00 +0000 Subject: [PATCH] Switch to Makefile for build system --- .dir-locals.el | 2 +- .gitignore | 5 ++--- Makefile | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ build.sh | 40 --------------------------------------- 4 files changed, 54 insertions(+), 44 deletions(-) create mode 100644 Makefile delete mode 100644 build.sh diff --git a/.dir-locals.el b/.dir-locals.el index 9dd9c84..e44a0f2 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -1,6 +1,6 @@ ;;; Directory Local Variables -*- no-byte-compile: t -*- ;;; For more information see (info "(emacs) Directory Variables") -((nil . ((compile-command . "sh build.sh") +((nil . ((compile-command . "make MODE=debug") (+license/license-choice . "Unlicense"))) (c-mode . ((mode . clang-format)))) diff --git a/.gitignore b/.gitignore index af974b9..28e9d1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ -*.o -*.out +build/ .cache/ compile_commands.json -TAGS \ No newline at end of file +TAGS diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f176f36 --- /dev/null +++ b/Makefile @@ -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)) diff --git a/build.sh b/build.sh deleted file mode 100644 index d70dfd9..0000000 --- a/build.sh +++ /dev/null @@ -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