-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
170 lines (136 loc) · 4.9 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
######################
# SSM runtime Makefile
######################
#
# For a list of useful available targets, run `make help'.
#
# Note that this Makefile is only used to build and test the platform-generic
# core of the SSM runtime; platform-specific builds may use their own build
# system that ignores this Makefile.
#
# Any .c files under EXE_DIR are linked against this library to produce an
# executable.
#
# This Makefile also a version of the runtime library instrumented for code
# coverage analysis. The build artifacts for instrumented code are mangled using
# the test_ prefix. This version of the runtime library is used to link against
# .c files in TEST_DIR.
#
# To actually run tests, please see the runtests.sh script.
LIB_NAME := ssm
MAKE_CC ?= cc
MAKE_LD ?= $(MAKE_CC)
MAKE_AR ?= ar
PLATFORM ?= simulation
BUILD_DIR := build
SRC_DIR := src
INC_DIR := include
TEST_DIR := test
EXE_DIR := examples/$(PLATFORM)
DOC_DIR := doc
PLATFORM_DIR := platform/$(PLATFORM)
LIB_SRC := $(wildcard $(SRC_DIR)/*.c)
LIB_INC := $(wildcard include/*.h)
LIB_OBJ := $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(LIB_SRC))
LIB_TGT := $(BUILD_DIR)/lib$(LIB_NAME).a
DOC_CFG := doc/Doxyfile
DOC_SRC := README.md $(wildcard doc/*.md doc/*.dox) $(LIB_SRC) $(LIB_INC)
DOC_TGT := $(BUILD_DIR)/doc
EXE_SRC := $(wildcard $(EXE_DIR)/*.c)
EXE_OBJ := $(patsubst $(EXE_DIR)/%.c, $(BUILD_DIR)/%.o, $(EXE_SRC))
EXE_TGT := $(patsubst %.o, %, $(EXE_OBJ))
EXE_INC := $(wildcard $(EXE_DIR)/*.h)
TLIB_NAME := t$(LIB_NAME)
TLIB_OBJ := $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/test_%.o, $(LIB_SRC))
TLIB_TGT := $(BUILD_DIR)/lib$(TLIB_NAME).a
TEST_SRC := $(wildcard $(TEST_DIR)/*.c)
TEST_OBJ := $(patsubst $(TEST_DIR)/%.c, $(BUILD_DIR)/test_%.o, $(TEST_SRC))
TEST_TGT := $(patsubst %.o, %, $(TEST_OBJ))
PLATFORM_SRC := $(wildcard $(PLATFORM_DIR)/src/*.c)
PLATFORM_OBJ := $(patsubst $(PLATFORM_DIR)/src/%.c, $(BUILD_DIR)/%.o, $(PLATFORM_SRC))
$(info PLATFORM is $(PLATFORM))
COV_TGT := $(BUILD_DIR)/coverage.xml
CC = $(MAKE_CC)
CFLAGS += -g -I$(INC_DIR) -O -Wall -pedantic $(EXTRA_CFLAGS)
ifeq ($(PLATFORM),simulation)
# enforce c99 for pure testing, but don't enforce it for other platforms
CFLAGS += -std=c99
endif
ifeq ($(PLATFORM),simulation)
# Check whether valgrind is available.
# ifeq (0,0)
ifeq ($(shell which valgrind),)
$(info # Valgrind is not available; compiling without it.)
else
# If available, we try to #include <valgrind/valgrind.h>, which we use to
# instrument our memory allocator.
#
# NOTE: this is just a heuristic that may not be very reliable.
# We should probably implement better dependency management.
$(info # Valgrind seems to be available; compiling libssm with Valgrind support.)
CFLAGS += -DUSE_VALGRIND
endif
endif
TEST_CFLAGS = $(CFLAGS) -g -DSSM_DEBUG --coverage -DCONFIG_MEM_STATS
LD = $(MAKE_LD)
LDFLAGS = -L$(BUILD_DIR)
TEST_LDFLAGS = $(LDFLAGS) --coverage
LDLIBS= -lpthread
AR = $(MAKE_AR)
ARFLAGS = -cr
PHONY += lib exes tests cov docs
lib: $(LIB_TGT)
exes: $(EXE_TGT)
tests: $(TEST_TGT)
cov: $(COV_TGT)
docs: $(DOC_TGT)
$(LIB_TGT): $(LIB_OBJ)
rm -f $@
$(AR) $(ARFLAGS) $@ $+
$(TLIB_TGT): $(TLIB_OBJ)
rm -f $@
$(AR) $(ARFLAGS) $@ $+
$(EXE_TGT): %: %.o $(PLATFORM_OBJ) $(LIB_TGT)
$(LD) $(LDFLAGS) -o $@ $@.o $(PLATFORM_OBJ) -l$(LIB_NAME) $(LDLIBS)
$(TEST_TGT): %: %.o $(TLIB_TGT)
$(LD) $(TEST_LDFLAGS) -o $@ $@.o -l$(TLIB_NAME) $(LDLIBS)
vpath %.c $(SRC_DIR) $(EXE_DIR) $(TEST_DIR) $(PLATFORM_DIR)/src
$(EXE_OBJ): $(BUILD_DIR)/%.o: %.c $(LIB_INC) $(EXE_INC) | $(BUILD_DIR)
$(CC) $(CFLAGS) -c -o $@ $<
$(LIB_OBJ): $(BUILD_DIR)/%.o: %.c $(LIB_INC) | $(BUILD_DIR)
$(CC) $(CFLAGS) -c -o $@ $<
$(TLIB_OBJ) $(TEST_OBJ): $(BUILD_DIR)/test_%.o: %.c $(LIB_INC) | $(BUILD_DIR)
rm -f $(patsubst %.o, %.gcda, $@) $(patsubst %.o, %.gcno, $@)
$(CC) $(TEST_CFLAGS) -c -o $@ $<
$(PLATFORM_OBJ): $(BUILD_DIR)/%.o: %.c $(LIB_INC) | $(BUILD_DIR)
$(CC) $(CFLAGS) -c -o $@ $<
$(COV_TGT): $(TEST_TGT)
@for i in $(TEST_TGT) ; do \
echo ./$$i ;\
./$$i >/dev/null || exit $$? ;\
done
gcovr --print-summary --filter src/ --html-details build/coverage.html --xml build/coverage.xml
$(DOC_TGT): $(DOC_CFG) $(DOC_SRC) | $(BUILD_DIR)
doxygen doc/Doxyfile
$(BUILD_DIR):
mkdir -p $@
PHONY += clean
clean:
rm -rf build
PHONY += help
help:
@echo "Available phony targets:" $(PHONY)
@echo
@echo "lib Build SSM runtime library [build/libssm.a]"
@echo "exes Build programs in examples/ [build/<example-name>]"
@echo "tests Build tests in test/ [build/test_<test-name>]"
@echo "cov Build coverage report [build/<filename.c>.gcov] (depends on gcovr)"
@echo "docs Build code documentation [build/doc] (depends on doxygen)"
@echo "clean Remove build directory"
@echo "help Show this help menu"
@echo
@echo "Available example targets:" $(EXE_TGT)
@echo "Available test targets:" $(TEST_TGT)
@echo
@echo "Specify, e.g., CONFIGS=\"CONFIG_MEM_STATS SSM_DEBUG\" to define additional compilation flags"
.PHONY: $(PHONY)