-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
53 lines (40 loc) · 1.22 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
BUILDROOT?=build
.DEFAULT_GOAL=all
.EXTRA_PREREQS:=Makefile clib.mk
include clib.mk
CFLAGS_BASE+=-Wall -Wextra -Werror -pedantic -MMD -I$(INTERFACE) $(EXTRA_CFLAGS)
ifeq ($(TARGET),release)
CFLAGS_TARGET=-O2 -DNEBUG
else ifeq ($(TARGET),coverage)
CFLAGS_TARGET=-g -fprofile-arcs -ftest-coverage
else
TARGET=debug
CFLAGS_TARGET=-g -fsanitize=address -fsanitize=undefined
endif
BUILD=$(BUILDROOT)/$(TARGET)
CFLAGS=$(CFLAGS_BASE) $(CFLAGS_TARGET)
DEPS=$(SOURCES:%.c=$(BUILD)/%.d) $(TEST_SOURCES:%c=$(BUILD)/%.d)
-include $(DEPS)
$(BUILD)/bins/test: $(SOURCES:%.c=$(BUILD)/%.o) $(TEST_SOURCES:%.c=$(BUILD)/%.o)
@mkdir -p $(@D)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
$(BUILD)/%.o: %.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -o $@ -c $<
$(BUILD)/libphbase.a: $(SOURCES:%.c=$(BUILD)/%.o)
@mkdir -p $(@D)
ar rcs $@ $^
.PHONY: all
all: $(BUILD)/libphbase.a $(BUILD)/bins/test
@$(BUILD)/bins/test
@echo "Build of $(TARGET) target successful at $(shell date)"
ifeq ($(TARGET),coverage)
.PHONY: coverage
coverage:
lcov --capture --directory $(BUILD) --output-file $(BUILD)/coverage.info
genhtml -o $(BUILD)/coverage $(BUILD)/coverage.info
@echo "Coverage output to $(BUILD)/coverage/index.html"
endif
.PHONY: clean
clean:
rm -rf $(BUILDROOT)