1# Copyright (c) 2021 Fraunhofer AISEC. See the COPYRIGHT
2# file at the top-level directory of this distribution.
3
4# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7# option. This file may not be copied, modified, or distributed
8# except according to those terms.
9
10LIB_NAME = libuoscore-uedhoc.a
11
12include makefile_config.mk
13
14$(info    CC is $(CC))
15# $(info    LIB_NAME is $(LIB_NAME))
16# $(info    PREFIX is $(PREFIX))
17# $(info    SOURCE_DIR is $(SOURCE_DIR))
18# $(info    BINARY_DIR is $(BINARY_DIR))
19# $(info    CC is $(CC))
20# $(info    CFLAGS is $(CFLAGS))
21# $(info    OPT is $(OPT))
22# $(info    CRYPTO_ENGINE is $(CRYPTO_ENGINE))
23################################################################################
24# Build directory
25PREFIX ?= build
26DIR = $(PREFIX)
27$(shell mkdir -p $(DIR))
28################################################################################
29# C Source files
30
31C_SOURCES += $(wildcard src/edhoc/*.c)
32C_SOURCES += $(wildcard src/oscore/*.c)
33C_SOURCES += $(wildcard src/common/*.c)
34C_SOURCES += $(wildcard src/cbor/*.c)
35
36
37#$(info    \n C_SOURCES is $(C_SOURCES))
38vpath %.c $(sort $(dir $(C_SOURCES)))
39
40################################################################################
41# libraries
42
43
44################################################################################
45# C includes
46C_INCLUDES += -Iinc
47
48# Crypto engine
49ifeq ($(findstring COMPACT25519,$(CRYPTO_ENGINE)),COMPACT25519)
50C_INCLUDES += -Iexternals/compact25519/src/c25519/
51C_INCLUDES += -Iexternals/compact25519/src/
52endif
53
54ifeq ($(findstring TINYCRYPT,$(CRYPTO_ENGINE)),TINYCRYPT)
55C_INCLUDES += -Iexternals/tinycrypt/lib/include
56endif
57
58ifeq ($(findstring MBEDTLS,$(CRYPTO_ENGINE)),MBEDTLS)
59C_INCLUDES += -Iexternals/mbedtls/library
60C_INCLUDES += -Iexternals/mbedtls/include
61C_INCLUDES += -Iexternals/mbedtls/include/mbedtls
62C_INCLUDES += -Iexternals/mbedtls/include/psa
63endif
64
65# CBOR engine
66ifeq ($(findstring ZCBOR,$(CBOR_ENGINE)),ZCBOR)
67C_INCLUDES += -Iexternals/zcbor/include
68endif
69
70################################################################################
71# CFLAGS
72################################################################################
73FILTERED_CFLAGS = -Os
74EXTENDED_CFLAGS = $(filter-out $(FILTERED_CFLAGS), $(CFLAGS))
75
76#add options form configuration file
77EXTENDED_CFLAGS += $(ARCH)
78EXTENDED_CFLAGS += $(OPT)
79EXTENDED_CFLAGS += $(DEBUG_PRINT)
80EXTENDED_CFLAGS += $(CBOR_ENGINE)
81EXTENDED_CFLAGS += $(CRYPTO_ENGINE)
82
83#add include paths
84EXTENDED_CFLAGS += $(C_INCLUDES)
85
86#generate debug symbols
87EXTENDED_CFLAGS += -g -gdwarf-2
88
89# Generate dependency information
90EXTENDED_CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
91
92
93
94#GCC warning flags
95ifeq ($(findstring cc,$(CC)),cc)
96EXTENDED_CFLAGS += -Waddress
97EXTENDED_CFLAGS += -Waggregate-return
98EXTENDED_CFLAGS += -Wformat-nonliteral
99EXTENDED_CFLAGS += -Wformat-security
100EXTENDED_CFLAGS += -Wformat
101EXTENDED_CFLAGS += -Winit-self
102EXTENDED_CFLAGS += -Wmissing-include-dirs
103EXTENDED_CFLAGS += -Wno-multichar
104EXTENDED_CFLAGS += -Wno-parentheses
105EXTENDED_CFLAGS += -Wno-type-limits
106EXTENDED_CFLAGS += -Wno-unused-parameter
107EXTENDED_CFLAGS += -Wunreachable-code
108EXTENDED_CFLAGS += -Wwrite-strings
109EXTENDED_CFLAGS += -Wpointer-arith
110EXTENDED_CFLAGS += -Wall
111EXTENDED_CFLAGS += -Wextra
112EXTENDED_CFLAGS += -Wcast-qual
113EXTENDED_CFLAGS += -Wstack-usage=7000
114EXTENDED_CFLAGS += -Wconversion
115EXTENDED_CFLAGS += -Wpedantic
116#EXTENDED_CFLAGS += -Werror
117
118#Clang warning flahs
119else ifeq ($(findstring clang,$(CC)),clang)
120EXTENDED_CFLAGS += -Wcast-qual
121EXTENDED_CFLAGS += -Wconversion
122EXTENDED_CFLAGS += -Wexit-time-destructors
123EXTENDED_CFLAGS += -Wglobal-constructors
124EXTENDED_CFLAGS += -Wmissing-noreturn
125EXTENDED_CFLAGS += -Wmissing-prototypes
126EXTENDED_CFLAGS += -Wno-missing-braces
127EXTENDED_CFLAGS += -Wold-style-cast
128EXTENDED_CFLAGS += -Wshadow
129EXTENDED_CFLAGS += -Wweak-vtables
130EXTENDED_CFLAGS += -Wall
131EXTENDED_CFLAGS += -Wextra
132EXTENDED_CFLAGS += -Wpedantic
133EXTENDED_CFLAGS += -Wstack-exhausted
134EXTENDED_CFLAGS += -Wconversion
135#EXTENDED_CFLAGS += -Werror
136endif
137
138# use AddressSanitizer to find memory bugs
139# comment this out for better speed
140#EXTENDED_CFLAGS += -fsanitize=address -fno-omit-frame-pointer
141#CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer
142#LDFLAGS += -fsanitize=address -static-libasan
143
144$(info    EXTENDED_CFLAGS are $(EXTENDED_CFLAGS))
145################################################################################
146# build the library
147################################################################################
148OBJ = $(addprefix $(DIR)/,$(notdir $(C_SOURCES:.c=.o)))
149#$(info    \n OBJ is $(OBJ))
150
151
152$(DIR)/$(LIB_NAME): $(OBJ)
153	@echo "[Link (Static)]"
154	@$(AR) -rcs $@ $^
155
156$(DIR)/%.o: %.c Makefile makefile_config.mk
157	@echo [Compile] $<
158	@$(CC) -c $(EXTENDED_CFLAGS) $< -o $@
159
160clean:
161	rm -fR $(DIR)