-
Notifications
You must be signed in to change notification settings - Fork 23
/
Makefile.ossl
142 lines (104 loc) · 5.97 KB
/
Makefile.ossl
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
# Makefile -- UNIX-style make for t_cose using OpenSSL crypto
#
# Copyright (c) 2019-2021, Laurence Lundblade. All rights reserved.
# Copyright (c) 2020, Michael Eckel, Fraunhofer SIT.
#
# SPDX-License-Identifier: BSD-3-Clause
#
# See BSD-3-Clause license in README.md
#
# ---- comment ----
# This is for OpenSSL Crypto. Adjust CRYPTO_INC and CRYPTO_LIB for the
# location of the openssl libraries on your build machine.
# ---- 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 has been 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 OpenSSL that is not installed
# in /usr/local/ /usr/local or some system location. The path names
# may need to be adjusted for your location of OpenSSL
#CRYPTO_INC=-I ../../openssl/openssl-1.1.1b/include/openssl -I ../../openssl/openssl-1.1.1b/include
#CRYPTO_LIB=../../openssl/openssl-1.1.1b/libcrypto.a
# These two are for reference to OpenSSL that has been installed in
# /usr/local/ or in some system location.
CRYPTO_LIB=-l crypto
CRYPTO_INC=-I /usr/local/include
CRYPTO_CONFIG_OPTS=-DT_COSE_USE_OPENSSL_CRYPTO
CRYPTO_OBJ=crypto_adapters/t_cose_openssl_crypto.o
CRYPTO_TEST_OBJ=test/t_cose_make_openssl_test_key.o
# ---- compiler configuration -----
# Optimize for size
C_OPTS=-Os -fPIC
# ---- T_COSE Config and test options ----
TEST_CONFIG_OPTS=
TEST_OBJ=test/t_cose_test.o test/run_tests.o test/t_cose_sign_verify_test.o test/t_cose_make_test_messages.o $(CRYPTO_TEST_OBJ)
# ---- the main body that is invariant ----
INC=-I inc -I test -I src
ALL_INC=$(INC) $(CRYPTO_INC) $(QCBOR_INC)
CFLAGS=$(CMD_LINE) $(ALL_INC) $(C_OPTS) $(TEST_CONFIG_OPTS) $(CRYPTO_CONFIG_OPTS)
SRC_OBJ=src/t_cose_sign1_verify.o src/t_cose_sign1_sign.o src/t_cose_util.o src/t_cose_parameters.o src/t_cose_short_circuit.o
.PHONY: all install install_headers install_so uninstall clean
all: libt_cose.a t_cose_test t_cose_basic_example_ossl
libt_cose.a: $(SRC_OBJ) $(CRYPTO_OBJ)
ar -r $@ $^
# The shared library 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) libt_cose.a
cc -o $@ $^ $(QCBOR_LIB) $(CRYPTO_LIB)
t_cose_basic_example_ossl: examples/t_cose_basic_example_ossl.o 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
install -m 644 inc/t_cose/t_cose_common.h $(DESTDIR)$(PREFIX)/include/t_cose
install -m 644 inc/t_cose/q_useful_buf.h $(DESTDIR)$(PREFIX)/include/t_cose
install -m 644 inc/t_cose/t_cose_sign1_sign.h $(DESTDIR)$(PREFIX)/include/t_cose
install -m 644 inc/t_cose/t_cose_sign1_verify.h $(DESTDIR)$(PREFIX)/include/t_cose
# 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) t_cose_basic_example_ossl examples/*.o t_cose_test libt_cose.a libt_cose.so main.o
# ---- public headers -----
PUBLIC_INTERFACE=inc/t_cose/t_cose_common.h inc/t_cose/t_cose_sign1_sign.h inc/t_cose/t_cose_sign1_verify.h
# ---- source dependecies -----
src/t_cose_util.o: src/t_cose_util.h src/t_cose_standard_constants.h inc/t_cose/t_cose_common.h src/t_cose_crypto.h
src/t_cose_sign1_verify.o: inc/t_cose/t_cose_sign1_verify.h src/t_cose_crypto.h src/t_cose_util.h src/t_cose_parameters.h inc/t_cose/t_cose_common.h src/t_cose_standard_constants.h src/t_cose_short_circuit.h
src/t_cose_parameters.o: src/t_cose_parameters.h src/t_cose_standard_constants.h inc/t_cose/t_cose_sign1_verify.h inc/t_cose/t_cose_common.h
src/t_cose_sign1_sign.o: inc/t_cose/t_cose_sign1_sign.h src/t_cose_standard_constants.h src/t_cose_crypto.h src/t_cose_util.h inc/t_cose/t_cose_common.h src/t_cose_short_circuit.h
src/t_cose_short_circuit.o: src/t_cose_short_circuit.h src/t_cose_standard_constants.h src/t_cose_crypto.h
# ---- test dependencies -----
test/t_cose_test.o: test/t_cose_test.h test/t_cose_make_test_messages.h src/t_cose_crypto.h $(PUBLIC_INTERFACE)
test/t_cose_sign_verify_test.o: test/t_cose_sign_verify_test.h test/t_cose_make_test_messages.h src/t_cose_crypto.h test/t_cose_make_test_pub_key.h $(PUBLIC_INTERFACE)
test/t_cose_make_test_messages.o: test/t_cose_make_test_messages.h inc/t_cose/t_cose_sign1_sign.h inc/t_cose/t_cose_common.h src/t_cose_standard_constants.h src/t_cose_crypto.h src/t_cose_util.h
test/run_test.o: test/run_test.h test/t_cose_test.h test/t_cose_hash_fail_test.h
test/t_cose_make_openssl_test_key.o: test/t_cose_make_test_pub_key.h test/t_cose_rsa_test_key.h src/t_cose_standard_constants.h inc/t_cose/t_cose_common.h
# ---- crypto dependencies ----
crypto_adapters/t_cose_openssl_crypto.o: src/t_cose_crypto.h inc/t_cose/t_cose_common.h src/t_cose_standard_constants.h inc/t_cose/q_useful_buf.h
# ---- example dependencies ----
examples/t_cose_basic_example_ossl.o: $(PUBLIC_INTERFACE)