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 10# in order to rebuild the uoscore-uedhoc.a and responder application call: 11# make oscore_edhoc; make 12 13include ../../../makefile_config.mk 14 15# toolchain 16CXX ?= g++ 17CC ?= gcc 18SZ ?= size 19MAKE ?= make 20 21# target 22TARGET = responder 23 24 25# build path 26BUILD_DIR = build 27 28# libusocore-uedhoc path 29USOCORE_UEDHOC_PATH = ../../../ 30USOCORE_UEDHOC_BUILD_PATH = $(USOCORE_UEDHOC_PATH)build 31 32ifeq ($(ARCH_32_ONLY), 1) 33# build for 32 bit x68 34# export the varible so that it is availbale in the uoscore-uedhoc Makefile 35ARCH = -m32 36export ARCH 37endif 38 39# debug build? 40DEBUG = 1 41 42# optimization 43OPT = -Og 44 45# CPP sources 46CPP_SOURCES += src/main.cpp 47CPP_SOURCES += ../../../externals/cantcoap/cantcoap.cpp 48 49# C sources 50# rename files avaible with the same name in diferent libraries 51# todo clean up this 52$(shell mv ../../../externals/compact25519/src/c25519/sha512.c ../../../externals/compact25519/src/c25519/_sha512.c ) 53$(shell mv ../../../externals/tinycrypt/lib/source/sha256.c ../../../externals/tinycrypt/lib/source/tc_sha256.c ) 54 55C_SOURCES += src/_entropy.c 56C_SOURCES += $(wildcard ../../common/*.c) 57C_SOURCES += $(wildcard ../../../externals/zcbor/src/*.c) 58 59# Crypto engine dependent source files 60ifeq ($(findstring COMPACT25519,$(CRYPTO_ENGINE)),COMPACT25519) 61C_SOURCES += $(wildcard ../../../externals/compact25519/src/c25519/*.c) 62C_SOURCES += $(wildcard ../../../externals/compact25519/src/*.c) 63endif 64 65ifeq ($(findstring TINYCRYPT,$(CRYPTO_ENGINE)),TINYCRYPT) 66C_SOURCES += $(wildcard ../../../externals/tinycrypt/lib/source/*.c) 67endif 68 69ifeq ($(findstring MBEDTLS,$(CRYPTO_ENGINE)),MBEDTLS) 70C_SOURCES += $(wildcard ../../../externals/mbedtls/library/*.c) 71endif 72 73# C includes 74C_INCLUDES += -I../../../inc/ 75C_INCLUDES += -I../../common/ 76C_INCLUDES += -I../../../test_vectors/ 77C_INCLUDES += -I../../../externals/cantcoap/ 78C_INCLUDES += -I../../../externals/zcbor/include 79 80# Crypto engine dependent includes 81ifeq ($(findstring COMPACT25519,$(CRYPTO_ENGINE)),COMPACT25519) 82C_INCLUDES += -I../../../externals/compact25519/src/c25519/ 83C_INCLUDES += -I../../../externals/compact25519/src/ 84endif 85 86ifeq ($(findstring TINYCRYPT,$(CRYPTO_ENGINE)),TINYCRYPT) 87C_INCLUDES += -I../../../externals/tinycrypt/lib/include 88endif 89 90ifeq ($(findstring MBEDTLS,$(CRYPTO_ENGINE)),MBEDTLS) 91C_INCLUDES += -I../../../externals/mbedtls/library 92C_INCLUDES += -I../../../externals/mbedtls/include 93C_INCLUDES += -I../../../externals/mbedtls/include/mbedtls 94C_INCLUDES += -I../../../externals/mbedtls/include/psa 95endif 96 97# C defines 98# make PRINT_ARRAY macro usable in the main file 99C_DEFS += -DDEBUG_PRINT 100 101C_DEFS += $(ENV_DEFS) 102 103# Linked libraries 104LD_LIBRARY_PATH += -L$(USOCORE_UEDHOC_BUILD_PATH) 105 106LDFLAGS += $(LD_LIBRARY_PATH) 107LDFLAGS += -luoscore-uedhoc 108LDFLAGS += -lstdc++ 109LDFLAGS += $(ARCH) 110########################################## 111# CFLAGS 112########################################## 113#general c flags 114CFLAGS += \ 115 $(ARCH) \ 116 $(C_DEFS) \ 117 $(C_INCLUDES) \ 118 $(OPT) \ 119 -Wall \ 120 -fstack-usage 121CXXFLAGS += $(ARCH) $(C_DEFS) $(C_INCLUDES) $(OPT) 122 123# have dubug information 124ifeq ($(DEBUG), 1) 125CFLAGS += -g -gdwarf-2 126CXXFLAGS += -Wall -g 127endif 128 129# Generate dependency information 130CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" 131CXXFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" 132 133# required for gddl-gen library 134CFLAGS += -DZCBOR_CANONICAL 135 136# use linux sockets 137CFLAGS += -DLINUX_SOCKETS 138CXXFLAGS += -DLINUX_SOCKETS 139 140# use AddressSanitizer to find memory bugs 141# comment this out for better speed 142#CFLAGS += -fsanitize=address -fno-omit-frame-pointer 143#CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer 144#LDFLAGS += -fsanitize=address -static-libasan 145 146########################################### 147# default action: build all 148########################################### 149#list of objects from c files 150OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) 151vpath %.c $(sort $(dir $(C_SOURCES))) 152 153# list of objects from c++ file 154OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cpp=.o))) 155vpath %.cpp $(sort $(dir $(CPP_SOURCES))) 156 157USOCORE_UEDHOC_OBJ = $(wildcard $(USOCORE_UEDHOC_PATH)/*.o) 158 159$(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR) 160 $(CXX) -c $(CXXFLAGS) $< -o $@ 161 162$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) 163 $(CC) -c $(CFLAGS) $< -o $@ 164 165$(BUILD_DIR)/$(TARGET): $(OBJECTS) Makefile $(USOCORE_UEDHOC_PATH)/Makefile 166 $(MAKE) -C $(USOCORE_UEDHOC_PATH) 167 $(CXX) $(OBJECTS) $(LDFLAGS) -o $@ 168 $(SZ) $@ 169 170$(BUILD_DIR): 171 mkdir $@ 172 173 174 175oscore_edhoc: 176 $(MAKE) -C $(USOCORE_UEDHOC_PATH) 177 178clean_oscore_edhoc: 179 $(MAKE) -C $(USOCORE_UEDHOC_PATH) clean 180 181clean: 182 -rm -fR $(BUILD_DIR) 183 $(MAKE) -C $(USOCORE_UEDHOC_PATH) clean 184 185 186####################################### 187# dependencies 188####################################### 189-include $(wildcard $(BUILD_DIR)/*.d) 190 191 192 193 194 195 196 197