-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
84 lines (70 loc) · 2.67 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
82
83
84
CC=clang
CFLAGS = -std=c11 -Wall -pedantic -Iinclude -Wall -g -fsanitize=address
SRC_FILES = $(wildcard src/*.c) $(wildcard src/*/*.c)
FILES = $(basename $(SRC_FILES:src/%=%))
OBJ_FILES = $(addprefix obj/,$(FILES:=.o))
TEST_FILES = $(join $(dir $(addprefix bin/tests/,$(FILES))), $(addprefix test_,$(notdir $(FILES))))
VERSION = 0.1.0
RWILDCARD = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
# module variables
MODULES := [email protected]:thomasbarrett/[email protected]
MODULES_REPOSITORY := $(addprefix git@, $(foreach dep, $(MODULES), $(word 2, $(subst @, ,$(dep)))))
MODULES_VERSION := $(foreach dep, $(MODULES), $(word 3, $(subst @, ,$(dep))))
MODULES_MAJOR_VERSION := $(foreach dep, $(MODULES_VERSION), $(word 1, $(subst ., ,$(dep))))
MODULES_PREFIX := /tmp/.modules/
MODULES_ROOT := $(foreach dep, $(MODULES_REPOSITORY), $(word 1, $(subst ., ,$(word 2, $(subst :, ,$(dep))))))
MODULES_PATH := $(addprefix $(MODULES_PREFIX), $(join $(MODULES_ROOT), $(addprefix /,$(MODULES_MAJOR_VERSION))))
MODULES_INCLUDE := $(foreach p, $(MODULES_PATH), -I$(p:=/include))
MODULES_OBJ = $(foreach p, $(MODULES_PATH), $(addprefix $p/, $(shell $(MAKE) object-files -C $p 2>/dev/null)))
.PHONY: all
all: $(TEST_FILES) $(OBJ_FILES)
.PHONY: clean
clean:
@rm -rf obj
@rm -rf bin
$(MODULES_OBJ): build-deps
obj/%.o: src/%.c
@mkdir -p $(dir $@)
@$(CC) -c $(CFLAGS) $(MODULES_INCLUDE) $^ -o $@
bin/tests/%: tests/%.c $(OBJ_FILES) $(MODULES_OBJ)
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) $(MODULES_INCLUDE) $^ -o $@
.PHONY: test
test: $(TEST_FILES)
tests/run.sh $(TEST_FILES)
.PHONY: version
version:
@echo ${VERSION}
.PHONY: list-deps
list-deps:
@echo $(MODULES)
.PHONY: install-deps
install-deps:
@$(foreach i, $(shell seq 1 $(words $(MODULES))), \
M_PATH=$(word $i, $(MODULES_PATH)); \
M_ROOT=$(word $i, $(MODULES_ROOT)); \
M_REPOSITORY=$(word $i, $(MODULES_REPOSITORY)); \
M_VERSION=$(word $i, $(MODULES_VERSION)); \
if [ ! -d "$${M_PATH}" ]; then \
printf "[ %s ] %s\n" $${M_VERSION} $${M_ROOT}; \
git clone "$${M_REPOSITORY}" --branch $${M_VERSION} --single-branch $${M_PATH} 2> /dev/null; \
fi \
)
# The build-deps target builds all dependency module makefiles
.PHONY: build-deps
build-deps: install-deps
@$(foreach i, $(shell seq 1 $(words $(MODULES))), \
M_PATH=$(word $i, $(MODULES_PATH)); \
M_VERSION=$(word $i, $(MODULES_VERSION)); \
M_ROOT=$(word $i, $(MODULES_ROOT)); \
printf "[ %s ] %s\n" $${M_VERSION} $${M_ROOT}; \
$(MAKE) -C $${M_PATH} &> /dev/null; \
)
.PHONY: object-files
object-files:
@echo $(OBJ_FILES)
.PHONY: lint
lint:
@for file in $(SRC_FILES); do \
clang-tidy $$file --checks=clang-analyzer-*,performance-* -- $(CFLAGS); \
done