1# SPDX-License-Identifier: BSD-2-Clause
2# Copyright (c) 2015 - 2020 Intel Corporation
3# Copyright (c) 2018 - 2020 Fraunhofer SIT sponsored by Infineon Technologies AG
4# All rights reserved.
5
6AC_INIT([tpm2-tss],
7        [3.1.0],
8        [https://github.com/tpm2-software/tpm2-tss/issues],
9        [],
10        [https://github.com/tpm2-software/tpm2-tss])
11AC_CONFIG_MACRO_DIR([m4])
12AM_INIT_AUTOMAKE([foreign
13                  subdir-objects])
14m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) #Backward compatible setting of "silent-rules"
15
16AC_CONFIG_HEADERS([config.h])
17
18AC_CONFIG_FILES([Makefile Doxyfile lib/tss2-sys.pc lib/tss2-esys.pc lib/tss2-mu.pc lib/tss2-tcti-device.pc lib/tss2-tcti-mssim.pc lib/tss2-tcti-swtpm.pc lib/tss2-tcti-pcap.pc lib/tss2-rc.pc lib/tss2-tctildr.pc lib/tss2-fapi.pc lib/tss2-tcti-cmd.pc])
19
20# propagate configure arguments to distcheck
21AC_SUBST([DISTCHECK_CONFIGURE_FLAGS],[$ac_configure_args])
22
23AC_CANONICAL_HOST
24
25AX_IS_RELEASE(dash-version)
26AX_CHECK_ENABLE_DEBUG([info])
27
28AC_PROG_CC
29AC_PROG_CXX
30AC_PROG_LN_S
31AC_USE_SYSTEM_EXTENSIONS
32LT_INIT()
33LT_LIB_DLLOAD
34PKG_INSTALLDIR()
35
36# Check OS and set library and compile flags accordingly
37case "${host_os}" in
38    *nto-qnx*)
39        HOSTOS='QNX'
40        ADD_COMPILER_FLAG([-D_QNX_SOURCE])
41        LIBSOCKET_LDFLAGS="-lsocket"
42        ;;
43    *bsd* | *BSD*)
44        HOSTOS='BSD'
45        LIBSOCKET_LDFLAGS=""
46        ;;
47    *)
48        #Assume linux
49        HOSTOS='Linux'
50        LIBSOCKET_LDFLAGS=""
51        ;;
52esac
53AC_SUBST([LIBSOCKET_LDFLAGS])
54AC_SUBST([HOSTOS])
55
56AM_CONDITIONAL(HOSTOS_LINUX, [test x"$HOSTOS" = xLinux])
57
58# runstatedir is only defined in the yet unreleased Autoconf 2.70
59AC_ARG_WITH([runstatedir],
60            AS_HELP_STRING([--with-runstatedir=<dir>],
61                           [replacement for --runstatedir in Autoconf <2.70]),
62            [runstatedir="$withval"])
63AS_IF([test -z "$runstatedir"], [runstatedir="${localstatedir}/run"])
64AC_SUBST([runstatedir])
65
66AX_RECURSIVE_EVAL([$sysconfdir], [SYSCONFDIR])
67AC_DEFINE_UNQUOTED([SYSCONFDIR], ["$SYSCONFDIR"], [System config dir])
68
69AC_ARG_WITH([userstatedir],
70            [AS_HELP_STRING([--with-userstatedir=<dir>],
71                            [sets the relative path in the user's home (default is ".local/share")])],,
72            [with_userstatedir=.local/share])
73AC_SUBST(userstatedir, $with_userstatedir)
74
75AC_ARG_WITH([sysusersdir],
76            [AS_HELP_STRING([--with-sysusersdir=<dir>],
77                            [sets the sysusers.d directory (default is "${sysconfdir}/sysusers.d")])],,
78            [with_sysusersdir="${sysconfdir}/sysusers.d"])
79AC_SUBST(sysusersdir, $with_sysusersdir)
80
81AC_ARG_WITH([tmpfilesdir],
82            [AS_HELP_STRING([--with-tmpfilesdir=<dir>],
83                            [sets the tmpfiles.d directory (default is "${sysconfdir}/tmpfiles.d")])],,
84            [with_tmpfilesdir="${sysconfdir}/tmpfiles.d"])
85AC_SUBST(tmpfilesdir, $with_tmpfilesdir)
86
87AC_ARG_ENABLE([unit],
88            [AS_HELP_STRING([--enable-unit],
89                            [build cmocka unit tests])],,
90            [enable_unit=no])
91m4_define([cmocka_min_version], [1.0])
92m4_define([cmocka_err], [Unit test enabled, but cmocka missing or version requirements not met. cmocka version must be >= cmocka_min_version])
93AS_IF([test "x$enable_unit" != xno],
94      [PKG_CHECK_MODULES([CMOCKA],
95                         [cmocka >= cmocka_min_version],,
96                         [AC_MSG_ERROR([cmocka_err])])])
97AM_CONDITIONAL([UNIT], [test "x$enable_unit" != xno])
98AS_IF([test "x$enable_unit" != xno],
99    [AC_DEFINE(UNIT, 1, [Enable for UNIT testing])])
100
101AC_ARG_ENABLE([esys],
102            [AS_HELP_STRING([--disable-esys],
103                            [don't build the esys layer])],,
104            [enable_esys=yes])
105
106AM_CONDITIONAL(ESYS, test "x$enable_esys" = "xyes")
107
108AC_CHECK_FUNC([strndup],[],[AC_MSG_ERROR([strndup function not found])])
109AC_CHECK_FUNCS([reallocarray])
110AC_ARG_ENABLE([fapi],
111            [AS_HELP_STRING([--enable-fapi],
112                            [build the fapi layer (default is yes)])],
113            [enable_fapi=$enableval],
114            [enable_fapi=yes])
115
116AM_CONDITIONAL(FAPI, test "x$enable_fapi" = "xyes")
117
118AC_ARG_ENABLE([fapi-async-tests],
119    AS_HELP_STRING([--enable-fapi-async-tests],
120               [Force fapi to spin asynchronously. (NOT FOR PRODUCTION!)]),,
121    [enable_fapi_async_tests=no])
122AS_IF([test "x$enable_fapi_async_tests" = "xyes"],
123    [AC_DEFINE([TEST_FAPI_ASYNC], [1], [FAPI forced async spinning])])
124AS_IF([test "x$enable_fapi_async_tests" = "xyes"],
125    [AC_MSG_WARN("FAPI compiled with asynchronous spinning testing. NOT FOR PRODUCTION!")])
126
127AC_ARG_WITH([crypto],
128            [AS_HELP_STRING([--with-crypto={ossl,mbed}],
129                            [sets the ESYS crypto backend (default is OpenSSL)])],,
130            [with_crypto=ossl])
131
132AM_CONDITIONAL(ESYS_OSSL, test "x$with_crypto" = "xossl")
133AM_CONDITIONAL(ESYS_MBED, test "x$with_crypto" = "xmbed")
134
135AS_IF([test "x$enable_esys" = xyes],
136      [AS_IF([test "x$with_crypto" = xossl], [
137           PKG_CHECK_MODULES([LIBCRYPTO], [libcrypto])
138           AC_DEFINE([OSSL], [1], [OpenSSL cryptographic backend])
139           TSS2_ESYS_CFLAGS_CRYPTO="$LIBCRYPTO_CFLAGS"
140           TSS2_ESYS_LDFLAGS_CRYPTO="$LIBCRYPTO_LIBS"
141       ], [test "x$with_crypto" = xmbed], [
142           AC_CHECK_HEADER(mbedtls/md.h, [], [AC_MSG_ERROR([Missing required mbedTLS library])])
143           AC_DEFINE([MBED], [1], [mbedTLS cryptographic backend])
144           TSS2_ESYS_CFLAGS_CRYPTO="$LIBMBED_CFLAGS"
145           TSS2_ESYS_LDFLAGS_CRYPTO="-lmbedcrypto"
146       ], [AC_MSG_ERROR([Bad value for --with-crypto $with_crypto])])])
147AC_SUBST([TSS2_ESYS_CFLAGS_CRYPTO])
148AC_SUBST([TSS2_ESYS_LDFLAGS_CRYPTO])
149
150AS_IF([test "x$enable_fapi" != xno -a "x$enable_esys" = "xno"],
151    [AC_MSG_ERROR([ESYS has to be enabled to compile FAPI.])])
152
153AS_IF([test "x$enable_fapi" != xno -a "x$with_crypto" != "xossl"],
154    [AC_MSG_ERROR([FAPI has to be compiled with OpenSSL])])
155
156AS_IF([test "x$enable_fapi" = xyes ],
157      [PKG_CHECK_MODULES([JSONC], [json-c])])
158
159AS_IF([test "x$enable_fapi" = xyes ],
160      [PKG_CHECK_MODULES([CURL], [libcurl])])
161
162AC_ARG_WITH([tctidefaultmodule],
163            [AS_HELP_STRING([--with-tctidefaultmodule],
164[The default TCTI module for ESYS. (Default: libtss2-tcti-default.so)])],
165            [AC_DEFINE_UNQUOTED([ESYS_TCTI_DEFAULT_MODULE],
166                                ["$with_tctidefaultmodule"],
167                                ["The default TCTI library file"])],
168	    [with_tctidefaultmodule=libtss2-tcti-default.so])
169
170AC_ARG_WITH([tctidefaultconfig],
171            [AS_HELP_STRING([--with-tctidefaultconfig],
172                            [The default tcti module's configuration.])],
173            [AC_DEFINE_UNQUOTED([ESYS_TCTI_DEFAULT_CONFIG],
174                                ["$with_tctidefaultconfig"],
175                                ["The default TCTIs configuration string"])])
176
177AC_ARG_ENABLE([tcti-device],
178            [AS_HELP_STRING([--disable-tcti-device],
179                            [don't build the tcti-device module])],,
180            [enable_tcti_device=yes])
181AM_CONDITIONAL([ENABLE_TCTI_DEVICE], [test "x$enable_tcti_device" != xno])
182AS_IF([test "x$enable_tcti_device" = "xyes"],
183	[AC_DEFINE([TCTI_DEVICE],[1], [TCTI FOR DEV TPM])])
184
185AC_ARG_ENABLE([tcti-mssim],
186            [AS_HELP_STRING([--disable-tcti-mssim],
187                            [don't build the tcti-mssim module])],,
188            [enable_tcti_mssim=yes])
189AM_CONDITIONAL([ENABLE_TCTI_MSSIM], [test "x$enable_tcti_mssim" != xno])
190AS_IF([test "x$enable_tcti_mssim" = "xyes"],
191	[AC_DEFINE([TCTI_MSSIM],[1], [TCTI FOR MS SIMULATOR])])
192
193AC_ARG_ENABLE([tcti-swtpm],
194            [AS_HELP_STRING([--disable-tcti-swtpm],
195                            [don't build the tcti-swtpm module])],,
196            [enable_tcti_swtpm=yes])
197AM_CONDITIONAL([ENABLE_TCTI_SWTPM], [test "x$enable_tcti_swtpm" != xno])
198AS_IF([test "x$enable_tcti_swtpm" = "xyes"], [AC_DEFINE([TCTI_SWTPM],[1], [TCTI FOR SWTPM])])
199
200AC_ARG_ENABLE([tcti-pcap],
201            [AS_HELP_STRING([--disable-tcti-pcap],
202                            [don't build the tcti-pcap module])],,
203            [enable_tcti_pcap=yes])
204AM_CONDITIONAL([ENABLE_TCTI_PCAP], [test "x$enable_tcti_pcap" != xno])
205
206AC_ARG_ENABLE([tcti-cmd],
207            [AS_HELP_STRING([--disable-tcti-cmd],
208                            [don't build the tcti-cmd module])],,
209            [enable_tcti_cmd=yes])
210
211AM_CONDITIONAL([ENABLE_TCTI_CMD], [test "x$enable_tcti_cmd" != xno])
212AS_IF([test "x$enable_tcti_cmd" = "xyes"],
213	[AC_DEFINE([TCTI_CMD],[1], [TCTI FOR COMMAND BASED ACCESS TO TPM2 DEVICE])])
214
215AC_ARG_ENABLE([tcti-fuzzing],
216            [AS_HELP_STRING([--enable-tcti-fuzzing],
217                            [build the tcti-fuzzing module])],,
218            [enable_tcti_fuzzing=no])
219AM_CONDITIONAL([ENABLE_TCTI_FUZZING], [test "x$enable_tcti_fuzzing" != xno])
220AS_IF([test "x$enable_tcti_fuzzing" = "xyes"],
221	[AC_DEFINE([TCTI_FUZZING],[1], [TCTI FOR FUZZING])])
222
223AC_ARG_ENABLE([nodl],
224              [AS_HELP_STRING([--enable-nodl],
225                              [link against TCTIs directly, do not use dlopen])],
226              [],
227              [enable_nodl=no])
228AM_CONDITIONAL([NO_DL], [test "x$enable_nodl" = "xyes"])
229AS_IF([test "x$enable_nodl" = "xyes"],
230      [AC_DEFINE([NO_DL],[1], [disable use of dlopen])])
231
232#
233# udev
234#
235AC_ARG_WITH([udevrulesdir],
236            [AS_HELP_STRING([--with-udevrulesdir=DIR],[udev rules directory])],,
237            [with_udevrulesdir=${libdir}/udev/rules.d])
238AX_NORMALIZE_PATH([with_udevrulesdir])
239AC_SUBST([udevrulesdir], [$with_udevrulesdir])
240AC_ARG_WITH([udevrulesprefix],
241            [AS_HELP_STRING([--with-udevrulesprefix=XY],[prefix for udev rules file])],
242            [AC_SUBST([udevrulesprefix],[$with_udevrulesprefix])])
243AM_CONDITIONAL(WITH_UDEVRULESPREFIX, [test -n "$with_udevrulesprefix"])
244
245dnl ---------  Physical TPM device for testing -----------------------
246
247AC_ARG_WITH([device],
248            [AS_HELP_STRING([--with-device=<device>],[TPM device for testing])],
249            [AS_IF([test \( -w "$with_device" \)  -a \( -r "$with_device" \)],
250                   [AC_MSG_RESULT([success])
251                    AX_NORMALIZE_PATH([with_device])
252                    with_device_set=yes],
253                   [AC_MSG_ERROR([TPM device provided does not exist or is not writable])])],
254            [with_device_set=no])
255AM_CONDITIONAL([TESTDEVICE],[test "x$with_device_set" = xyes])
256
257AC_ARG_WITH([devicetests],
258            [AS_HELP_STRING([--with-devicetests=<case>],[Comma-separated values of possible tests: destructive,mandatory,optional] default is mandatory)],
259            [AS_IF([test "x" =  x$(echo $with_devicetests | sed 's/destructive//g'  | sed 's/mandatory//g'  | sed 's/optional//g' | sed 's/,//g') ],
260                   [AC_MSG_RESULT([success])
261                    with_devicetests_set=yes],
262                   [AC_MSG_ERROR([Illegal test type for device tests.])])],
263            [with_devicetests="mandatory"])
264
265if echo $with_devicetests | grep destructive > /dev/null; then
266    enable_device_destructive="yes"
267fi
268AM_CONDITIONAL([DEVICEDESTRUCTIVE],[test "x$enable_device_destructive" = "xyes"])
269
270if echo $with_devicetests | grep optional > /dev/null; then
271    enable_device_optional="yes"
272fi
273AM_CONDITIONAL([DEVICEOPTIONAL],[test "x$enable_device_optional" = "xyes"])
274
275if echo $with_devicetests | grep mandatory > /dev/null; then
276    enable_device_mandatory="yes"
277fi
278AM_CONDITIONAL([DEVICEMANDATORY],[test "x$enable_device_mandatory" = "xyes"])
279
280#
281# enable integration tests and check for simulator binary
282#
283AC_ARG_ENABLE([integration],
284    [AS_HELP_STRING([--enable-integration],
285        [build and execute integration tests])],,
286    [enable_integration=no])
287AS_IF([test "x$enable_integration" = "xyes"],
288     [AS_IF([test "$HOSTOS" = "Linux"],
289           [ERROR_IF_NO_PROG([ss])],
290           [ERROR_IF_NO_PROG([sockstat])])
291       ERROR_IF_NO_PROG([echo])
292       ERROR_IF_NO_PROG([kill])
293       ERROR_IF_NO_PROG([stdbuf])
294       ERROR_IF_NO_PROG([sleep])
295       ERROR_IF_NO_PROG([cat])
296       ERROR_IF_NO_PROG([realpath])
297       ERROR_IF_NO_PROG([dirname])
298       ERROR_IF_NO_PROG([basename])
299       ERROR_IF_NO_PROG([mktemp])
300       ERROR_IF_NO_PROG([od])
301       ERROR_IF_NO_PROG([awk])
302       ERROR_IF_NO_PROG([expr])
303       ERROR_IF_NO_PROG([grep])
304       ERROR_IF_NO_PROG([env])
305       ERROR_IF_NO_PROG([rm])
306       AS_IF([test "x$with_crypto" != xossl -o "x$enable_esys" != xyes],
307           [PKG_CHECK_MODULES([LIBCRYPTO],[libcrypto])])
308       AC_CHECK_HEADER(uthash.h, [], [AC_MSG_ERROR([Can not find uthash.h. Please install uthash-dev])])
309
310       # choose tcti for testing and look for TPM simulator binary
311       integration_tcti="none"
312       integration_args=""
313       AS_IF([test "x$with_device_set" = xyes],
314             [# use device if --with-device was passed
315              integration_tcti=device
316              integration_args="--device=$with_device"
317              AC_MSG_WARN([Using physical TPM for integration testing])])
318       AS_IF([test "x$integration_tcti" = "xnone" && test "x$enable_tcti_swtpm" != xyes && test "x$enable_tcti_mssim" != xyes],
319             [AC_MSG_ERROR([No suitable TCTI for testing enabled. Please use option --enable-tcti-swtpm (recommended) or --enable-tcti-mssim (fallback) to enable a suitable TCTI or disable testing with --disable-integration.])])
320       AS_IF([test "x$integration_tcti" = "xnone" && test "x$enable_tcti_swtpm" = "xyes"],
321             [# check for swtpm binary
322              AC_CHECK_PROG([result_swtpm], [swtpm], [yes], [no])
323              AS_IF([test "x$result_swtpm" = "xyes"],
324                    [integration_tcti=swtpm],
325                    [AC_MSG_WARN([Executable swtpm not found in PATH.])])])
326       AS_IF([test "x$integration_tcti" = "xnone" && test "x$enable_tcti_mssim" = "xyes"],
327             [# check for mssim binary
328              AC_MSG_NOTICE([Falling back to testing with tcti-mssim.])
329              AC_CHECK_PROG([result_tpm_server], [tpm_server], [yes], [no])
330              AS_IF([test "x$result_tpm_server" = "xyes"],
331                    [integration_tcti=mssim
332                     AC_DEFINE([INTEGRATION_TCTI_MSSIM], [1], [use mssim TCTI for integration tests])],
333                    [AC_MSG_WARN([Executable tpm_server not found in PATH (fallback)])])])
334       AS_IF([test "x$integration_tcti" = "xnone"],
335             [AC_MSG_ERROR([No simulator executable found in PATH for testing TCTI.])])
336       AC_SUBST([INTEGRATION_TCTI], [$integration_tcti])
337       AC_SUBST([INTEGRATION_ARGS], [$integration_args])
338       AC_SUBST([ENABLE_INTEGRATION], [$enable_integration])])
339AM_CONDITIONAL([ENABLE_INTEGRATION],[test "x$enable_integration" = "xyes"])
340#
341# sanitizer compiler flags
342#
343AC_ARG_WITH([sanitizer],
344            [AS_HELP_STRING([--with-sanitizer={none,address,undefined}],
345                            [build with the given sanitizer])],,
346            [with_sanitizer=none])
347AS_CASE(["x$with_sanitizer"],
348        ["xnone"],
349        [],
350        ["xaddress"],
351        [
352            SANITIZER_CFLAGS="-fsanitize=address -fno-omit-frame-pointer"
353            SANITIZER_LDFLAGS="-lasan"
354        ],
355        ["xundefined"],
356        [
357            SANITIZER_CFLAGS="-fsanitize=undefined"
358            SANITIZER_LDFLAGS="-lubsan"
359        ],
360        ["xundefined,address"],
361        [
362            SANITIZER_CFLAGS="-fsanitize=undefined,address -fno-omit-frame-pointer"
363            SANITIZER_LDFLAGS="-lasan -lubsan"
364        ],
365        [AC_MSG_ERROR([Bad value for --with-sanitizer])])
366AC_SUBST([SANITIZER_CFLAGS])
367AC_SUBST([SANITIZER_LDFLAGS])
368#
369# fuzz testing
370#
371AC_ARG_WITH([fuzzing],
372            [AS_HELP_STRING([--with-fuzzing={none,libfuzzer,ossfuzz}],
373                            [fuzzing to build with (default is none)])],,
374            [with_fuzzing=none])
375AS_CASE(["x$with_fuzzing"],
376        ["xnone"],
377        [],
378        ["xlibfuzzer"],
379        [ADD_FUZZING_FLAG([-fsanitize=fuzzer])],
380        ["xossfuzz"],
381        [AS_IF([test "x$LIB_FUZZING_ENGINE" = "x"],
382               [AC_MSG_ERROR([OSS Fuzz testing requires LIB_FUZZING_ENGINE environment variable be set])])
383         ADD_FUZZING_FLAG([-lFuzzingEngine])],
384        [AC_MSG_ERROR([Bad value for --with-fuzzing])])
385AM_CONDITIONAL([ENABLE_FUZZING],[test "x$with_fuzzing" != "xnone"])
386AS_IF([test "x$with_fuzzing" != "xnone"],
387      [AS_IF([test "x$enable_tcti_fuzzing" = xno],
388             [AC_MSG_ERROR([Fuzz tests can not be enabled without the TCTI_FUZZING module])])
389       AS_IF([test "x$GEN_FUZZ" != "x1"],
390             [AC_MSG_ERROR([Fuzz tests can not be enabled without "GEN_FUZZ=1" variable])])])
391
392AX_VALGRIND_CHECK
393
394gl_LD_VERSION_SCRIPT
395
396AC_ARG_ENABLE([log-file],
397            [AS_HELP_STRING([--disable-log-file],
398                            [write logging to stderr only])],,
399            [enable_log_file=yes])
400AS_IF([test "x$enable_log_file" != xno],
401	[AC_DEFINE([LOG_FILE_ENABLED],[1], [Support for writing to a log file is enabled])])
402
403AC_ARG_WITH([maxloglevel],
404            [AS_HELP_STRING([--with-maxloglevel={none,error,warning,info,debug,trace}],
405                            [sets the maximum log level (default is trace)])],,
406            [with_maxloglevel=trace])
407AS_CASE(["x$with_maxloglevel"],
408        ["xnone"],
409        [AC_DEFINE_UNQUOTED([MAXLOGLEVEL], [0], ["Logging disabled"])],
410        ["xerror"],
411        [AC_DEFINE_UNQUOTED([MAXLOGLEVEL], [2], ["Error log level"])],
412        ["xwarning"],
413        [AC_DEFINE_UNQUOTED([MAXLOGLEVEL], [3], ["Warning log level"])],
414        ["xinfo"],
415        [AC_DEFINE_UNQUOTED([MAXLOGLEVEL], [4], ["Info log level"])],
416        ["xdebug"],
417        [AC_DEFINE_UNQUOTED([MAXLOGLEVEL], [5], ["Debug log level"])],
418        ["xtrace"],
419        [AC_DEFINE_UNQUOTED([MAXLOGLEVEL], [6], ["Trace log level"])],
420        [AC_MSG_ERROR([Bad value for --with-maxloglevel])])
421
422AC_ARG_ENABLE([defaultflags],
423              [AS_HELP_STRING([--disable-defaultflags],
424                              [Disable default preprocessor, compiler, and linker flags.])],,
425              [enable_defaultflags=yes])
426AS_IF([test "x$enable_defaultflags" = "xyes"],
427      [
428      AS_IF([test "x$enable_debug" = "xno"],
429            [ADD_COMPILER_FLAG([-O2])
430             AX_ADD_FORTIFY_SOURCE])
431      ADD_COMPILER_FLAG([-std=c99])
432      ADD_COMPILER_FLAG([-Wall])
433      ADD_COMPILER_FLAG([-Wextra])
434      ADD_COMPILER_FLAG([-Wformat-security])
435      AS_IF([test "x$ax_is_release" = "xno"],
436          [ADD_COMPILER_FLAG([-Werror])])
437      ADD_COMPILER_FLAG([-fstack-protector-all])
438      ADD_COMPILER_FLAG([-fpic])
439      ADD_COMPILER_FLAG([-fPIC])
440      # work around GCC bug #53119
441      #   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
442      ADD_COMPILER_FLAG([-Wno-missing-braces])
443      ADD_COMPILER_FLAG([-Wstrict-overflow=5])
444      ADD_LINK_FLAG([-Wl,--no-undefined])
445      ADD_LINK_FLAG([-Wl,-z,noexecstack])
446      ADD_LINK_FLAG([-Wl,-z,now])
447      ADD_LINK_FLAG([-Wl,-z,relro])
448      ])
449
450AC_ARG_ENABLE([weakcrypto],
451    [AS_HELP_STRING([--disable-weakcrypto],
452	           [Disable crypto algorithms considered weak])],,
453    [enable_weakcrypto=no])
454AS_IF([test "x$enable_weakcrypto" = "xyes"],
455	[AC_DEFINE([DISABLE_WEAK_CRYPTO],[1],[DISABLE WEAK CRYPTO ALGORITHMS])])
456
457AC_ARG_ENABLE([self-generated-certificate],
458            [AS_HELP_STRING([--enable-self-generated-certificate],
459                            [Alllow usage of self generated root certifcate])],,
460            [enable_self_generated_certificate=no])
461AS_IF([test "x$enable_self_generated_certificate" = xyes],
462	[AC_DEFINE([SELF_GENERATED_CERTIFICATE], [1], [Allow usage of self generated root certificate])],
463	[AS_IF([test "x$integration_tcti" != "xdevice"], [AC_DEFINE([FAPI_TEST_EK_CERT_LESS], [1], [Perform integration tests without EK certificate verification])])])
464
465AS_IF([test "x$enable_integration" = "xyes" && test "x$enable_self_generated_certificate" != "xyes" && test "x$integration_tcti" != "xdevice"],
466      [AC_MSG_WARN([Running integration tests without EK certificate verification, use --enable-self-generated-certificate for full test coverage])])
467
468# Check for systemd helper tools used by make install
469AC_CHECK_PROG(systemd_sysusers, systemd-sysusers, yes)
470AM_CONDITIONAL(SYSD_SYSUSERS, test "x$systemd_sysusers" = "xyes")
471AC_CHECK_PROG(systemd_tmpfiles, systemd-tmpfiles, yes)
472AM_CONDITIONAL(SYSD_TMPFILES, test "x$systemd_tmpfiles" = "xyes")
473# Check all tools used by make install
474AS_IF([test "$HOSTOS" = "Linux"],
475      [ERROR_IF_NO_PROG([groupadd])
476       ERROR_IF_NO_PROG([useradd])
477       ERROR_IF_NO_PROG([id])
478       ERROR_IF_NO_PROG([chown])
479       ERROR_IF_NO_PROG([chmod])
480       ERROR_IF_NO_PROG([mkdir])
481       ERROR_IF_NO_PROG([setfacl])])
482
483AC_SUBST([PATH])
484
485dnl --------- Doxy Gen -----------------------
486DX_DOXYGEN_FEATURE(ON)
487DX_DOT_FEATURE(OFF)
488DX_HTML_FEATURE(ON)
489DX_CHM_FEATURE(OFF)
490DX_CHI_FEATURE(OFF)
491DX_MAN_FEATURE(ON)
492DX_RTF_FEATURE(ON)
493DX_XML_FEATURE(OFF)
494DX_PDF_FEATURE(OFF)
495DX_PS_FEATURE(OFF)
496DX_INIT_DOXYGEN($PACKAGE_NAME, [Doxyfile], [doxygen-doc])
497
498AM_CONDITIONAL(DOXYMAN, [test $DX_FLAG_doc -eq 1])
499AS_IF([test $DX_FLAG_doc -ne 1],
500	[AS_IF([test "x$enable_doxygen_doc" = xyes],
501                     [ERROR_IF_NO_PROG([doxygen])])])
502
503AX_CODE_COVERAGE
504m4_ifdef([_AX_CODE_COVERAGE_RULES],
505         [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],
506         [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
507AX_ADD_AM_MACRO_STATIC([])
508
509AM_COND_IF([ENABLE_TCTI_DEVICE], [],
510           [AM_COND_IF([ENABLE_TCTI_MSSIM], [],
511                       [AM_COND_IF([ENABLE_TCTI_SWTPM], [],
512                                   [AM_COND_IF([ENABLE_TCTI_FUZZING], [],
513                                               [AC_MSG_WARN("No build-in TCTI module enabled")])])])])
514
515AM_COND_IF([ENABLE_TCTI_FUZZING], [
516            AM_COND_IF([ENABLE_TCTI_DEVICE],
517                       AC_MSG_ERROR([Fuzzing TCTI is meant to be built as the only TCTI: use --disable-tcti-device --disable-tcti-mssim --disable-tcti-swtpm]))
518            AM_COND_IF([ENABLE_TCTI_MSSIM],
519                       AC_MSG_ERROR([Fuzzing TCTI is meant to be built as the only TCTI: use --disable-tcti-device --disable-tcti-mssim --disable-tcti-swtpm]))
520            AM_COND_IF([ENABLE_TCTI_SWTPM],
521                       AC_MSG_ERROR([Fuzzing TCTI is meant to be built as the only TCTI: use --disable-tcti-device --disable-tcti-mssim --disable-tcti-swtpm]))
522            AS_CASE([$CC],
523                    [*clang*], [AC_MSG_NOTICE("Building fuzzing tests with $CC")],
524                    [AC_MSG_ERROR("Fuzzing TCTI can only be used with clang")])
525            ], [])
526
527AC_OUTPUT
528
529AC_MSG_RESULT([
530    $PACKAGE_NAME $VERSION
531    esys:               $enable_esys
532    fapi:               $enable_fapi
533    tctidefaultmodule:  $with_tctidefaultmodule
534    tctidefaultconfig:  $with_tctidefaultconfig
535    unit:               $enable_unit
536    integration:        $enable_integration
537    testing backend:    $integration_tcti
538    fuzzing:            $with_fuzzing
539    debug:              $enable_debug
540    maxloglevel:        $with_maxloglevel
541    doxygen:            $DX_FLAG_doc $enable_doxygen_doc
542    crypto backend:     $with_crypto
543    sysconfdir:         $sysconfdir
544    localstatedir:      $localstatedir
545    runstatedir:        $runstatedir
546    sysusersdir:        $sysusersdir
547    tmpfilesdir:        $tmpfilesdir
548    userstatedir:       [\$HOME/]$with_userstatedir
549])
550