forked from tpm2-software/tpm2-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.ac
249 lines (205 loc) · 8.04 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
AC_INIT([tpm2-tools],
[m4_esyscmd_s([git describe --tags --always --dirty])])
AC_CONFIG_MACRO_DIR([m4])
AX_IS_RELEASE([dash-version])
AX_CHECK_ENABLE_DEBUG([info])
AC_PROG_CC
AC_PROG_LN_S
LT_INIT
AM_INIT_AUTOMAKE([foreign
subdir-objects])
# enable "silent-rules" option by default
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
AX_CODE_COVERAGE
m4_ifdef([_AX_CODE_COVERAGE_RULES],
[AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],
[AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
AX_ADD_AM_MACRO_STATIC([])
AC_CONFIG_FILES([Makefile])
# enable autoheader config.h file
AC_CONFIG_HEADERS([lib/config.h])
AC_CHECK_PROG([PANDOC],[pandoc],[yes])
AS_IF(
[test "x${PANDOC}" = x"yes"],
[],
[AC_MSG_WARN([Required executable pandoc not found, man pages will not be built])])
AM_CONDITIONAL([HAVE_PANDOC],[test "x${PANDOC}" = "xyes"])
AM_CONDITIONAL(
[HAVE_MAN_PAGES],
[test -d "${srcdir}/man/man1" -o "x${PANDOC}" = "xyes"])
PKG_CHECK_MODULES([TSS2_ESYS_3_0], [tss2-esys >= 3.0.0],
[AC_DEFINE([ESYS_3_0], [1], [Esys3.0])]
[AC_SUBST([TSS2_ESYS_CFLAGS], [$TSS2_ESYS_3_0_CFLAGS])
AC_SUBST([TSS2_ESYS_LIBS], [$TSS2_ESYS_3_0_LIBS])],
[PKG_CHECK_MODULES([TSS2_ESYS_2_3], [tss2-esys >= 2.3.0],
[AC_DEFINE([ESYS_2_3], [1], [Esys2.3])]
[AC_SUBST([TSS2_ESYS_CFLAGS], [$TSS2_ESYS_2_3_CFLAGS])
AC_SUBST([TSS2_ESYS_LIBS], [$TSS2_ESYS_2_3_LIBS])])])
PKG_CHECK_MODULES([TSS2_TCTILDR], [tss2-tctildr])
PKG_CHECK_MODULES([TSS2_MU], [tss2-mu])
PKG_CHECK_MODULES([TSS2_RC], [tss2-rc])
PKG_CHECK_MODULES([CRYPTO], [libcrypto >= 1.0.2g])
PKG_CHECK_MODULES([CURL], [libcurl])
# backwards compat with older pkg-config
# - pull in AC_DEFUN from pkg.m4
m4_ifndef([PKG_CHECK_VAR], [
# PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
# -------------------------------------------
# Retrieves the value of the pkg-config variable for the given module.
AC_DEFUN([PKG_CHECK_VAR],
[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
_PKG_CONFIG([$1], [variable="][$3]["], [$2])
AS_VAR_COPY([$1], [pkg_cv_][$1])
AS_VAR_IF([$1], [""], [$5], [$4])dnl
])# PKG_CHECK_VAR
])
AC_ARG_WITH([bashcompdir],
AS_HELP_STRING([--with-bashcompdir=DIR], [directory for bash completions]), ,
[PKG_CHECK_VAR([with_bashcompdir], [bash-completion], [completionsdir], ,
[with_bashcompdir="${datarootdir}/bash-completion/completions"])])
AC_SUBST(bashcompdir, [$with_bashcompdir])
AC_CANONICAL_HOST
# Check OS and set library and compile flags accordingly
case "${host_os}" in
*nto-qnx*)
EXTRA_CFLAGS="$EXTRA_CFLAGS -D_QNX_SOURCE"
;;
*)
;;
esac
AC_ARG_ENABLE([unit],
[AS_HELP_STRING([--enable-unit],
[build cmocka unit tests])],,
[enable_unit=no])
AM_CONDITIONAL([UNIT], [test "x$enable_unit" != xno])
dnl macro that checks for specific modules in python
AC_DEFUN([AC_PYTHON_MODULE],
[AC_MSG_CHECKING([for module $1 in python])
echo "import $1" | python - 2>/dev/null
if test $? -ne 0 ; then
AC_MSG_ERROR([not found])
else
AC_MSG_RESULT(found)
fi
])
AS_IF([test "x$enable_unit" != xno], [
PKG_CHECK_MODULES([CMOCKA],[cmocka])
AC_CHECK_PROG([tpm2_abrmd], [tpm2-abrmd], yes, no)
AS_IF([test $tpm2_abrmd = missing],
[AC_MSG_ERROR([Required executable tpm2_abrmd not found, try setting PATH])])
AC_CHECK_PROG([tpm_server], [tpm_server], yes, no)
AS_IF([test $tpm_server = missing],
[AC_MSG_ERROR([Required executable tpm_server not found, try setting PATH])])
AC_CHECK_PROG([BASH_SHELL], [bash], yes, no)
AS_IF([test $BASH_SHELL = missing],
[AC_MSG_ERROR([Required executable bash not found, system tests require a bash shell!])])
AC_CHECK_PROG([PYTHON], [python], yes, no)
AS_IF([test $PYTHON = missing],
[AC_MSG_ERROR([Required executable python not found, some system tests will fail!])])
AC_PYTHON_MODULE([yaml])
AC_CHECK_PROG([XXD], [xxd], yes, no)
AS_IF([test $XXD = missing],
[AC_MSG_ERROR([Required executable xxd not found, some system tests will fail!])])
AC_CHECK_PROG([SS], [ss], yes, no)
AS_IF([test $SS = missing],
[AC_MSG_ERROR([Required executable ss not found, some system tests will fail!])])
AC_CHECK_PROG([SHASUM], [shasum], yes, no)
AS_IF([test $SHASUM = missing],
[AC_MSG_ERROR([Required executable shasum not found, some system tests will fail!])])
AC_CHECK_PROG([MKTEMP], [mktemp], yes, no)
AS_IF([test $MKTEMP = missing],
[AC_MSG_ERROR([Required executable mktemp not found, some system tests will fail!])])
unit_test_tool_report="- tpm2_abrmd: $tpm2_abrmd
- tpm_server: $tpm_server
- bash: $BASH_SHELL
- python: $PYTHON
- xxd: $XXD
- ss: $SS
- shasum: $SHASUM
- mktemp: $MKTEMP"
])
AC_ARG_ENABLE([hardening],
[AS_HELP_STRING([--disable-hardening],
[Disable compiler and linker options to frustrate memory corruption exploits])],,
[enable_hardening="yes"])
# Good information on adding flags, and dealing with compilers can be found here:
# https://github.com/zcash/zcash/issues/1832
# https://github.com/kmcallister/autoharden/
AS_IF([test x"$enable_hardening" != x"no"], [
AC_DEFUN([add_hardened_c_flag], [
AX_CHECK_COMPILE_FLAG([$1],
[EXTRA_CFLAGS="$EXTRA_CFLAGS $1"],
[AC_MSG_ERROR([Cannot enable $1, consider configuring with --disable-hardening])]
)
])
AC_DEFUN([add_hardened_ld_flag], [
AX_CHECK_LINK_FLAG([$1],
[EXTRA_LDFLAGS="$EXTRA_LDFLAGS $1"],
[AC_MSG_ERROR([Cannot enable $1, consider configuring with --disable-hardening])]
)
])
AC_DEFUN([add_hardened_define_flag], [
AX_CHECK_PREPROC_FLAG([$1],
[EXTRA_CFLAGS="$EXTRA_CFLAGS $1"],
[AC_MSG_ERROR([Cannot enable $1, consider configuring with --disable-hardening])]
)
])
add_hardened_c_flag([-Wall])
add_hardened_c_flag([-Wextra])
add_hardened_c_flag([-Werror])
add_hardened_c_flag([-Wformat])
add_hardened_c_flag([-Wformat-security])
add_hardened_c_flag([-Wstack-protector])
add_hardened_c_flag([-fstack-protector-all])
add_hardened_c_flag([-Wstrict-overflow=5])
add_hardened_c_flag([-Wbool-compare])
add_hardened_c_flag([-O2])
AX_ADD_FORTIFY_SOURCE
add_hardened_c_flag([-fPIC])
add_hardened_ld_flag([[-shared]])
add_hardened_c_flag([-fPIE])
add_hardened_ld_flag([[-pie]])
add_hardened_ld_flag([[-Wl,-z,relro]])
add_hardened_ld_flag([[-Wl,-z,now]])
], [
AC_MSG_WARN([Compiling with --disable-hardening is dangerous!
you should consider fixing the configure script compiler flags
and submitting patches upstream!])
])
AC_DEFUN([add_c_flag], [
AX_CHECK_COMPILE_FLAG([$1],
[EXTRA_CFLAGS="$EXTRA_CFLAGS $1"],
$2
)
])
# -D_GNU_SOURCE is required for execvpe() in options.c
add_c_flag([-D_GNU_SOURCE], [AC_MSG_ERROR([Cannot enable -D_GNU_SOURCE])])
# Best attempt compiler options that are on newer versions of GCC that
# we can't widely enforce without killing other peoples builds
add_c_flag([-Wstringop-overflow=4])
add_c_flag([-Wstringop-truncation])
add_c_flag([-Wduplicated-branches])
add_c_flag([-Wduplicated-cond])
# Best attempt, strip unused stuff from the binary to reduce size.
# Rather than nesting these and making them ugly just use a counter.
AX_CHECK_COMPILE_FLAG([-fdata-sections], [strip="${strip}y"])
AX_CHECK_COMPILE_FLAG([-ffunction-sections], [strip="${strip}y"])
AX_CHECK_LINK_FLAG([[-Wl,--gc-sections]], [strip="${strip}y"])
AS_IF([test x"$strip" = x"yyy"], [
EXTRA_CFLAGS="$EXTRA_CFLAGS -fdata-sections -ffunction-sections"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,--gc-sections"
],
AC_MSG_NOTICE([Not using compiler options to reduce binary size!])
)
AC_SUBST([EXTRA_CFLAGS])
AC_SUBST([EXTRA_LDFLAGS])
AC_SUBST([PATH])
AC_OUTPUT
AC_MSG_RESULT([
- $PACKAGE_NAME: $VERSION
- Man pages: ${PANDOC:-no}
- Unit tests: $enable_unit
$unit_test_tool_report
])