forked from Infineon/linux-optiga-trust-m
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
360 lines (310 loc) · 10.5 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#/**
#* MIT License
#*
#* Copyright (c) 2020 Infineon Technologies AG
#*
#* Permission is hereby granted, free of charge, to any person obtaining a copy
#* of this software and associated documentation files (the "Software"), to deal
#* in the Software without restriction, including without limitation the rights
#* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#* copies of the Software, and to permit persons to whom the Software is
#* furnished to do so, subject to the following conditions:
#*
#* The above copyright notice and this permission notice shall be included in all
#* copies or substantial portions of the Software.
#*
#* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#* SOFTWARE
#
#*/
#~ Uncomment this for AARCH64 or pass it as argument in command line
#~ AARCH64 = YES
TRUSTM = trustm_lib
BUILD_FOR_RPI = YES
BUILD_FOR_ULTRA96 = NO
USE_LIBGPIOD_RPI = NO
PALDIR = $(TRUSTM)/pal/linux
LIBDIR = $(TRUSTM)/optiga/util
LIBDIR += $(TRUSTM)/optiga/crypt
LIBDIR += $(TRUSTM)/optiga/comms
LIBDIR += $(TRUSTM)/optiga/common
LIBDIR += $(TRUSTM)/optiga/cmd
LIBDIR += $(TRUSTM)/externals/mbedtls
LIBDIR += trustm_helper
OPENSSL_VERSION := $(shell pkg-config --modversion openssl)
OPENSSL_MAJOR = $(shell echo $(OPENSSL_VERSION) | awk -F. '{print $$1}')
ifeq ($(OPENSSL_MAJOR), 1)
#OTHDIR = $(TRUSTM)/examples/optiga
BINDIR = bin
APPDIR = ex_cli_applications
ENGDIR = trustm_engine
ifdef AARCH64
LIB_INSTALL_DIR = /usr/lib/aarch64-linux-gnu
else
LIB_INSTALL_DIR = /usr/lib/arm-linux-gnueabihf
endif
ENGINE_INSTALL_DIR = $(LIB_INSTALL_DIR)/engines-1.1
INCDIR = $(TRUSTM)/optiga/include
INCDIR += $(TRUSTM)/optiga/include/optiga
INCDIR += $(TRUSTM)/optiga/include/optiga/ifx_i2c
INCDIR += $(TRUSTM)/optiga/include/optiga/comms
INCDIR += $(TRUSTM)/optiga/include/optiga/common
INCDIR += $(TRUSTM)/optiga/include/optiga/cmd
INCDIR += $(TRUSTM)/optiga/include/optiga/pal
INCDIR += $(TRUSTM)/pal/linux
INCDIR += trustm_helper/include
INCDIR += trustm_engine
INCDIR += $(TRUSTM)/externals/mbedtls/include
ifdef INCDIR
INCSRC := $(shell find $(INCDIR) -name '*.h')
INCDIR := $(addprefix -I ,$(INCDIR))
endif
ifdef LIBDIR
ifdef PALDIR
LIBSRC = $(PALDIR)/pal.c
ifeq ($(BUILD_FOR_RPI), YES)
LIBSRC += $(PALDIR)/pal_gpio.c
endif
ifeq ($(BUILD_FOR_ULTRA96), YES)
LIBSRC += $(PALDIR)/pal_gpio.c
endif
ifeq ($(USE_LIBGPIOD_RPI), YES)
LIBSRC += $(PALDIR)/pal_gpio_gpiod.c
endif
LIBSRC += $(PALDIR)/pal_i2c.c
LIBSRC += $(PALDIR)/pal_logger.c
LIBSRC += $(PALDIR)/pal_os_datastore.c
LIBSRC += $(PALDIR)/pal_os_event.c
LIBSRC += $(PALDIR)/pal_os_lock.c
LIBSRC += $(PALDIR)/pal_os_timer.c
LIBSRC += $(PALDIR)/pal_os_memory.c
LIBSRC += $(TRUSTM)/pal/pal_crypt_openssl.c
ifeq ($(BUILD_FOR_RPI), YES)
LIBSRC += $(PALDIR)/target/rpi3/pal_ifx_i2c_config.c
endif
ifeq ($(USE_LIBGPIOD_RPI), YES)
LIBSRC += $(PALDIR)/target/gpiod/pal_ifx_i2c_config.c
endif
ifeq ($(BUILD_FOR_ULTRA96), YES)
LIBSRC += $(PALDIR)/target/ultra96/pal_ifx_i2c_config.c
endif
endif
LIBSRC += $(shell find $(LIBDIR) -name '*.c')
LIBOBJ := $(patsubst %.c,%.o,$(LIBSRC))
LIB = libtrustm.so
endif
ifdef OTHDIR
OTHSRC := $(shell find $(OTHDIR) -name '*.c')
OTHOBJ := $(patsubst %.c,%.o,$(OTHSRC))
endif
ifdef APPDIR
APPSRC := $(shell find $(APPDIR) -name '*.c')
APPOBJ := $(patsubst %.c,%.o,$(APPSRC))
APPS := $(patsubst %.c,%,$(APPSRC))
endif
ifdef ENGDIR
ENGSRC := $(shell find $(ENGDIR) -name '*.c')
ENGOBJ := $(patsubst %.c,%.o,$(ENGSRC))
ENG = trustm_engine.so
endif
CC = gcc
DEBUG = -g
CFLAGS += -c
ifdef AARCH64
CFLAGS += -fPIC
endif
#CFLAGS += $(DEBUG)
CFLAGS += $(INCDIR)
CFLAGS += -Wall
ifeq ($(USE_LIBGPIOD_RPI), YES)
CFLAGS += -DHAS_LIBGPIOD
endif
CFLAGS += -DENGINE_DYNAMIC_SUPPORT
#CFLAGS += -DMODULE_ENABLE_DTLS_MUTUAL_AUTH
LDFLAGS += -lpthread
LDFLAGS += -lssl
ifeq ($(USE_LIBGPIOD_RPI), YES)
LDFLAGS += -lgpiod
endif
LDFLAGS += -lcrypto
LDFLAGS += -lrt
LDFLAGS += -Wl,--no-undefined
LDFLAGS_1 = -L$(BINDIR) -Wl,-R$(BINDIR)
LDFLAGS_1 += -ltrustm
.Phony : install uninstall all clean
all : $(BINDIR)/$(LIB) $(APPS) $(BINDIR)/$(ENG)
install:
@echo "Create symbolic link to trustm_lib $(LIB_INSTALL_DIR)/$(LIB)"
@ln -s $(realpath $(BINDIR)/$(LIB)) $(LIB_INSTALL_DIR)/$(LIB)
@echo "Create symbolic link to the openssl engine $(ENGINE_INSTALL_DIR)/$(ENG)"
@ln -s $(realpath $(BINDIR)/$(ENG)) $(ENGINE_INSTALL_DIR)/$(ENG)
uninstall: clean
@echo "Removing trustm_lib $(LIB_INSTALL_DIR)/$(LIB)"
@rm -rf $(LIB_INSTALL_DIR)/$(LIB)
@echo "Removing openssl symbolic link from $(ENGINE_INSTALL_DIR)"
@rm -rf $(ENGINE_INSTALL_DIR)/$(ENG)
clean :
@echo "Removing *.o from $(LIBDIR)"
@rm -rf $(LIBOBJ)
@echo "Removing *.o from $(OTHDIR)"
@rm -rf $(OTHOBJ)
@echo "Removing *.o from $(APPDIR)"
@rm -rf $(APPOBJ)
@echo "Removing *.o from $(ENGDIR)"
@rm -rf $(ENGOBJ)
@echo "Removing all application from $(APPDIR)"
@rm -rf $(APPS)
@echo "Removing all application from $(BINDIR)"
@rm -rf bin/*
@echo "Removing all hidden files"
@rm -rf .trustm_*
$(BINDIR)/$(ENG): %: $(ENGOBJ) $(INCSRC) $(BINDIR)/$(LIB)
@echo "******* Linking $@ "
@mkdir -p bin
@$(CC) $(ENGOBJ) $(LDFLAGS) $(LDFLAGS_1) -shared -o $@
$(APPS): %: $(OTHOBJ) $(INCSRC) $(BINDIR)/$(LIB) %.o
@echo "******* Linking $@ "
@mkdir -p bin
@$(CC) [email protected] $(LDFLAGS_1) $(LDFLAGS) $(OTHOBJ) -o $@
@mv $@ bin/.
$(BINDIR)/$(LIB): %: $(LIBOBJ) $(INCSRC)
@echo "******* Linking $@ "
@mkdir -p bin
@$(CC) $(LIBOBJ) $(LDFLAGS) -shared -o $@
$(LIBOBJ): %.o: %.c $(INCSRC)
@echo "+++++++ Generating lib object: $< "
@$(CC) $(CFLAGS) $< -o $@
%.o: %.c $(INCSRC)
@echo "------- Generating application objects: $< "
@$(CC) $(CFLAGS) $< -o $@
else
BINDIR = bin
APPDIR = ex_cli_applications
ifdef AARCH64
LIB_INSTALL_DIR = /usr/lib/aarch64-linux-gnu
else
LIB_INSTALL_DIR = /usr/lib/arm-linux-gnueabihf
endif
INCDIR = $(TRUSTM)/optiga/include
INCDIR += $(TRUSTM)/optiga/include/optiga
INCDIR += $(TRUSTM)/optiga/include/optiga/ifx_i2c
INCDIR += $(TRUSTM)/optiga/include/optiga/comms
INCDIR += $(TRUSTM)/optiga/include/optiga/common
INCDIR += $(TRUSTM)/optiga/include/optiga/cmd
INCDIR += $(TRUSTM)/optiga/include/optiga/pal
INCDIR += $(TRUSTM)/pal/linux
INCDIR += trustm_helper/include
INCDIR += $(TRUSTM)/externals/mbedtls/include
ifdef INCDIR
INCSRC := $(shell find $(INCDIR) -name '*.h')
INCDIR := $(addprefix -I ,$(INCDIR))
endif
ifdef LIBDIR
ifdef PALDIR
LIBSRC = $(PALDIR)/pal.c
ifeq ($(BUILD_FOR_RPI), YES)
LIBSRC += $(PALDIR)/pal_gpio.c
endif
ifeq ($(BUILD_FOR_ULTRA96), YES)
LIBSRC += $(PALDIR)/pal_gpio.c
endif
ifeq ($(USE_LIBGPIOD_RPI), YES)
LIBSRC += $(PALDIR)/pal_gpio_gpiod.c
endif
LIBSRC += $(PALDIR)/pal_i2c.c
LIBSRC += $(PALDIR)/pal_logger.c
LIBSRC += $(PALDIR)/pal_os_datastore.c
LIBSRC += $(PALDIR)/pal_os_event.c
LIBSRC += $(PALDIR)/pal_os_lock.c
LIBSRC += $(PALDIR)/pal_os_timer.c
LIBSRC += $(PALDIR)/pal_os_memory.c
LIBSRC += $(TRUSTM)/pal/pal_crypt_openssl.c
ifeq ($(BUILD_FOR_RPI), YES)
LIBSRC += $(PALDIR)/target/rpi3/pal_ifx_i2c_config.c
endif
ifeq ($(USE_LIBGPIOD_RPI), YES)
LIBSRC += $(PALDIR)/target/gpiod/pal_ifx_i2c_config.c
endif
ifeq ($(BUILD_FOR_ULTRA96), YES)
LIBSRC += $(PALDIR)/target/ultra96/pal_ifx_i2c_config.c
endif
endif
LIBSRC += $(shell find $(LIBDIR) -name '*.c')
LIBOBJ := $(patsubst %.c,%.o,$(LIBSRC))
LIB = libtrustm.so
endif
ifdef OTHDIR
OTHSRC := $(shell find $(OTHDIR) -name '*.c')
OTHOBJ := $(patsubst %.c,%.o,$(OTHSRC))
endif
ifdef APPDIR
APPSRC := $(shell find $(APPDIR) -name '*.c')
APPOBJ := $(patsubst %.c,%.o,$(APPSRC))
APPS := $(patsubst %.c,%,$(APPSRC))
endif
CC = gcc
DEBUG = -g
CFLAGS += -c
ifdef AARCH64
CFLAGS += -fPIC
endif
#CFLAGS += $(DEBUG)
CFLAGS += $(INCDIR)
CFLAGS += -Wall
ifeq ($(USE_LIBGPIOD_RPI), YES)
CFLAGS += -DHAS_LIBGPIOD
endif
#CFLAGS += -DENGINE_DYNAMIC_SUPPORT
#CFLAGS += -DMODULE_ENABLE_DTLS_MUTUAL_AUTH
LDFLAGS += -lpthread
LDFLAGS += -lssl
ifeq ($(USE_LIBGPIOD_RPI), YES)
LDFLAGS += -lgpiod
endif
LDFLAGS += -lcrypto
LDFLAGS += -lrt
LDFLAGS += -Wl,--no-undefined
LDFLAGS_1 = -L$(BINDIR) -Wl,-R$(BINDIR)
LDFLAGS_1 += -ltrustm
.Phony : install uninstall all clean
all : $(BINDIR)/$(LIB) $(APPS)
install:
@echo "Create symbolic link to trustm_lib $(LIB_INSTALL_DIR)/$(LIB)"
@ln -s $(realpath $(BINDIR)/$(LIB)) $(LIB_INSTALL_DIR)/$(LIB)
uninstall: clean
@echo "Removing trustm_lib $(LIB_INSTALL_DIR)/$(LIB)"
@rm -rf $(LIB_INSTALL_DIR)/$(LIB)
clean :
@echo "Removing *.o from $(LIBDIR)"
@rm -rf $(LIBOBJ)
@echo "Removing *.o from $(OTHDIR)"
@rm -rf $(OTHOBJ)
@echo "Removing *.o from $(APPDIR)"
@rm -rf $(APPOBJ)
@echo "Removing all application from $(APPDIR)"
@rm -rf $(APPS)
@echo "Removing all application from $(BINDIR)"
@rm -rf bin/*
@echo "Removing all hidden files"
@rm -rf .trustm_*
$(APPS): %: $(OTHOBJ) $(INCSRC) $(BINDIR)/$(LIB) %.o
@echo "******* Linking $@ "
@mkdir -p bin
@$(CC) [email protected] $(LDFLAGS_1) $(LDFLAGS) $(OTHOBJ) -o $@
@mv $@ bin/.
$(BINDIR)/$(LIB): %: $(LIBOBJ) $(INCSRC)
@echo "******* Linking $@ "
@mkdir -p bin
@$(CC) $(LIBOBJ) $(LDFLAGS) -shared -o $@
$(LIBOBJ): %.o: %.c $(INCSRC)
@echo "+++++++ Generating lib object: $< "
@$(CC) $(CFLAGS) $< -o $@
%.o: %.c $(INCSRC)
@echo "------- Generating application objects: $< "
@$(CC) $(CFLAGS) $< -o $@
endif