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
13# toolchain
14CXX = g++
15CC = gcc
16SZ = size
17MAKE = make
18
19# target
20TARGET = server
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
100
101# use AddressSanitizer to find memory bugs
102# comment this out for better speed
103#CFLAGS += -fsanitize=address -fno-omit-frame-pointer
104#CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer
105#LDFLAGS += -fsanitize=address -static-libasan
106
107###########################################
108# default action: build all
109###########################################
110#list of objects from c files
111OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
112vpath %.c $(sort $(dir $(C_SOURCES)))
113
114# list of objects from c++ file
115OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(CPP_SOURCES:.cpp=.o)))
116vpath %.cpp $(sort $(dir $(CPP_SOURCES)))
117
118USOCORE_UEDHOC_OBJ = $(wildcard $(USOCORE_UEDHOC_PATH)/*.o)
119
120
121
122$(BUILD_DIR)/%.o: %.cpp Makefile | $(BUILD_DIR)
123	$(CXX) -c $(CXXFLAGS) $< -o $@
124
125$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
126	$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
127
128$(BUILD_DIR)/$(TARGET): $(OBJECTS) Makefile $(USOCORE_UEDHOC_PATH)/Makefile $(USOCORE_UEDHOC_OBJ)
129	$(MAKE) -C $(USOCORE_UEDHOC_PATH)
130	$(CXX) $(OBJECTS)  $(LDFLAGS) -o $@
131	$(SZ) $@
132
133$(BUILD_DIR):
134	mkdir $@
135
136
137
138oscore_edhoc:
139	$(MAKE) -C $(USOCORE_UEDHOC_PATH)
140
141clean_oscore_edhoc:
142	$(MAKE) -C $(USOCORE_UEDHOC_PATH) clean
143
144clean:
145	-rm -fR $(BUILD_DIR)
146	$(MAKE) -C $(USOCORE_UEDHOC_PATH) clean
147
148#######################################
149# dependencies
150#######################################
151-include $(wildcard $(BUILD_DIR)/*.d)