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