-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
81 lines (62 loc) · 1.91 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
default: lib bin
.PHONY: lib bin test clean clean_test
CC = gcc
LD = gcc
AR = gcc-ar
MD = mkdir -p
RM = rm -rf
CSTD = c99
CFLAGS = -std=$(CSTD) -Wall -Wextra -pedantic -Werror -I$(INCLUDEDIR)
LDFLAGS =
LIBS = -lm
ARFLAGS = cr
TESTFLAGS = -fsanitize=address -fsanitize=leak -fsanitize=undefined
DEBUGFLAGS := -g -O0 $(TESTFLAGS)
RELEASEFLAGS = -DNDEBUG -flto -O3
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td
ifdef RELEASE
CFLAGS += $(RELEASEFLAGS)
LDFLAGS += $(RELEASEFLAGS)
else
CFLAGS += $(DEBUGFLAGS)
LDFLAGS += $(DEBUGFLAGS)
TESTFLAGS =
endif
BUILDDIR = build
OBJDIR = build/objs
DEPDIR = build/deps
TESTDIR = $(BUILDDIR)/tests
DIRS = $(BUILDDIR) $(OBJDIR) $(DEPDIR) $(TESTDIR)
INCLUDEDIR = include
SRCDIR = src
OBJS = $(patsubst %.c,$(OBJDIR)/%.o,$(filter-out %_test.c,$(notdir $(wildcard $(SRCDIR)/*.c))))
TESTS = $(patsubst %_test.c,$(TESTDIR)/%,$(notdir $(wildcard $(SRCDIR)/*_test.c)))
TESTLOG = $(BUILDDIR)/test.log
$(DIRS):
$(MD) $@
$(OBJDIR)/%.o : $(SRCDIR)/%.c
$(OBJDIR)/%.o : $(SRCDIR)/%.c $(DEPDIR)/%.d | $(DIRS)
$(CC) $(DEPFLAGS) $(CFLAGS) -c -o $@ $<
@mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d && touch $@
$(BUILDDIR)/libsmlisp.a : $(filter-out %/main.o,$(OBJS)) | $(DIRS)
$(AR) $(ARFLAGS) $@ $^
$(BUILDDIR)/smlisp : $(OBJDIR)/main.o $(BUILDDIR)/libsmlisp.a | $(DIRS)
$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
$(TESTDIR)/% : $(SRCDIR)/%_test.c $(BUILDDIR)/libsmlisp.a | $(DIRS)
$(CC) $(CFLAGS) $(TESTFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
lib: $(BUILDDIR)/libsmlisp.a
bin: $(BUILDDIR)/smlisp
test: $(TESTS) | $(DIRS)
@echo Starting test suite
@$(RM) $(TESTLOG)
@for test in $^; do \
printf "Testing $$(basename "$$test")...\r"; \
"$$test" 2>&1 | tee $(TESTLOG) | grep "PANIC\|FAIL\|tests passed"; \
done
clean_test:
$(RM) $(TESTDIR)
clean:
$(RM) $(DIRS)
$(DEPDIR)/%.d: ;
.PRECIOUS: $(DEPDIR)/%.d
include $(wildcard $(DEPDIR)/*.d)