Switch to Makefile for build system
This commit is contained in:
@@ -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))))
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,4 @@
|
|||||||
*.o
|
build/
|
||||||
*.out
|
|
||||||
.cache/
|
.cache/
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
TAGS
|
TAGS
|
||||||
51
Makefile
Normal file
51
Makefile
Normal 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))
|
||||||
40
build.sh
40
build.sh
@@ -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
|
|
||||||
Reference in New Issue
Block a user