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 += $(OSCORE_NVM_SUPPORT) 82EXTENDED_CFLAGS += $(CRYPTO_ENGINE) 83EXTENDED_CFLAGS += $(DUNIT_TEST) 84 85# Unit tests require NVM support regardless of user settings 86ifeq ($(findstring UNIT_TEST,$(DUNIT_TEST)),UNIT_TEST) 87EXTENDED_CFLAGS += -DOSCORE_NVM_SUPPORT 88endif 89 90#add include paths 91EXTENDED_CFLAGS += $(C_INCLUDES) 92 93#generate debug symbols 94EXTENDED_CFLAGS += -g -gdwarf-2 95 96# Generate dependency information 97EXTENDED_CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" 98 99 100 101#GCC warning flags 102ifeq ($(findstring cc,$(CC)),cc) 103EXTENDED_CFLAGS += -Waddress 104EXTENDED_CFLAGS += -Waggregate-return 105EXTENDED_CFLAGS += -Wformat-nonliteral 106EXTENDED_CFLAGS += -Wformat-security 107EXTENDED_CFLAGS += -Wformat 108EXTENDED_CFLAGS += -Winit-self 109EXTENDED_CFLAGS += -Wmissing-include-dirs 110EXTENDED_CFLAGS += -Wno-multichar 111EXTENDED_CFLAGS += -Wno-parentheses 112EXTENDED_CFLAGS += -Wno-type-limits 113EXTENDED_CFLAGS += -Wno-unused-parameter 114EXTENDED_CFLAGS += -Wunreachable-code 115EXTENDED_CFLAGS += -Wwrite-strings 116EXTENDED_CFLAGS += -Wpointer-arith 117EXTENDED_CFLAGS += -Wall 118EXTENDED_CFLAGS += -Wextra 119EXTENDED_CFLAGS += -Wcast-qual 120EXTENDED_CFLAGS += -Wstack-usage=9000 121EXTENDED_CFLAGS += -Wconversion 122EXTENDED_CFLAGS += -Wpedantic 123#EXTENDED_CFLAGS += -Werror 124 125#Clang warning flahs 126else ifeq ($(findstring clang,$(CC)),clang) 127EXTENDED_CFLAGS += -Wcast-qual 128EXTENDED_CFLAGS += -Wconversion 129EXTENDED_CFLAGS += -Wexit-time-destructors 130EXTENDED_CFLAGS += -Wglobal-constructors 131EXTENDED_CFLAGS += -Wmissing-noreturn 132EXTENDED_CFLAGS += -Wmissing-prototypes 133EXTENDED_CFLAGS += -Wno-missing-braces 134EXTENDED_CFLAGS += -Wold-style-cast 135EXTENDED_CFLAGS += -Wshadow 136EXTENDED_CFLAGS += -Wweak-vtables 137EXTENDED_CFLAGS += -Wall 138EXTENDED_CFLAGS += -Wextra 139EXTENDED_CFLAGS += -Wpedantic 140EXTENDED_CFLAGS += -Wstack-exhausted 141EXTENDED_CFLAGS += -Wconversion 142#EXTENDED_CFLAGS += -Werror 143endif 144 145# use AddressSanitizer to find memory bugs 146# comment this out for better speed 147#EXTENDED_CFLAGS += -fsanitize=address -fno-omit-frame-pointer 148#CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer 149#LDFLAGS += -fsanitize=address -static-libasan 150 151$(info EXTENDED_CFLAGS are $(EXTENDED_CFLAGS)) 152################################################################################ 153# build the library 154################################################################################ 155OBJ = $(addprefix $(DIR)/,$(notdir $(C_SOURCES:.c=.o))) 156#$(info \n OBJ is $(OBJ)) 157 158 159$(DIR)/$(LIB_NAME): $(OBJ) 160 @echo "[Link (Static)]" 161 @$(AR) -rcs $@ $^ 162 163$(DIR)/%.o: %.c Makefile makefile_config.mk 164 @echo [Compile] $< 165 @$(CC) -c $(EXTENDED_CFLAGS) $< -o $@ 166 167clean: 168 rm -fR $(DIR)