forked from tpm2-software/tpm2-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.ac
147 lines (124 loc) · 4.6 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
AC_INIT([tpm2-tools],
[m4_esyscmd_s([git describe --tags --always --dirty])])
AC_CONFIG_MACRO_DIR([m4])
AC_PROG_CC
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
AC_CONFIG_FILES([Makefile])
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"])
PKG_CHECK_MODULES([TSS2_SYS],[tss2-sys])
PKG_CHECK_MODULES([CRYPTO], [libcrypto >= 1.0.2g])
PKG_CHECK_MODULES([CURL],[libcurl])
AC_ARG_ENABLE([unit],
[AS_HELP_STRING([--enable-unit],
[build cmocka unit tests (default is no)])],
[enable_unit=$enableval],
[enable_unit=no])
AS_IF([test "x$enable_unit" != xno],
[PKG_CHECK_MODULES([CMOCKA],
[cmocka],
[AC_DEFINE([HAVE_CMOCKA],
[1])])])
AM_CONDITIONAL([UNIT], [test "x$enable_unit" != xno])
AC_ARG_ENABLE([dlclose],
[AS_HELP_STRING([--disable-dlclose],
[Some versions of libc cause a sigsegv on exit, this disables the dlclose and works around that bug])],
[]
[AC_DEFINE([DISABLE_DLCLOSE], [1])]
)
AC_ARG_ENABLE([hardening],
[AS_HELP_STRING([--enable-hardening],
[Enable compiler and linker options to frustrate memory corruption exploits @<:@yes@:>@])],
[hardening="$enableval"],
[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"$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_define_flag([-U_FORTIFY_SOURCE])
add_hardened_define_flag([-D_FORTIFY_SOURCE=2])
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!])
])
# -D_GNU_SOURCE is required for execvpe() in options.c
AX_CHECK_PREPROC_FLAG([-D_GNU_SOURCE],
[EXTRA_CFLAGS="$EXTRA_CFLAGS -D_GNU_SOURCE"],
[AC_MSG_ERROR([Cannot enable -D_GNU_SOURCE])]
)
# 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+="y"])
AX_CHECK_COMPILE_FLAG([-ffunction-sections], [strip+="y"])
AX_CHECK_LINK_FLAG([[-Wl,--gc-sections]], [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_CHECK_PROG([BASH_SHELL],[bash],[yes])
AS_IF(
[test "x${BASH_SHELL}" == x"yes"],
[],
[AC_MSG_WARN([Required executable bash not found, system tests require a bash shell!])])
AC_CHECK_PROG([PYTHON],[python],[yes])
AS_IF(
[test "x${PYTHON}" == x"yes"],
[],
[AC_MSG_WARN([Required executable python not found, some system tests will fail!])])
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 -
if test $? -ne 0 ; then
AC_MSG_RESULT([not found])
AC_MSG_WARN([System tests require pyyaml, some tests will fail!])
fi
AC_MSG_RESULT(found)
])
AC_PYTHON_MODULE([yaml])
AC_SUBST([EXTRA_CFLAGS])
AC_SUBST([EXTRA_LDFLAGS])
AC_OUTPUT