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