forked from stefanberger/swtpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.ac
554 lines (494 loc) · 15.9 KB
/
configure.ac
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
#
# configure.ac
#
# The Initial Developer of the Original Code is International
# Business Machines Corporation. Portions created by IBM
# Corporation are Copyright (C) 2014 International Business
# Machines Corporation. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the Common Public License as published by
# IBM Corporation; either version 1 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# Common Public License for more details.
#
# You should have received a copy of the Common Public License
# along with this program; if not, a copy can be viewed at
# http://www.opensource.org/licenses/cpl1.0.php.
#
# This file is derived from tpm-tool's configure.in.
#
AC_INIT(swtpm, 0.4.0)
AC_PREREQ(2.12)
AC_CONFIG_SRCDIR(Makefile.am)
AC_CONFIG_HEADER(config.h)
SWTPM_VER_MAJOR=`echo $PACKAGE_VERSION | cut -d "." -f1`
SWTPM_VER_MINOR=`echo $PACKAGE_VERSION | cut -d "." -f2`
SWTPM_VER_MICRO=`echo $PACKAGE_VERSION | cut -d "." -f3`
AC_SUBST([SWTPM_VER_MAJOR])
AC_SUBST([SWTPM_VER_MINOR])
AC_SUBST([SWTPM_VER_MICRO])
dnl Check for programs
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
LT_INIT
AC_CONFIG_MACRO_DIR([m4])
AC_CANONICAL_TARGET
AC_CANONICAL_HOST
AM_INIT_AUTOMAKE([foreign 1.6])
AM_SILENT_RULES([yes])
DEBUG=""
AC_MSG_CHECKING([for debug-enabled build])
AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [create a debug build]),
[if test "$enableval" = "yes"; then
DEBUG="yes"
AC_MSG_RESULT([yes])
else
DEBUG="no"
AC_MSG_RESULT([no])
fi],
[DEBUG="no",
AC_MSG_RESULT([no])])
# If the user has not set CFLAGS, do something appropriate
test_CFLAGS=${CFLAGS+set}
if test "$test_CFLAGS" != set; then
if test "$DEBUG" = "yes"; then
CFLAGS="-O0 -g -DDEBUG"
else
CFLAGS="-g -O2"
fi
elif test "$DEBUG" = "yes"; then
CFLAGS="$CFLAGS -O0 -g -DDEBUG"
fi
AC_HEADER_STDC
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
AC_TYPE_SIGNAL
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_MKDIR_P
AC_ARG_WITH([selinux],
AS_HELP_STRING([--with-selinux],
[add SELinux policy extensions @<:@default=check@:>@]))
m4_divert_text([DEFAULTS], [with_selinux=check])
dnl Check for SELinux policy support
if test "$with_selinux" != "no"; then
if test "$with_selinux" = "check" || test "$with_selinux" = "yes"; then
if ! test -f /usr/share/selinux/devel/Makefile; then
if test "$with_selinux" = "yes"; then
AC_MSG_ERROR("Is selinux-policy-devel installed?")
else
with_selinux="no"
fi
fi
AC_PATH_PROG([SEMODULE], semodule)
if test "x$SEMODULE" = "x"; then
if test "$with_selinux" = "yes"; then
AC_MSG_ERROR("Is selinux-policy-devel installed?")
else
with_selinux="no"
fi
fi
if test "$with_selinux" = "check"; then
with_selinux="yes"
fi
fi
fi
AM_CONDITIONAL([WITH_SELINUX], [test "x$with_selinux" = "xyes"])
if test "$prefix" = "/usr" && test "$sysconfdir" = '${prefix}/etc'; then
sysconfdir="/etc"
fi
if test "$prefix" = "" && test "$datarootdir" = '${prefix}/share'; then
datarootdir="/usr/share"
fi
if test "$prefix" = "/usr" && test "$localstatedir" = '${prefix}/var'; then
localstatedir="/var"
fi
if test "x$prefix" = "xNONE"; then
prefix="/usr/local"
fi
SYSCONFDIR=`eval echo $sysconfdir`
DATAROOTDIR=`eval echo $datarootdir`
LOCALSTATEDIR=`eval echo $localstatedir`
AC_SUBST([SYSCONFDIR])
AC_SUBST([DATAROOTDIR])
AC_SUBST([LOCALSTATEDIR])
cryptolib=openssl
AC_ARG_WITH([openssl],
[AS_HELP_STRING([--with-openssl],
[build with openssl library])],
[],
[])
case "$cryptolib" in
openssl)
AC_CHECK_LIB(crypto,
[AES_set_encrypt_key],
[true],
AC_MSG_ERROR(Faulty openssl crypto library))
AC_CHECK_HEADERS([openssl/aes.h],[],
AC_MSG_ERROR(Is openssl-devel/libssl-dev installed?))
AC_MSG_RESULT([Building with openssl crypto library])
LIBCRYPTO_LIBS=$(pkg-config --libs libcrypto)
AC_SUBST([LIBCRYPTO_LIBS])
;;
esac
LIBTASN1_LIBS=$(pkg-config --libs libtasn1)
if test $? -ne 0; then
AC_MSG_ERROR("Is libtasn1-devel installed? -- could not get libs for libtasn1")
fi
AC_SUBST([LIBTASN1_LIBS])
PKG_CHECK_MODULES(
[LIBTPMS],
[libtpms],
,
AC_MSG_ERROR("no libtpms.pc found; please set PKG_CONFIG_PATH to the directory where libtpms.pc is located")
)
LDFLAGS="$LDFLAGS $LIBTPMS_LDFLAGS"
CFLAGS="$CFLAGS $LIBTPMS_CFLAGS"
AC_CHECK_LIB(tpms,
TPMLIB_ChooseTPMVersion,[true],
AC_MSG_ERROR("libtpms 0.6 or later is required")
)
AC_SUBST([LIBTPMS_LIBS])
AC_CHECK_LIB(c, clock_gettime, LIBRT_LIBS="", LIBRT_LIBS="-lrt")
AC_SUBST([LIBRT_LIBS])
AC_PATH_PROG([TPM_NVDEFINE], tpm_nvdefine)
if test "x$TPM_NVDEFINE" = "x"; then
have_tcsd=no
AC_MSG_WARN([NVRAM area tools are needed for TPM 1.2 certificate injection: tpm-tools package])
else
have_tcsd=yes
fi
with_swtpm_setup=yes
AM_CONDITIONAL([HAVE_TCSD], test "$have_tcsd" != "no")
dnl If we have the tcsd package, we can build swtpm_setup, but need netstat also
AC_PATH_PROG([NETSTAT], [netstat])
case $host_os in
linux-*)
if test "x$NETSTAT" = "x" && test "$have_tcsd" != "no"; then
AC_MSG_ERROR([netstat tool is missing for tests: net-tools package])
fi
;;
esac
AC_MSG_CHECKING([for whether to build with CUSE interface])
AC_ARG_WITH([cuse],
AC_HELP_STRING([--with-cuse],
[build with CUSE interface]),
[],
[with_cuse=check]
)
if test "$with_cuse" != "no"; then
LIBFUSE_CFLAGS=$(pkg-config fuse --cflags 2>/dev/null)
if test $? -ne 0; then
if test "$with_cuse" = "yes"; then
AC_MSG_ERROR("Is fuse-devel installed? -- could not get cflags for libfuse")
else
with_cuse=no
fi
else
with_cuse=yes
fi
fi
dnl with_cuse is now yes or no
if test "$with_cuse" != "no"; then
LIBFUSE_LIBS=$(pkg-config fuse --libs)
if test $? -ne 0; then
AC_MSG_ERROR("Is fuse-devel installed? -- could not get libs for libfuse")
fi
AC_SUBST([LIBFUSE_CFLAGS])
AC_SUBST([LIBFUSE_LIBS])
AC_DEFINE_UNQUOTED([WITH_CUSE], 1,
[whether to build with CUSE interface])
GLIB_CFLAGS=$(pkg-config --cflags glib-2.0)
if test $? -ne 0; then
AC_MSG_ERROR("Is glib-2.0 installed? -- could not get cflags")
fi
AC_SUBST([GLIB_CFLAGS])
GLIB_LIBS=$(pkg-config --libs glib-2.0)
if test $? -ne 0; then
AC_MSG_ERROR("Is glib-2.0 installed? -- could not get libs")
fi
AC_SUBST([GLIB_LIBS])
GTHREAD_LIBS=$(pkg-config --libs gthread-2.0)
if test $? -ne 0; then
AC_MSG_ERROR("Is glib-2.0 installed? -- could not get libs for gthread-2.0")
fi
AC_SUBST([GTHREAD_LIBS])
fi
AM_CONDITIONAL([WITH_CUSE],[test "$with_cuse" = "yes"])
AC_MSG_RESULT($with_cuse)
AC_MSG_CHECKING([for whether to build with chardev interface])
case $host_os in
linux-*)
with_chardev=yes
AC_DEFINE_UNQUOTED([WITH_CHARDEV], 1,
[whether to build with chardev interface])
;;
*)
with_chardev=no
esac
AM_CONDITIONAL([WITH_CHARDEV],[test "$with_chardev" = "yes"])
AC_MSG_RESULT($with_cuse)
AC_ARG_WITH([gnutls],
AC_HELP_STRING([--with-gnutls],
[build with gnutls library]),
[],
[with_gnutls=check]
)
if test "x$with_gnutls" != "xno"; then
GNUTLS_LDFLAGS=$(pkg-config --libs gnutls)
if test $? -ne 0; then
if test "x$with_gnutls" = "xyes"; then
AC_MSG_ERROR("Is gnutls installed? -- could not get libs for gnutls")
else
with_gnutls=no
fi
fi
fi
if test "x$with_gnutls" != "xno"; then
AC_PATH_PROG([GNUTLS_CERTTOOL], certtool)
if test "x$GNUTLS_CERTTOOL" = "x"; then
if test "x$with_gnutls" = "xyes"; then
AC_MSG_ERROR("Could not find certtool. Is gnutls-utils/gnutls-bin installed?")
else
with_gnutls=no
fi
fi
fi
if test "x$with_gnutls" != "xno"; then
ORIG_CFLAGS="$CFLAGS"
GNUTLS_CFLAGS=$(pkg-config gnutls --cflags)
CFLAGS="$CFLAGS $GNUTLS_CFLAGS $GNUTLS_LDFLAGS"
AC_CHECK_LIB([gnutls], [gnutls_load_file], [
GNUTLS_LIBS=-lgnutls
],
[if test "x$with_gnutls" = "xyes"; then
AC_MSG_ERROR([GNUTLS >= 3.1.0 library not found: libgnutls.so])
else
with_gnutls="no"
fi])
CFLAGS="$ORIG_CFLAGS"
fi
if test "x$with_gnutls" != "xno"; then
ORIG_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $GNUTLS_CFLAGS"
AC_CHECK_HEADER(gnutls/abstract.h, [], \
[if test "x$with_gnutls" = "xyes"; then
AC_MSG_ERROR([GNUTLS >= 3.1.0 library header not found: gnutls/abstract.h])
else
with_gnutls="no"
fi])
CFLAGS="$ORIG_CFLAGS"
fi
if test "x$with_gnutls" != "xno"; then
with_gnutls="yes"
fi
AM_CONDITIONAL([WITH_GNUTLS], [test "x$with_gnutls" = "xyes"])
AC_SUBST([GNUTLS_LIBS])
AC_PATH_PROG([EXPECT], expect)
if test "x$EXPECT" = "x"; then
AC_MSG_ERROR([expect is required: expect package])
fi
AC_PATH_PROG([GAWK], gawk)
if test "x$GAWK" = "x"; then
AC_MSG_ERROR([gawk is required: gawk package])
fi
AC_PATH_PROG([SOCAT], socat)
if test "x$SOCAT" = "x"; then
AC_MSG_ERROR([socat is required: socat package])
fi
AC_PATH_PROG([PYTHON], python3)
if test "x$PYTHON" = "x"; then
AC_MSG_ERROR([python3 is required])
fi
AC_ARG_ENABLE([hardening],
AS_HELP_STRING([--disable-hardening], [Disable hardening flags]))
if test "x$enable_hardening" != "xno"; then
TMP="$($CC -fstack-protector-strong $srcdir/include/swtpm/tpm_ioctl.h 2>&1)"
if echo $TMP | $GREP 'unrecognized command line option' >/dev/null; then
HARDENING_CFLAGS="-fstack-protector -Wstack-protector "
else
HARDENING_CFLAGS="-fstack-protector-strong -Wstack-protector "
fi
dnl Must not have -O0 but must have a -O for -D_FORTIFY_SOURCE=2
TMP1="$(echo $CFLAGS | sed -n 's/.*\(-O0\).*/\1/p')"
TMP2="$(echo $CFLAGS | sed -n 's/.*\(-O\).*/\1/p')"
if test -z "$TMP1" && test -n "$TPM2"; then
HARDENING_CFLAGS="$HARDENING_CFLAGS -D_FORTIFY_SOURCE=2 "
fi
dnl Check linker for 'relro' and 'now'
save_CFLAGS="$CFLAGS"
CFLAGS="-Wl,-z,relro -Werror"
AC_MSG_CHECKING([whether linker supports -Wl,-z,relro])
AC_COMPILE_IFELSE(
[AC_LANG_SOURCE([[int main() { return 0; }]])],
[HARDENING_CFLAGS="$HARDENING_CFLAGS -Wl,-z,relro"
AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)]
)
CFLAGS="-Wl,-z,now -Werror"
AC_MSG_CHECKING([whether linker supports -Wl,-z,now])
AC_COMPILE_IFELSE(
[AC_LANG_SOURCE([[int main() { return 0; }]])],
[HARDENING_CFLAGS="$HARDENING_CFLAGS -Wl,-z,now"
AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)]
)
CFLAGS="$save_CFLAGS"
AC_SUBST([HARDENING_CFLAGS])
fi
AC_ARG_ENABLE([test-coverage],
AS_HELP_STRING([--enable-test-coverage], [Enable test coverage flags]))
if test "x$enable_test_coverage" = "xyes"; then
COVERAGE_CFLAGS="-fprofile-arcs -ftest-coverage"
COVERAGE_LDFLAGS="-fprofile-arcs"
fi
AC_ARG_WITH([tss-user],
AC_HELP_STRING([--with-tss-user=TSS_USER],
[The tss user to use]),
[TSS_USER="$withval"],
[TSS_USER="tss"]
)
AC_ARG_WITH([tss-group],
AC_HELP_STRING([--with-tss-group=TSS_GROUP],
[The tss group to use]),
[TSS_GROUP="$withval"],
[TSS_GROUP="tss"]
)
case $have_tcsd in
yes)
AC_MSG_CHECKING([whether TSS_USER $TSS_USER is available])
if ! test $(id -u $TSS_USER); then
AC_MSG_ERROR(["$TSS_USER is not available"])
else
AC_MSG_RESULT([yes])
fi
AC_MSG_CHECKING([whether TSS_GROUP $TSS_GROUP is available])
if ! test $(id -g $TSS_GROUP); then
AC_MSG_ERROR(["$TSS_GROUP is not available"])
else
AC_MSG_RESULT([yes])
fi
;;
esac
AC_SUBST([TSS_USER])
AC_SUBST([TSS_GROUP])
CFLAGS="$CFLAGS -Wreturn-type -Wsign-compare -Wswitch-enum"
CFLAGS="$CFLAGS -Wmissing-prototypes -Wall -Werror"
CFLAGS="$CFLAGS -Wformat -Wformat-security"
CFLAGS="$CFLAGS $GNUTLS_CFLAGS $COVERAGE_CFLAGS"
LDFLAGS="$LDFLAGS $COVERAGE_LDFLAGS"
dnl Simulate the following for systems with pkg-config < 0.28:
dnl PKG_CHECK_VAR([libtpms_cryptolib], [libtpms], [cryptolib],
dnl [], AC_MSG_ERROR([Could not determine libtpms crypto library.]))
PKG_PROG_PKG_CONFIG
AC_MSG_CHECKING([Checking the crypto library libtpms is linked to])
libtpms_cryptolib=`$PKG_CONFIG --variable cryptolib libtpms`
if test "x$libtpms_cryptolib" = "x"; then
AC_MSG_WARN([Could not determine the crypto library libtpms is using, assuming ${cryptolib}])
libtpms_cryptolib=${cryptolib}
fi
AC_MSG_RESULT($libtpms_cryptolib)
if test "$libtpms_cryptolib" != "$cryptolib"; then
echo "libtpms is using $libtpms_cryptolib; we have to use the same"
if test "$cryptolib" = "openssl"; then
AC_MSG_ERROR([do not use --with-openssl])
else
AC_MSG_ERROR([use --with-openssl])
fi
fi
with_vtpm_proxy=no
case $host_os in
linux-*)
with_vtpm_proxy=yes
AC_DEFINE_UNQUOTED([WITH_VTPM_PROXY], 1,
[whether to build in vTPM proxy support (Linux only)])
esac
case $host_os in
cygwin)
CFLAGS="$CFLAGS -D__USE_LINUX_IOCTL_DEFS"
esac
dnl Seccomp profile using -lseccomp (Linux only)
case $host_os in
linux-*)
with_seccomp_default=yes
;;
*)
with_seccomp_default=no
;;
esac
AC_MSG_CHECKING([for whether to build with seccomp profile])
AC_ARG_WITH([seccomp],
AC_HELP_STRING([--with-seccomp],
[build with seccomp profile]),
AC_MSG_RESULT([$with_seccomp]),
[with_seccomp=$with_seccomp_default]
AC_MSG_RESULT([$with_seccomp])
)
if test "$with_seccomp" != "no"; then
LIBSECCOMP_CFLAGS=$(pkg-config libseccomp --cflags 2>/dev/null)
if test $? -ne 0; then
AC_MSG_ERROR("Is libseccomp-devel installed? -- could not get cflags for libseccomp")
else
with_libseccomp=yes
fi
LIBSECCOMP_LIBS=$(pkg-config --libs libseccomp)
AC_SUBST([LIBSECCOMP_LIBS])
AC_SUBST([LIBSECCOMP_CFLAGS])
AC_DEFINE_UNQUOTED([WITH_SECCOMP], 1,
[whether to build in seccomp profile (Linux only)])
fi
AC_CONFIG_FILES([Makefile \
debian/swtpm-tools.postinst \
dist/swtpm.spec \
etc/Makefile \
etc/swtpm_setup.conf \
samples/Makefile \
samples/swtpm-localca.conf \
include/Makefile \
include/swtpm/Makefile \
include/swtpm.h \
src/Makefile \
src/selinux/Makefile \
src/swtpm/Makefile \
src/swtpm_bios/Makefile \
src/swtpm_cert/Makefile \
src/swtpm_ioctl/Makefile \
src/swtpm_setup/Makefile \
src/swtpm_setup/swtpm_setup.h \
man/Makefile \
man/man3/Makefile \
man/man8/Makefile \
tests/Makefile \
tests/test_config \
])
AC_CONFIG_FILES([src/swtpm_setup/swtpm_setup.sh],
[chmod 755 src/swtpm_setup/swtpm_setup.sh])
AC_CONFIG_FILES([samples/swtpm-localca],
[chmod 755 samples/swtpm-localca])
AC_OUTPUT
echo
printf "with_gnutls : %5s (no = swtpm_cert will NOT be built)\n" $with_gnutls
printf "with_selinux : %5s (no = SELinux policy extenions will NOT be built)\n" $with_selinux
printf "with_cuse : %5s (no = no CUSE interface)\n" $with_cuse
printf "with_chardev : %5s (no = no chardev interface)\n" $with_chardev
printf "with_swtpm_setup: %5s (no = swtpm_setup will NOT be built)\n" $with_swtpm_setup
printf "with_vtpm_proxy : %5s (no = no vtpm proxy support; Linux only)\n" $with_vtpm_proxy
printf "with_seccomp : %5s (no = no seccomp profile; Linux only)\n" $with_seccomp
echo
echo "cryptolib: $cryptolib"
echo
echo "CFLAGS=$CFLAGS"
echo "HARDENING_CFLAGS=$HARDENING_CFLAGS"
echo "LDFLAGS=$LDFLAGS"
echo "LIBSECCOMP_LIBS=$LIBSECCOMP_LIBS"
echo
echo "TSS_USER=$TSS_USER"
echo "TSS_GROUP=$TSS_GROUP"
echo