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)
57C_SOURCES += $(wildcard ../../../test_vectors/*.c)
58
59# Crypto engine dependent source files
60ifeq ($(findstring COMPACT25519,$(CRYPTO_ENGINE)),COMPACT25519)
61C_SOURCES += $(wildcard ../../../externals/compact25519/src/c25519/*.c)
62C_SOURCES += $(wildcard ../../../externals/compact25519/src/*.c)
63endif
64
65ifeq ($(findstring TINYCRYPT,$(CRYPTO_ENGINE)),TINYCRYPT)
66C_SOURCES += $(wildcard ../../../externals/tinycrypt/lib/source/*.c)
67endif
68
69ifeq ($(findstring MBEDTLS,$(CRYPTO_ENGINE)),MBEDTLS)
70C_SOURCES += $(wildcard ../../../externals/mbedtls/library/*.c)
71endif
72
73# C_SOURCES += $(wildcard ../../../externals/tinycrypt/lib/source/*.c)
74
75# C includes
76C_INCLUDES += -I../../../inc/
77C_INCLUDES += -I../../common/
78C_INCLUDES += -I../../../test_vectors/
79C_INCLUDES += -I../../../externals/cantcoap/
80C_INCLUDES += -I../../../externals/zcbor/include
81
82# Crypto engine dependent includes
83ifeq ($(findstring COMPACT25519,$(CRYPTO_ENGINE)),COMPACT25519)
84C_INCLUDES += -I../../../externals/compact25519/src/c25519/
85C_INCLUDES += -I../../../externals/compact25519/src/
86endif
87
88ifeq ($(findstring TINYCRYPT,$(CRYPTO_ENGINE)),TINYCRYPT)
89C_INCLUDES += -I../../../externals/tinycrypt/lib/include
90endif
91
92ifeq ($(findstring MBEDTLS,$(CRYPTO_ENGINE)),MBEDTLS)
93C_INCLUDES += -I../../../externals/mbedtls/library
94C_INCLUDES += -I../../../externals/mbedtls/include
95C_INCLUDES += -I../../../externals/mbedtls/include/mbedtls
96C_INCLUDES += -I../../../externals/mbedtls/include/psa
97endif
98
99# C defines
100# make PRINT_ARRAY macro usable in the main file
101C_DEFS += -DDEBUG_PRINT
102C_DEFS += -DLINUX_SOCKETS
103
104# Linked libraries
105LD_LIBRARY_PATH += -L$(USOCORE_UEDHOC_BUILD_PATH)
106
107LDFLAGS += $(LD_LIBRARY_PATH)
108LDFLAGS += -luoscore-uedhoc
109LDFLAGS += $(ARCH)
110##########################################
111# CFLAGS
112##########################################
113#general c flags
114CFLAGS +=  $(ARCH) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall
115CXXFLAGS +=  $(ARCH) $(C_DEFS) $(C_INCLUDES) $(OPT)
116
117# have dubug information
118ifeq ($(DEBUG), 1)
119CFLAGS += -g -gdwarf-2
120CXXFLAGS += -Wall -g
121endif
122
123# Generate dependency information
124CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
125CXXFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
126
127# required for gddl-gen library
128CFLAGS += -DZCBOR_CANONICAL
129
130
131
132# use AddressSanitizer to find memory bugs
133# comment this out for better speed
134#CFLAGS += -fsanitize=address -fno-omit-frame-pointer
135#CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer
136#LDFLAGS += -fsanitize=address -static-libasan
137
138###########################################
139# default action: build all
140###########################################
141#list of objects from c files
142OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
143vpath %.c $(sort $(dir $(C_SOURCES)))
144
145# list of objects from c++ file
146OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cpp=.o)))
147vpath %.cpp $(sort $(dir $(CPP_SOURCES)))
148
149USOCORE_UEDHOC_OBJ = $(wildcard $(USOCORE_UEDHOC_PATH)/*.o)
150
151
152
153$(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR)
154	$(CXX) -c $(CXXFLAGS) $< -o $@
155
156$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
157	$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
158
159$(BUILD_DIR)/$(TARGET): $(OBJECTS) Makefile $(USOCORE_UEDHOC_PATH)/Makefile $(USOCORE_UEDHOC_OBJ)
160	$(MAKE) -C $(USOCORE_UEDHOC_PATH)
161	$(CXX) $(OBJECTS)  $(LDFLAGS) -o $@
162	$(SZ) $@
163
164$(BUILD_DIR):
165	mkdir $@
166
167
168
169oscore_edhoc:
170	$(MAKE) -C $(USOCORE_UEDHOC_PATH)
171
172clean_oscore_edhoc:
173	$(MAKE) -C $(USOCORE_UEDHOC_PATH) clean
174
175clean:
176	-rm -fR $(BUILD_DIR)
177	$(MAKE) -C $(USOCORE_UEDHOC_PATH) clean
178
179#######################################
180# dependencies
181#######################################
182-include $(wildcard $(BUILD_DIR)/*.d)