# Copyright (c) 2021 Fraunhofer AISEC. See the COPYRIGHT # file at the top-level directory of this distribution. # Licensed under the Apache License, Version 2.0 or the MIT license # , at your # option. This file may not be copied, modified, or distributed # except according to those terms. include ../../../makefile_config.mk ROOT_DIR := ../../.. # toolchain CXX ?= g++ CC ?= gcc SZ ?= size MAKE ?= make # target TARGET = responder # build path BUILD_DIR = build # libusocore-uedhoc path USOCORE_UEDHOC_PATH = ../../../ USOCORE_UEDHOC_BUILD_PATH = $(USOCORE_UEDHOC_PATH)build ifeq ($(ARCH_32_ONLY), 1) # build for 32 bit x68 # export the variable so that it is available in the uoscore-uedhoc Makefile ARCH = -m32 export ARCH endif # debug build? DEBUG = 1 # optimization OPT = -Og # CPP sources CPP_SOURCES += src/main.cpp CPP_SOURCES += ../../../externals/cantcoap/cantcoap.cpp # C sources # rename files available with the same name in different libraries # todo clean up this $(shell mv ../../../externals/compact25519/src/c25519/sha512.c ../../../externals/compact25519/src/c25519/_sha512.c ) $(shell mv ../../../externals/tinycrypt/lib/source/sha256.c ../../../externals/tinycrypt/lib/source/tc_sha256.c ) C_SOURCES += src/_entropy.c C_SOURCES += $(wildcard ../../common/*.c) C_SOURCES += $(wildcard ../../../externals/zcbor/src/*.c) C_SOURCES += $(wildcard ../../../test_vectors/*.c) # Crypto engine dependent source files ifeq ($(findstring COMPACT25519,$(CRYPTO_ENGINE)),COMPACT25519) C_SOURCES += $(wildcard ../../../externals/compact25519/src/c25519/*.c) C_SOURCES += $(wildcard ../../../externals/compact25519/src/*.c) endif ifeq ($(findstring TINYCRYPT,$(CRYPTO_ENGINE)),TINYCRYPT) C_SOURCES += $(wildcard ../../../externals/tinycrypt/lib/source/*.c) endif ifeq ($(findstring MBEDTLS,$(CRYPTO_ENGINE)),MBEDTLS) C_SOURCES += $(wildcard ../../../externals/mbedtls/library/*.c) endif # C includes C_INCLUDES += -I../../../inc/ C_INCLUDES += -I../../common/ C_INCLUDES += -I../../../test_vectors/ C_INCLUDES += -I../../../externals/cantcoap/ C_INCLUDES += -I../../../externals/zcbor/include # Crypto engine dependent includes ifeq ($(findstring COMPACT25519,$(CRYPTO_ENGINE)),COMPACT25519) C_INCLUDES += -I../../../externals/compact25519/src/c25519/ C_INCLUDES += -I../../../externals/compact25519/src/ endif ifeq ($(findstring TINYCRYPT,$(CRYPTO_ENGINE)),TINYCRYPT) C_INCLUDES += -I../../../externals/tinycrypt/lib/include endif ifeq ($(findstring MBEDTLS,$(CRYPTO_ENGINE)),MBEDTLS) C_INCLUDES += -I../../../externals/mbedtls/library C_INCLUDES += -I../../../externals/mbedtls/include C_INCLUDES += -I../../../externals/mbedtls/include/mbedtls C_INCLUDES += -I../../../externals/mbedtls/include/psa endif # C defines # make PRINT_ARRAY macro usable in the main file C_DEFS += -DDEBUG_PRINT C_DEFS += $(ENV_DEFS) # Linked libraries LD_LIBRARY_PATH += -L$(USOCORE_UEDHOC_BUILD_PATH) LDFLAGS += $(LD_LIBRARY_PATH) LDFLAGS += -luoscore-uedhoc LDFLAGS += -lstdc++ LDFLAGS += $(ARCH) ########################################## # CFLAGS ########################################## #general c flags CFLAGS += \ $(ARCH) \ $(C_DEFS) \ $(C_INCLUDES) \ $(OPT) \ -Wall \ -fstack-usage CXXFLAGS += $(ARCH) $(C_DEFS) $(C_INCLUDES) $(OPT) # have dubug information ifeq ($(DEBUG), 1) CFLAGS += -g -gdwarf-2 CXXFLAGS += -Wall -g endif # Generate dependency information CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" CXXFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" # required for gddl-gen library CFLAGS += -DZCBOR_CANONICAL #CFLAGS += -DZCBOR_VERBOSE # use linux sockets CFLAGS += -DLINUX_SOCKETS CXXFLAGS += -DLINUX_SOCKETS # use AddressSanitizer to find memory bugs # comment this out for better speed #CFLAGS += -fsanitize=address -fno-omit-frame-pointer #CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer #LDFLAGS += -fsanitize=address -static-libasan ########################################### # default action: build all ########################################### #list of objects from c files OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) vpath %.c $(sort $(dir $(C_SOURCES))) # list of objects from c++ file OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cpp=.o))) vpath %.cpp $(sort $(dir $(CPP_SOURCES))) USOCORE_UEDHOC_OBJ = $(wildcard $(USOCORE_UEDHOC_PATH)/*.o) $(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR) $(CXX) -c $(CXXFLAGS) $< -o $@ $(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) $(CC) -c $(CFLAGS) $< -o $@ $(BUILD_DIR)/$(TARGET): $(OBJECTS) Makefile $(USOCORE_UEDHOC_PATH)/Makefile $(MAKE) -C $(USOCORE_UEDHOC_PATH) $(CXX) $(OBJECTS) $(LDFLAGS) -o $@ $(SZ) $@ $(BUILD_DIR): mkdir $@ oscore_edhoc: $(MAKE) -C $(USOCORE_UEDHOC_PATH) clean_oscore_edhoc: $(MAKE) -C $(USOCORE_UEDHOC_PATH) clean clean: -rm -fR $(BUILD_DIR) $(MAKE) -C $(USOCORE_UEDHOC_PATH) clean ####################################### # dependencies ####################################### -include $(wildcard $(BUILD_DIR)/*.d)