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 10include ../../../makefile_config.mk 11ROOT_DIR := ../../.. 12 13# toolchain 14CXX ?= g++ 15CC ?= gcc 16SZ ?= size 17MAKE ?= make 18 19# target 20TARGET = responder 21 22 23# build path 24BUILD_DIR = build 25 26# libusocore-uedhoc path 27USOCORE_UEDHOC_PATH = ../../../ 28USOCORE_UEDHOC_BUILD_PATH = $(USOCORE_UEDHOC_PATH)build 29 30ifeq ($(ARCH_32_ONLY), 1) 31# build for 32 bit x68 32# export the variable so that it is available in the uoscore-uedhoc Makefile 33ARCH = -m32 34export ARCH 35endif 36 37# debug build? 38DEBUG = 1 39 40# optimization 41OPT = -Og 42 43# CPP sources 44CPP_SOURCES += src/main.cpp 45CPP_SOURCES += ../../../externals/cantcoap/cantcoap.cpp 46 47# C sources 48# rename files available with the same name in different libraries 49# todo clean up this 50$(shell mv ../../../externals/compact25519/src/c25519/sha512.c ../../../externals/compact25519/src/c25519/_sha512.c ) 51$(shell mv ../../../externals/tinycrypt/lib/source/sha256.c ../../../externals/tinycrypt/lib/source/tc_sha256.c ) 52 53C_SOURCES += src/_entropy.c 54C_SOURCES += $(wildcard ../../common/*.c) 55C_SOURCES += $(wildcard ../../../externals/zcbor/src/*.c) 56C_SOURCES += $(wildcard ../../../test_vectors/*.c) 57 58# Crypto engine dependent source files 59ifeq ($(findstring COMPACT25519,$(CRYPTO_ENGINE)),COMPACT25519) 60C_SOURCES += $(wildcard ../../../externals/compact25519/src/c25519/*.c) 61C_SOURCES += $(wildcard ../../../externals/compact25519/src/*.c) 62endif 63 64ifeq ($(findstring TINYCRYPT,$(CRYPTO_ENGINE)),TINYCRYPT) 65C_SOURCES += $(wildcard ../../../externals/tinycrypt/lib/source/*.c) 66endif 67 68ifeq ($(findstring MBEDTLS,$(CRYPTO_ENGINE)),MBEDTLS) 69C_SOURCES += $(wildcard ../../../externals/mbedtls/library/*.c) 70endif 71 72# C includes 73C_INCLUDES += -I../../../inc/ 74C_INCLUDES += -I../../common/ 75C_INCLUDES += -I../../../test_vectors/ 76C_INCLUDES += -I../../../externals/cantcoap/ 77C_INCLUDES += -I../../../externals/zcbor/include 78 79# Crypto engine dependent includes 80ifeq ($(findstring COMPACT25519,$(CRYPTO_ENGINE)),COMPACT25519) 81C_INCLUDES += -I../../../externals/compact25519/src/c25519/ 82C_INCLUDES += -I../../../externals/compact25519/src/ 83endif 84 85ifeq ($(findstring TINYCRYPT,$(CRYPTO_ENGINE)),TINYCRYPT) 86C_INCLUDES += -I../../../externals/tinycrypt/lib/include 87endif 88 89ifeq ($(findstring MBEDTLS,$(CRYPTO_ENGINE)),MBEDTLS) 90C_INCLUDES += -I../../../externals/mbedtls/library 91C_INCLUDES += -I../../../externals/mbedtls/include 92C_INCLUDES += -I../../../externals/mbedtls/include/mbedtls 93C_INCLUDES += -I../../../externals/mbedtls/include/psa 94endif 95 96# C defines 97# make PRINT_ARRAY macro usable in the main file 98C_DEFS += -DDEBUG_PRINT 99 100C_DEFS += $(ENV_DEFS) 101 102# Linked libraries 103LD_LIBRARY_PATH += -L$(USOCORE_UEDHOC_BUILD_PATH) 104 105LDFLAGS += $(LD_LIBRARY_PATH) 106LDFLAGS += -luoscore-uedhoc 107LDFLAGS += -lstdc++ 108LDFLAGS += $(ARCH) 109########################################## 110# CFLAGS 111########################################## 112#general c flags 113CFLAGS += \ 114 $(ARCH) \ 115 $(C_DEFS) \ 116 $(C_INCLUDES) \ 117 $(OPT) \ 118 -Wall \ 119 -fstack-usage 120CXXFLAGS += $(ARCH) $(C_DEFS) $(C_INCLUDES) $(OPT) 121 122# have dubug information 123ifeq ($(DEBUG), 1) 124CFLAGS += -g -gdwarf-2 125CXXFLAGS += -Wall -g 126endif 127 128# Generate dependency information 129CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" 130CXXFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" 131 132# required for gddl-gen library 133CFLAGS += -DZCBOR_CANONICAL 134#CFLAGS += -DZCBOR_VERBOSE 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