-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
67 lines (46 loc) · 1.52 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
CC ?= clang
LIBS := -static -lcap -lseccomp
DEFS := -DDEBUG
INCLUDES := -I/usr/include
BIN := tinyc
LIB := ./src/libtinyc.a
SOURCE_BIN := ./src/main.c
BUILD := debug
CFLAGS := -std=gnu99 -Wall -O2
SRCS := $(shell find ./src/ -name '*.c')
LIB_OBJS := $(patsubst %.c, %.o, $(filter-out $(SOURCE_BIN), $(SRCS)))
TESTS := $(shell find ./test/ -name '*.c')
TESTS_BINS := $(patsubst %.c, %.out, $(filter-out $(SOURCE_BIN), $(TESTS)))
all: $(BIN) depend
$(BIN): $(LIB) $(SOURCE_BIN)
$(CC) $(CFLAGS) $(SOURCE_BIN) $(DEFS) $(INCLUDES) -o $@ $< $(LIBS)
install: $(BIN)
sudo cp ./tinyc /usr/local/bin/tinyc
test: clean all $(TESTS_BINS)
@echo "-------"
@echo "TESTS:"
@echo "-------"
@find ./test/ -name "*.out" -exec /bin/sh -c '{ echo {} ; ./{} ; }' \;
test-leak: clean all $(TESTS_BINS)
@echo "-------"
@echo "TEST LEAK:"
@echo "-------"
@find ./test/ -name "*.out" -exec /bin/sh -c '{ echo {} ; valgrind --leak-check=yes --error-exitcode=1 {} ; }' \;
$(LIB): $(LIB_OBJS)
$(AR) rvs $@ $^
%.o: %.c
$(CC) $(CFLAGS) $(DEFS) $(INCLUDES) -c -o $@ $<
depend: .depend
.depend: $(SRCS)
$(CC) $(CFLAGS) $(INCLUDES) -MM $^ -MF ./.depend
include .depend
%.out: %.c
$(CC) $(CFLAGS) $< $(DEFS) $(INCLUDES) $(LIBS) -o $@ $(LIB)
print-%:
@echo '$*=$($*)'
clean:
find . \( -name "*.o" -o -name "*.a" -o -name "*.out" \) -type f -delete &
find . \( -name "callgrind.*" -o -name $(BIN) \) -type f -delete
fmt:
find . -name "*.c" -o -name "*.h" | xargs clang-format -style=file -i
.PHONY: clean depend fmt