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