-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
150 lines (122 loc) · 4.06 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
# SPDX-License-Identifier: BSD-2-Clause
# Copyright 2023 IBM Corp.
CC = gcc
AR = ar
LD = gcc
_CFLAGS = -Wall -Werror -MMD -ggdb3 -fPIC
CFLAGS =
LDFLAGS =
SRC_DIR = ./src
OBJ_DIR = ./obj
LIB_DIR = ./lib
TEST_DIR = ./test
INCLUDE = -I./include -I./ -I./external
DEBUG ?= 0
ifeq ($(strip $(DEBUG)), 1)
_CFLAGS += -g
else
_LDFLAGS += -s
endif
# Handle coverage generator preference, only supports lcov/gcovr via the Makefile
# consider using the `make coverage` target and manually running your if not supported
ifeq ($(strip $(PREFER_LCOV)), 1)
COVERER = lcov
else ifeq ($(strip $(PREFER_GCOVR)), 1)
COVERER = gcovr
else
# Default to preferring gcovr if it exists, fallback to lcov if not
ifneq ($(strip $(shell which gcovr)),)
COVERER = gcovr
else ifneq ($(strip $(shell which lcov)),)
COVERER = lcov
else
endif
endif
SRCS = esl.c \
authentication_2.c \
update.c \
pseries.c \
crypto_util.c \
log.c \
phyp.c
#By default, build with openssl as crypto library
CRYPTO_LIB = openssl
CRYPTO_LIB_OPTIONS = openssl
ifeq ($(filter $(CRYPTO_LIB),$(CRYPTO_LIB_OPTIONS)),)
$(error CRYPTO_LIB must be set to one of: $(CRYPTO_LIB_OPTIONS))
endif
ifeq ($(CRYPTO_LIB), openssl)
SRCS += crypto_openssl.c
CRYPTO_ARG = OPENSSL=1
_CFLAGS += -DSECVAR_CRYPTO_OPENSSL
endif
SRCS := $(addprefix $(SRC_DIR)/,$(SRCS))
OBJS = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRCS))
COV_OBJS = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.gcov.o,$(SRCS))
_CFLAGS += $(CFLAGS) $(INCLUDE)
_LDFLAGS += $(LDFLAGS)
all: $(LIB_DIR)/libstb-secvar-$(CRYPTO_LIB).a $(LIB_DIR)/libstb-secvar-$(CRYPTO_LIB).so
-include $(OBJS:.o=.d)
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(OBJ_DIR)
$(CC) $(_CFLAGS) $< -o $@ -c
# Coverage objects
$(OBJ_DIR)/%.gcov.o: $(SRC_DIR)/%.c
@mkdir -p $(OBJ_DIR)
$(CC) $(_CFLAGS) -Wall -Werror -g -O0 --coverage -DNO_PRLOG $< -o $@ -c
$(LIB_DIR)/libstb-secvar-$(CRYPTO_LIB).a: $(OBJS)
@mkdir -p $(LIB_DIR)
$(AR) -rcs $@ $^ $(_LDFLAGS)
$(LIB_DIR)/libstb-secvar-$(CRYPTO_LIB).gcov.a: $(COV_OBJS)
@mkdir -p $(LIB_DIR)
$(AR) -rcs $@ $^ $(_LDFLAGS)
$(LIB_DIR)/libstb-secvar-$(CRYPTO_LIB).so: $(OBJS)
@mkdir -p $(LIB_DIR)
$(LD) $(_LDFLAGS) -shared $^ -o $@
tests: $(LIB_DIR)/libstb-secvar-$(CRYPTO_LIB).a
@$(MAKE) -C $(TEST_DIR) $(CRYPTO_ARG)
check: $(LIB_DIR)/libstb-secvar-$(CRYPTO_LIB).a
@$(MAKE) -C $(TEST_DIR) $(CRYPTO_ARG) check
memcheck: $(LIB_DIR)/libstb-secvar-$(CRYPTO_LIB).a
@$(MAKE) -C $(TEST_DIR) memcheck
coverage: $(LIB_DIR)/libstb-secvar-$(CRYPTO_LIB).gcov.a
@$(MAKE) -C $(TEST_DIR) coverage
coverage-report: coverage
ifeq ($(COVERER),)
$(error Neither lcov nor gcovr appear to be installed, please install one of them to use this target)
endif
ifeq ($(PERSIST_REPORT),)
rm -rf report
endif
@mkdir -p report
ifeq ($(COVERER),lcov)
@echo "Using lcov to generate report"
@lcov --no-external --capture --directory . --output-file report/test.info
@genhtml report/test.info --legend --output-directory=report
else ifeq ($(COVERER),gcovr)
@echo "Using gcovr to generate report"
@gcovr --html-details report/index.html --delete
endif
TEST_SRCS = $(wildcard test/*.c)
# variableScope: avoid reducing variable scope to maintain C compatibility
# missingInclude: TODO: ideally rework all includes to make this unnecessary
# unusedFunction: not all functions provided in the library might be used
# TODO: should be removed when test coverage improves
CPPCHECK_ARGS = --enable=all --force \
--suppress=variableScope \
--suppress=missingInclude \
--suppress=unusedFunction \
--error-exitcode=1 -q
cppcheck:
cppcheck $(CPPCHECK_ARGS) \
-D__BYTE_ORDER__=__LITTLE_ENDIAN__ \
$(INCLUDE) $(SRCS) $(TEST_SRCS)
cppcheck-be:
cppcheck $(CPPCHECK_ARGS) \
-D__BYTE_ORDER__=__BIG_ENDIAN__ \
$(INCLUDE) $(SRCS) $(TEST_SRCS)
clean:
@$(MAKE) -C $(TEST_DIR) clean
rm -rf $(OBJ_DIR) $(LIB_DIR)
rm -rf report/
.PHONY: all check cppcheck cppcheck-be clean tests coverage coverage-report