-
Notifications
You must be signed in to change notification settings - Fork 17
/
Makefile.am
267 lines (227 loc) · 9.66 KB
/
Makefile.am
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
# SPDX-License-Identifier: BSD-2
#
.PHONY: example
AM_CFLAGS = -I$(srcdir)/src
EXTRA_DIST = \
CHANGELOG.md \
CONTRIBUTING.md \
INSTALL.md \
LICENSE \
README.md \
VERSION
# rule to extract contributors from git history & generate AUTHORS file
AUTHORS :
git log --format='%aN <%aE>' | grep -v 'users.noreply.github.com' | sort | \
uniq -c | sort -nr | sed 's/^\s*//' | cut -d" " -f2- > $@
all-local: AUTHORS
EXTRA_DIST += AUTHORS
CLEANS = AUTHORS
# CODE_COVERAGE
include $(top_srcdir)/aminclude_static.am
clean-local: code-coverage-clean
rm -rf $(CLEANS)
distclean-local: code-coverage-dist-clean
# workaround for https://github.com/autoconf-archive/autoconf-archive/pull/182
if CODE_COVERAGE_ENABLED
AM_DISTCHECK_CONFIGURE_FLAGS := $(AM_DISTCHECK_CONFIGURE_FLAGS) --disable-code-coverage
endif # CODE_COVERAGE_ENABLED
noinst_LIBRARIES =
# === The Library itself ===
libtss2_tcti_uefi = src/libtss2-tcti-uefi.a
lib_LIBRARIES = $(libtss2_tcti_uefi)
tss2dir = $(includedir)/tss2
tss2_HEADERS = src/tss2-tcti-uefi.h
# rules to build libraries
src_libtss2_tcti_uefi_a_CFLAGS = $(EXTRA_CFLAGS) $(AM_CFLAGS) \
$(CODE_COVERAGE_CFLAGS)
src_libtss2_tcti_uefi_a_SOURCES = src/tcti-uefi.c src/tcti-uefi.h \
src/tcg2-protocol.h src/uefi-types.h src/tcg2-util.c src/tcg2-util.h
# === EXAMPLES ===
libexample_util = example/libexample-util.a
noinst_LIBRARIES += $(libexample_util)
example: $(EXAMPLES)
EXAMPLES = \
example/tcg2-get-caps.efi \
example/tcg2-get-eventlog.efi \
example/tpm2-get-caps-fixed.efi \
example/tpm2-nv-ops.efi \
example/tpm2-get-pcrs.efi \
example/tcg2-get-pcr-banks.efi
CLEANS += \
$(EXAMPLES) \
example/tcg2-get-caps.so \
example/tcg2-get-eventlog.so \
example/tpm2-get-caps-fixed.so \
example/tpm2-nv-ops.so \
example/tpm2-get-pcrs.so \
example/tcg2-get-pcr-banks.so \
example/*.$(OBJEXT)
example_libexample_util_a_CFLAGS = $(EXTRA_CFLAGS) $(AM_CFLAGS) \
$(CODE_COVERAGE_CFLAGS)
example_libexample_util_a_SOURCES = example/compat.c example/compat.h \
example/tss2-util.c example/tss2-util.h example/util.c example/util.h
# hack to ensure .deps directory required by autotools is created in the
# 'example' directory before we build any targets
example/.deps:
mkdir -p $@
example/tcg2-get-caps.$(OBJEXT): example/tcg2-get-caps.c \
src/tcg2-protocol.h src/tcg2-util.h | example/.deps
example/tcg2-get-eventlog.$(OBJEXT): example/tcg2-get-eventlog.c \
|example/.deps
example/tpm2-get-caps-fixed.$(OBJEXT): example/tpm2-get-caps-fixed.c \
example/compat.h example/tss2-util.h | example/.deps
example/tpm2-nv-ops.$(OBJEXT): example/tpm2-nv-ops.c \
example/compat.h example/tss2-util.h | example/.deps
example/tpm2-get-pcrs.$(OBJEXT): example/tpm2-get-pcrs.c \
example/tss2-util.h | example/.deps
example/tcg2-get-pcr-banks.$(OBJEXT): example/tcg2-get-pcr-banks.c \
example/compat.h example/tss2-util.h | example/.deps
# dependency expression for shared objects built for the UEFI executables
example/tcg2-get-caps.so: CFLAGS+=$(EXTRA_CFLAGS) $(AM_CFLAGS)
example/tcg2-get-caps.so: LDFLAGS+=-Wl,--no-undefined
example/tcg2-get-caps.so: LDLIBS+=$(CODE_COVERAGE_LIBS)
example/tcg2-get-caps.so: $(libtss2_tcti_uefi) $(libexample_util)
example/tcg2-get-caps.so: example/tcg2-get-caps.$(OBJEXT)
example/tcg2-get-eventlog.so: CFLAGS+=$(EXTRA_CFLAGS) $(AM_CFLAGS)
example/tcg2-get-eventlog.so: LDFLAGS+=-Wl,--no-undefined
example/tcg2-get-eventlog.so: LDLIBS+=$(CODE_COVERAGE_LIBS)
example/tcg2-get-eventlog.so: $(libtss2_tcti_uefi) $(libexample_util)
example/tcg2-get-eventlog.so: example/tcg2-get-eventlog.$(OBJEXT)
example/tpm2-get-caps-fixed.so: CFLAGS+=$(EXTRA_CFLAGS) $(AM_CFLAGS)
example/tpm2-get-caps-fixed.so: LDFLAGS+=-Wl,--no-undefined
example/tpm2-get-caps-fixed.so: LDLIBS+=-l:libtss2-sys.a -l:libtss2-mu.a \
$(CODE_COVERAGE_LIBS)
example/tpm2-get-caps-fixed.so: $(libexample_util) $(libtss2_tcti_uefi)
example/tpm2-get-caps-fixed.so: example/tpm2-get-caps-fixed.$(OBJEXT)
example/tpm2-nv-ops.so: CFLAGS+=$(EXTRA_CFLAGS) $(AM_CFLAGS)
example/tpm2-nv-ops.so: LDFLAGS+=-Wl,--no-undefined
example/tpm2-nv-ops.so: LDLIBS+=-l:libtss2-sys.a -l:libtss2-mu.a \
$(CODE_COVERAGE_LIBS)
example/tpm2-nv-ops.so: $(libexample_util) $(libtss2_tcti_uefi)
example/tpm2-nv-ops.so: example/tpm2-nv-ops.$(OBJEXT)
example/tpm2-get-pcrs.so: CFLAGS+=$(EXTRA_CFLAGS) $(AM_CFLAGS)
example/tpm2-get-pcrs.so: LDFLAGS+=-Wl,--no-undefined
example/tpm2-get-pcrs.so: LDLIBS+=-l:libtss2-sys.a -l:libtss2-mu.a \
$(CODE_COVERAGE_LIBS)
example/tpm2-get-pcrs.so: $(libexample_util) $(libtss2_tcti_uefi)
example/tpm2-get-pcrs.so: example/tpm2-get-pcrs.$(OBJEXT)
example/tcg2-get-pcr-banks.so: CFLAGS+=$(EXTRA_CFLAGS) $(AM_CFLAGS)
example/tcg2-get-pcr-banks.so: LDFLAGS+=-Wl,--no-undefined
example/tcg2-get-pcr-banks.so: LDLIBS+=$(CODE_COVERAGE_LIBS)
example/tcg2-get-pcr-banks.so: $(libexample_util) $(libtss2_tcti_uefi)
example/tcg2-get-pcr-banks.so: example/tcg2-get-pcr-banks.$(OBJEXT)
# === TESTS ===
TESTS =
TEST_EXTENSIONS =
# UNIT tests
noinst_LIBRARIES += test/libtest-util.a
if UNIT
TEST_UNIT = \
test/example-util_unit \
test/tcg2-util_unit \
test/tcti-uefi-cast_unit \
test/tcti-uefi-finalize_unit \
test/tcti-uefi-init_unit \
test/tcti-uefi-receive_unit \
test/tcti-uefi-transmit_unit
TESTS += $(TEST_UNIT)
check_PROGRAMS = $(TEST_UNIT)
endif
# variables to simplify test rules
TEST_FLAGS = $(CMOCKA_CFLAGS) $(EXTRA_CFLAGS) $(AM_CFLAGS) \
$(CODE_COVERAGE_CFLAGS)
TEST_LIBS = $(libexample_util) $(CMOCKA_LIBS) $(CODE_COVERAGE_LIBS) \
src/libtss2-tcti-uefi.a test/libtest-util.a
TEST_WRAPS_TCTI = -Wl,--wrap=AllocatePool,--wrap=CopyMem,--wrap=FreePool \
-Wl,--wrap=Print,--wrap=tcg2_get_capability,--wrap=tcg2_get_max_buf \
-Wl,--wrap=tcg2_get_protocol,--wrap=tcg2_submit_command,--wrap=DumpHex
TEST_WRAPS_TCG2 = -Wl,--wrap=AllocatePool,--wrap=CopyMem \
-Wl,--wrap=FreePool,--wrap=Print,--wrap=efi_call2,--wrap=efi_call5 \
-Wl,--wrap=LibLocateProtocol
if UNIT
# rule to build test utility library
test_libtest_util_a_CFLAGS = $(EXTRA_CFLAGS) $(AM_CFLAGS)
test_libtest_util_a_SOURCES = test/tcti-uefi-wraps.c test/tcti-uefi-wraps.h
# rules to build test executables
test_example_util_unit_CFLAGS = $(TEST_FLAGS) -DGNU_EFI_SETJMP_H
test_example_util_unit_LDADD = $(TEST_LIBS)
test_example_util_unit_LDFLAGS = $(TEST_WRAPS_TCTI)
test_example_util_unit_SOURCES = test/example-util_unit.c
test_tcg2_util_unit_CFLAGS = $(TEST_FLAGS) -DGNU_EFI_SETJMP_H
test_tcg2_util_unit_LDADD = $(TEST_LIBS)
test_tcg2_util_unit_LDFLAGS = $(TEST_WRAPS_TCG2)
test_tcg2_util_unit_SOURCES = test/tcg2-util_unit.c
test_tcti_uefi_cast_unit_CFLAGS = $(TEST_FLAGS)
test_tcti_uefi_cast_unit_LDADD = $(TEST_LIBS)
test_tcti_uefi_cast_unit_LDFLAGS = $(TEST_WRAPS_TCTI)
test_tcti_uefi_cast_unit_SOURCES = test/tcti-uefi-cast_unit.c
test_tcti_uefi_init_unit_CFLAGS = $(TEST_FLAGS)
test_tcti_uefi_init_unit_LDADD = $(TEST_LIBS)
test_tcti_uefi_init_unit_LDFLAGS = $(TEST_WRAPS_TCTI)
test_tcti_uefi_init_unit_SOURCES = test/tcti-uefi-init_unit.c
test_tcti_uefi_receive_unit_CFLAGS = $(TEST_FLAGS)
test_tcti_uefi_receive_unit_LDADD = $(TEST_LIBS)
test_tcti_uefi_receive_unit_LDFLAGS = $(TEST_WRAPS_TCTI)
test_tcti_uefi_receive_unit_SOURCES = test/tcti-uefi-receive_unit.c
test_tcti_uefi_transmit_unit_CFLAGS = $(TEST_FLAGS)
test_tcti_uefi_transmit_unit_LDADD = $(TEST_LIBS)
test_tcti_uefi_transmit_unit_LDFLAGS = $(TEST_WRAPS_TCTI)
test_tcti_uefi_transmit_unit_SOURCES = test/tcti-uefi-transmit_unit.c
test_tcti_uefi_finalize_unit_CFLAGS = $(TEST_FLAGS)
test_tcti_uefi_finalize_unit_LDADD = $(TEST_LIBS)
test_tcti_uefi_finalize_unit_LDFLAGS = $(TEST_WRAPS_TCTI)
test_tcti_uefi_finalize_unit_SOURCES = test/tcti-uefi-finalize_unit.c
endif
# INTEGRATION tests
TEST_EXTENSIONS += .efi
EFI_LOG_COMPILER = $(srcdir)/lib/efi-test-setup.sh
EFI_LOG_FLAGS = --startup-template=$(srcdir)/lib/startup.nsh.template --arch=$(ARCH) --ovmf=$(OVMF_PATH)
tests: $(TEST_INTEGRATION)
if INTEGRATION
TEST_INTEGRATION = \
test/hello-world.efi \
test/tss2-mu-uint32.efi \
test/tss2-getrandom.efi \
example/tcg2-get-caps.efi \
example/tpm2-get-caps-fixed.efi \
example/tpm2-nv-ops.efi \
example/tpm2-get-pcrs.efi \
example/tcg2-get-pcr-banks.efi
# example/tcg2-get-eventlog.efi # not working on ARM UEFI build
TESTS += $(TEST_INTEGRATION)
CLEANS += \
$(TEST_INTEGRATION) \
test/hello-world.so \
test/tss2-mu-uint32.so \
test/tss2-getrandom.so
endif
EXTRA_DIST += \
lib/efi-test-setup.sh \
lib/startup.nsh.template \
test/hello-world.c \
test/tss2-mu-uint32.c \
test/tss2-getrandom.c
test/.deps:
mkdir -p $@
test/hello-world.$(OBJEXT): test/hello-world.c | test/.deps
test/tss2-mu-uint32.$(OBJEXT): test/tss2-mu-uint32.c | test/.deps
test/tss2-getrandom.$(OBJEXT): test/tss2-getrandom.c | test/.deps
test/hello-world.so: CFLAGS+=$(EXTRA_CFLAGS) $(AM_CFLAGS)
test/hello-world.so: LDFLAGS+=-Wl,--no-undefined
test/hello-world.so: test/hello-world.$(OBJEXT)
test/tss2-mu-uint32.so: CFLAGS+=$(EXTRA_CFLAGS) $(AM_CFLAGS)
test/tss2-mu-uint32.so: LDFLAGS+=-Wl,--no-undefined
test/tss2-mu-uint32.so: LDLIBS+=-l:libtss2-mu.a
test/tss2-mu-uint32.so: test/tss2-mu-uint32.$(OBJEXT)
test/tss2-getrandom.so: CFLAGS+=$(EXTRA_CFLAGS) $(AM_CFLAGS)
test/tss2-getrandom.so: LDFLAGS+=-Wl,--no-undefined
test/tss2-getrandom.so: LDLIBS+=-l:libtss2-sys.a -l:libtss2-mu.a
test/tss2-getrandom.so: $(libtss2_tcti_uefi)
test/tss2-getrandom.so: test/tss2-getrandom.$(OBJEXT)
# Build rules for INTEGRATION tests and EXAMPLES
# pattern rule to link intermediate shared object
%.so: %.o
$(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) $^ -o $@ -Bstatic $(LDLIBS) $(EXTRA_LDLIBS)
# pattern to transform intermediate shared object into efi executable
%.efi: %.so
$(OBJCOPY) $(OBJFLAGS) $(EXTRA_OBJFLAGS) $^ $@