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 responder application call:
11# make oscore_edhoc; make
12
13# toolchain
14CXX = g++
15CC = gcc
16SZ = size
17MAKE = make
18
19# target
20TARGET = responder
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
72
73# Linked libraries
74LD_LIBRARY_PATH += -L$(USOCORE_UEDHOC_BUILD_PATH)
75
76LDFLAGS += $(LD_LIBRARY_PATH)
77LDFLAGS += -luoscore-uedhoc
78LDFLAGS += $(ARCH)
79##########################################
80# CFLAGS
81##########################################
82#general c flags
83CFLAGS +=  $(ARCH) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall
84CXXFLAGS += $(ARCH) $(C_DEFS) $(C_INCLUDES) $(OPT)
85
86# have dubug information
87ifeq ($(DEBUG), 1)
88CFLAGS += -g -gdwarf-2
89CXXFLAGS += -Wall -g
90endif
91
92# Generate dependency information
93CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
94CXXFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
95
96# required for gddl-gen library
97CFLAGS += -DZCBOR_CANONICAL
98
99# use AddressSanitizer to find memory bugs
100# comment this out for better speed
101#CFLAGS += -fsanitize=address -fno-omit-frame-pointer
102#CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer
103#LDFLAGS += -fsanitize=address -static-libasan
104
105###########################################
106# default action: build all
107###########################################
108#list of objects from c files
109OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
110vpath %.c $(sort $(dir $(C_SOURCES)))
111
112# list of objects from c++ file
113OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cpp=.o)))
114vpath %.cpp $(sort $(dir $(CPP_SOURCES)))
115
116USOCORE_UEDHOC_OBJ = $(wildcard $(USOCORE_UEDHOC_PATH)/*.o)
117
118$(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR)
119	$(CXX) -c $(CXXFLAGS) $< -o $@
120
121$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
122	$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
123
124$(BUILD_DIR)/$(TARGET): $(OBJECTS) Makefile $(USOCORE_UEDHOC_PATH)/Makefile
125	$(MAKE) -C $(USOCORE_UEDHOC_PATH)
126	$(CXX) $(OBJECTS)  $(LDFLAGS) -o $@
127	$(SZ) $@
128
129$(BUILD_DIR):
130	mkdir $@
131
132
133
134oscore_edhoc:
135	$(MAKE) -C $(USOCORE_UEDHOC_PATH)
136
137clean_oscore_edhoc:
138	$(MAKE) -C $(USOCORE_UEDHOC_PATH) clean
139
140clean:
141	-rm -fR $(BUILD_DIR)
142	$(MAKE) -C $(USOCORE_UEDHOC_PATH) clean
143
144
145#######################################
146# dependencies
147#######################################
148-include $(wildcard $(BUILD_DIR)/*.d)
149
150
151
152
153
154
155
156