-
Notifications
You must be signed in to change notification settings - Fork 24
/
Makefile.psa
158 lines (115 loc) · 5.33 KB
/
Makefile.psa
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
# Makefile.psa -- Makefile for t_cose with the Mbed TLS crypto library
#
# Copyright (c) 2019-2023, Laurence Lundblade. All rights reserved.
# Copyright (c) 2020, Michael Eckel, Fraunhofer SIT.
# Copyright (c) 2022, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
# See BSD-3-Clause license in README.md
#
# ---- General comment ----
# This makefile is for t_cose with the Mbed TLS crypto library. Mbed
# TLS is an implementation of the PSA crypto API. See longer
# explanation in README.md. Adjust CRYPTO_INC and CRYPTO_LIB for the
# location of the Mbed TLS library on your build machine.
# Makefile.common, included below, contains the lists of library, test
# and example object files that are invariant by crypto library.
# ---- QCBOR location ----
# This is for direct reference to QCBOR that is not installed in
# /usr/local or some system location. The path may need to be adjusted
# for your location of QCBOR.
#QCBOR_DIR=../../QCBOR/master
#QCBOR_INC=-I $(QCBOR_DIR)/inc
#QCBOR_LIB=$(QCBOR_DIR)/libqcbor.a
# This is for reference to QCBOR that is installed in /usr/local or in
# some system location. This will typically use dynamic linking if
# there is a libqcbor.so
QCBOR_INC=-I /usr/local/include
QCBOR_LIB=-lqcbor
# ---- crypto configuration -----
# These two are for direct reference to Mbed TLS crypto that is not
# installed in /usr/local or some system location. The path names may
# need to be adjusted for your location of Mbed TLS
#CRYPTO_INC=-I ../../mbedtls/include/
#CRYPTO_LIB=../../mbedtls/library/libmbedcrypto.a
# These two are for reference to Mbed TLS that has been installed in
# /usr/local or in some system location.
CRYPTO_LIB=-l mbedcrypto
CRYPTO_INC=-I /usr/local/include
CRYPTO_CONFIG_OPTS=-DT_COSE_USE_PSA_CRYPTO
CRYPTO_OBJ=crypto_adapters/t_cose_psa_crypto.o
CRYPTO_TEST_OBJ=examples/init_keys_psa.o
CRYPTO_EXAMPLE_OBJ=examples/init_keys_psa.o
# ---- other configuration ----
# Use as needed. It has been used to disable features that aren't ready
# or that aren't passing tests
OTHER_OPTS=
# ---- compiler configuration -----
# This makefile uses a minimum of compiler flags so that it will
# work out-of-the-box with a wide variety of compilers. For example,
# some compilers error out on some of the warnings flags gcc supports.
# The $(CMD_LINE) variable allows passing in extra flags. This is
# used on the stringent build script that is in
# https://github.com/laurencelundblade/tdv. This script is used
# before pushes to master (though not yet through an automated build
# process). See "warn:" below.
C_OPTS=-Os -fPIC
# ---- Aggregate includes and options ----
INC=-I inc -I test -I src -I examples
ALL_INC=$(INC) $(CRYPTO_INC) $(QCBOR_INC)
CFLAGS=$(CMD_LINE) $(ALL_INC) $(C_OPTS) $(CRYPTO_CONFIG_OPTS) $(OTHER_OPTS)
# ---- The build targets ----
.PHONY: all install install_headers install_so uninstall clean warn
all: libt_cose.a t_cose_test t_cose_examples
# run "make warn" as a handy way to compile with the warning flags
# used in the QCBOR release process. See C_OPTS above.
warn:
make -f Makefile.psa CMD_LINE="-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Wcast-qual"
# ---- Bring in common definitions of SRC_OBJ, TEST_OBJ, ... -----
include Makefile.common
# --- Finally, the things that actually get built ----
libt_cose.a: $(SRC_OBJ) $(CRYPTO_OBJ)
ar -r $@ $^
# The shared library which is not made by default because of platform
# variability For example MacOS and Linux behave differently and some
# IoT OS's don't support them at all.
libt_cose.so: $(SRC_OBJ) $(CRYPTO_OBJ)
cc -shared $^ -o $@ $(CRYPTO_LIB) $(QCBOR_LIB)
t_cose_test: main.o $(TEST_OBJ) $(CRYPTO_TEST_OBJ) libt_cose.a
cc -dead_strip -o $@ $^ $(QCBOR_LIB) $(CRYPTO_LIB)
crypto_adapters/t_cose_psa_crypto.o: crypto_adapters/t_cose_psa_crypto.c \
src/t_cose_crypto.h \
src/t_cose_util.h \
inc/t_cose/t_cose_standard_constants.h
examples/init_keys_psa.o: examples/init_keys_psa.c \
examples/init_keys.h \
$(PUBLIC_INTERFACE)
t_cose_examples: $(EXAMPLE_OBJ) $(CRYPTO_EXAMPLE_OBJ) libt_cose.a
cc -o $@ $^ $(QCBOR_LIB) $(CRYPTO_LIB)
# ---- Installation ----
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
install: libt_cose.a install_headers
install -d $(DESTDIR)$(PREFIX)/lib/
install -m 644 libt_cose.a $(DESTDIR)$(PREFIX)/lib/
install_headers: $(PUBLIC_INTERFACE)
install -d $(DESTDIR)$(PREFIX)/include/t_cose
@for i in $(PUBLIC_INTERFACE); do \
install -m 644 $$i $(DESTDIR)$(PREFIX)/include/t_cose ; \
done
# The shared library is not installed by default because of platform variability.
install_so: libt_cose.so install_headers
install -m 755 libt_cose.so $(DESTDIR)$(PREFIX)/lib/libt_cose.so.1.0.0
ln -sf libt_cose.so.1 $(DESTDIR)$(PREFIX)/lib/libt_cose.so
ln -sf libt_cose.so.1.0.0 $(DESTDIR)$(PREFIX)/lib/libt_cose.so.1
uninstall: libt_cose.a $(PUBLIC_INTERFACE)
$(RM) -d $(DESTDIR)$(PREFIX)/include/t_cose/*
$(RM) -d $(DESTDIR)$(PREFIX)/include/t_cose/
$(RM) $(addprefix $(DESTDIR)$(PREFIX)/lib/, \
libt_cose.a libt_cose.so libt_cose.so.1 libt_cose.so.1.0.0)
clean:
rm -f $(SRC_OBJ) $(TEST_OBJ) $(CRYPTO_OBJ) $(CRYPTO_TEST_OBJ) $(EXAMPLE_OBJ) $(CRYPTO_EXAMPLE_OBJ) \
t_cose_examples libt_cose.so \
main.o t_cose_test libt_cose.a libt_cose.so