Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
71 lines (51 loc) · 1.81 KB
/
Copy pathMakefile
File metadata and controls
71 lines (51 loc) · 1.81 KB
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
CC ?= cc
AR ?= ar
# Optimisation and instrumentation only. tools/coverage-html.sh overrides this
# to add gcov instrumentation, so the standard, include paths and warning set
# below stay identical between a normal build and a coverage build.
OPT ?= -O2
WARNINGS = -Wall -Wextra -Wpedantic -Wconversion -Wshadow -Wcast-align -Wcast-qual \
-Wpointer-arith -Wformat=2 -Wmissing-prototypes -Wstrict-prototypes \
-Wredundant-decls -Wundef
# Build flags shared by the library, example and tests.
CFLAGS = $(OPT) -std=c99 -Iinclude $(WARNINGS)
BUILD_DIR = build
OBJ_DIR = $(BUILD_DIR)/obj
LIB_DIR = $(BUILD_DIR)/lib
LIB = $(LIB_DIR)/libcfdp.a
SRCS = $(wildcard src/*.c)
OBJS = $(patsubst src/%.c,$(OBJ_DIR)/%.o,$(SRCS))
# Test entry point plus one test file per source module.
TEST_SRCS = $(wildcard tests/*.c)
TEST_HDRS = $(wildcard tests/*.h)
TEST_OBJS = $(patsubst tests/%.c,$(OBJ_DIR)/tests/%.o,$(TEST_SRCS))
CTEST_PATH = $(BUILD_DIR)/tests/ctest
EXAMPLE_PATH = $(BUILD_DIR)/examples/example
all: lib ctest example
lib: $(LIB)
$(LIB): $(OBJS)
mkdir -p $(dir $@)
$(AR) rcs $@ $(OBJS)
$(OBJ_DIR)/%.o: src/%.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
ctest: $(CTEST_PATH)
# Test objects live under $(OBJ_DIR) so gcov's .gcno/.gcda files stay inside
# $(BUILD_DIR) instead of being dropped in the repository root.
$(OBJ_DIR)/tests/%.o: tests/%.c $(TEST_HDRS)
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -Itests -c $< -o $@
$(CTEST_PATH): $(TEST_OBJS) $(LIB)
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(TEST_OBJS) $(LIB) -o $@
example: $(EXAMPLE_PATH)
$(EXAMPLE_PATH): examples/example.c $(LIB)
mkdir -p $(dir $@)
$(CC) $(CFLAGS) examples/example.c $(LIB) -o $@
run: ctest
$(CTEST_PATH)
coverage-html:
bash tools/coverage-html.sh
clean:
rm -rf $(BUILD_DIR)
.PHONY: all lib ctest example run clean coverage-html