-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMakefile
258 lines (201 loc) · 7.24 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
###############################################################################
# File: Makefile
#
# Copyright 2019 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Other Rights Reserved.
#
# This software was created at NASA's Goddard Space Flight Center.
# This software is governed by the NASA Open Source Agreement and may be
# used, distributed and modified only pursuant to the terms of that
# agreement.
#
# Maintainer(s):
# Joe-Paul Swinski, Code 582 NASA GSFC
#
# Notes:
# 1. Most settings used to build the library can be overridden in the config.mk
# file. To create a custom build of this library, copy and edit your own
# config.mk file and then issue the following commands to build the library:
#
# make CONFIG=config.mk
#
# 2. In order to use clang instead of gcc, set the CC and AR variables.
# For example, if you wanted to run AddressSanitizer via clang, issue the following
# commands to build the library:
#
# make CC=clang USER_COPT=-fsanitize=address USER_LOPT=-fsanitize=address
# sudo make CC=clang USER_COPT=-fsanitize=address USER_LOPT=-fsanitize=address install
#
# 3. Running the clang static code analysis is accomplished by preceding whichever
# build command you use with "scan-build". For example, a nominal scan is performed by:
#
# scan-build make
#
# Once the scan is complete, the use of scan-view prompted by the program on error, requires
# python2.7 to be the default python interpreter. Check the system path if scan-view reports
# a SyntaxError when it tries to run.
#
# 4. The libabi.version script controls the export of any symbols in the library. By convention
# anything that starts with bplib_ is exported. Run the following command to verify which
# symbols are available to a linking application:
#
# nm -CD /usr/local/lib/libbp.so | grep " T "
#
##############################################################################
## DEFINITIONS
# bplib repository root directory
ROOT := .
# bplib repository application interface include directory
API := $(ROOT)/inc
# library objects
APP_OBJ := bplib.o
# common objects
APP_OBJ += crc.o
APP_OBJ += rb_tree.o
APP_OBJ += rh_hash.o
APP_OBJ += cbuf.o
APP_OBJ += lrc.o
# version 6 objects
APP_OBJ += v6.o
APP_OBJ += bib.o
APP_OBJ += cteb.o
APP_OBJ += pay.o
APP_OBJ += pri.o
APP_OBJ += dacs.o
APP_OBJ += sdnv.o
# storage service objects
APP_OBJ += file.o
APP_OBJ += ram.o
APP_OBJ += flash.o
APP_OBJ += flash_sim.o
# search path for application objects (note this is a make system variable)
VPATH := $(ROOT)/lib
VPATH += $(ROOT)/common
VPATH += $(ROOT)/v6
VPATH += $(ROOT)/os
VPATH += $(ROOT)/store
VPATH += $(ROOT)/unittest
# compiler options for search path for include headers (in form of -I_header_)
INCLUDES := -I$(ROOT)/inc
INCLUDES += -I$(ROOT)/lib
INCLUDES += -I$(ROOT)/common
INCLUDES += -I$(ROOT)/v6
INCLUDES += -I$(ROOT)/os
INCLUDES += -I$(ROOT)/store
INCLUDES += -I$(ROOT)/unittest
##############################################################################
## CUSTOMIZATION
# definitions needed by the application (used to declare things like -D_APP_NAME_)
APP_DEFS ?= $(USER_DEFS)
# compiler options needed by the application
APP_COPT ?= $(USER_COPT)
# linker options needed by the application
APP_LOPT ?= $(USER_LOPT)
# location to install bplib
PREFIX ?= /usr/local
# configuration makefile, if not set then uses default
CONFIG ?= posix.mk
# include configuration makefile to override and add to above definitions
include $(CONFIG)
# unit test objects #
APP_OBJ += unittest.o
APP_OBJ += ut_assert.o
ifeq ($(BUILD_UNITTESTS),1)
APP_OBJ += ut_crc.o
APP_OBJ += ut_rb_tree.o
APP_OBJ += ut_rh_hash.o
APP_OBJ += ut_flash.o
endif
###############################################################################
## COMPILER/LINKER CONFIGURATION
TGTLIB := bp
TGTVER := $(shell cat version.txt)
LIBDIR := $(PREFIX)/lib
INCDIR := $(PREFIX)/include/$(TGTLIB)
BLDDIR := build
COPT := -g -Wall -Wextra -D'LIBID="$(TGTVER)"' $(INCLUDES) $(APP_DEFS)
COPT += -DLIBPATH=\"$(LIBDIR)\"
COPT += -DINCPATH=\"$(INCDIR)\"
COPT += -Wshadow
COPT += -pthread
COPT += -fPIC # position independent code needed for shared library
LOPT := -lrt
LOPT += -lpthread
ALL_OBJ := $(addprefix $(BLDDIR)/, $(APP_OBJ))
ALL_COPT := $(COPT) $(APP_COPT)
ALL_LOPT := $(LOPT) $(APP_LOPT)
###############################################################################
## COMPILER RULES
$(BLDDIR)/%.o: %.c
$(CC) -c $(ALL_COPT) -o $@ $<
##############################################################################
## TARGET RULES
all: clean lib
dev: clean lib bindings example
lib: static-lib shared-lib
static-lib: $(BLDDIR) $(ALL_OBJ)
$(AR) crs $(BLDDIR)/lib$(TGTLIB).a $(ALL_OBJ)
shared-lib: $(BLDDIR) $(ALL_OBJ)
$(CC) $(ALL_OBJ) $(ALL_LOPT) -shared -Wl,--version-script=libabi.version -o $(BLDDIR)/lib$(TGTLIB).so.$(TGTVER)
ln -sf lib$(TGTLIB).so.$(TGTVER) $(BLDDIR)/lib$(TGTLIB).so
bindings:
make -C binding/lua
example:
make -C app
install: install-lib
install-dev: install-lib install-bindings install-example
install-lib: install-headers install-static install-shared
install-headers: $(INCDIR)
cp $(foreach element,$(API),$(subst -I,,$(element)/*.h)) $(INCDIR)
chmod 644 $(INCDIR)/*
install-static: $(PREFIX) $(LIBDIR)
cp $(BLDDIR)/lib$(TGTLIB).a $(LIBDIR)
chmod 644 $(LIBDIR)/lib$(TGTLIB).a
install-shared: $(PREFIX) $(LIBDIR)
cp $(BLDDIR)/lib$(TGTLIB).so.$(TGTVER) $(LIBDIR)
ln -sf $(LIBDIR)/lib$(TGTLIB).so.$(TGTVER) $(LIBDIR)/lib$(TGTLIB).so
ldconfig
chmod 644 $(LIBDIR)/lib$(TGTLIB).so
chmod 644 $(LIBDIR)/lib$(TGTLIB).so.$(TGTVER)
install-bindings:
make -C binding/lua install
install-example:
make -C app install
$(BLDDIR):
-mkdir -p $(BLDDIR)
$(PREFIX):
-mkdir -p $(PREFIX)
$(LIBDIR):
-mkdir -p $(LIBDIR)
$(INCDIR):
-mkdir -p $(INCDIR)
clean ::
-rm -Rf $(BLDDIR)
##############################################################################
## TEST RULES
luaexec = lua5.3
testcase ?= binding/lua/test/test_runner.lua
testmem:
valgrind --leak-check=full --track-origins=yes --track-fds=yes $(luaexec) $(testcase)
testcpu:
valgrind --tool=callgrind $(luaexec) $(testcase)
# kcachegrind callgrind.out.<pid>
testheap:
valgrind --tool=massif --time-unit=B --pages-as-heap=yes $(luaexec) $(testcase)
# ms_print massif.out.<pid>
testcov:
lcov -c --directory build --output-file build/coverage.info
genhtml build/coverage.info --output-directory build/coverage_html
# firefox build/coverage_html/index.html
##############################################################################
## STATIC ANALYSIS RULES
CHECK_OPT = --enable=all --inconclusive --error-exitcode=1 -q
CHECK_OPT += --suppress=unusedFunction --suppress=missingInclude
CHECK_OPT += --suppress=objectIndex:common/crc.c
CHECK_OPT += --suppress=redundantAssignment:v6/dacs.c
CHECK_OPT += --suppress=memleak:os/cfe.c
CHECK_OPT += --suppress=memleak:os/posix.c
check:
cppcheck $(ROOT) $(CHECK_OPT) $(INCLUDES) $(APP_DEFS)
# end of file