]> git.proxmox.com Git - swtpm.git/blame - configure.ac
swtpm: poll for HUP as well
[swtpm.git] / configure.ac
CommitLineData
f163b202
SB
1#
2# configure.ac
3#
4# The Initial Developer of the Original Code is International
5# Business Machines Corporation. Portions created by IBM
6# Corporation are Copyright (C) 2014 International Business
7# Machines Corporation. All Rights Reserved.
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the Common Public License as published by
11# IBM Corporation; either version 1 of the License, or (at your option)
12# any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# Common Public License for more details.
18#
19# You should have received a copy of the Common Public License
20# along with this program; if not, a copy can be viewed at
21# http://www.opensource.org/licenses/cpl1.0.php.
22#
23# This file is derived from tpm-tool's configure.in.
24#
25
26AC_INIT(swtpm, 0.1.0)
27AC_PREREQ(2.12)
28AC_CONFIG_SRCDIR(Makefile.am)
29AC_CONFIG_HEADER(config.h)
30
31SWTPM_VER_MAJOR=`echo $PACKAGE_VERSION | cut -d "." -f1`
32SWTPM_VER_MINOR=`echo $PACKAGE_VERSION | cut -d "." -f2`
33SWTPM_VER_MICRO=`echo $PACKAGE_VERSION | cut -d "." -f3`
34
35AC_SUBST([SWTPM_VER_MAJOR])
36AC_SUBST([SWTPM_VER_MINOR])
37AC_SUBST([SWTPM_VER_MICRO])
38
39dnl Check for programs
40AC_PROG_CC
41AC_PROG_INSTALL
42AC_PROG_LN_S
43AC_PROG_LIBTOOL
44
f163b202
SB
45AC_CONFIG_MACRO_DIR([m4])
46AC_CANONICAL_TARGET
47AM_INIT_AUTOMAKE([foreign 1.6])
48
49DEBUG=""
50AC_MSG_CHECKING([for debug-enabled build])
51AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [create a debug build]),
52 [if test "$enableval" = "yes"; then
53 DEBUG="yes"
54 AC_MSG_RESULT([yes])
55 else
56 DEBUG="no"
57 AC_MSG_RESULT([no])
58 fi],
59 [DEBUG="no",
60 AC_MSG_RESULT([no])])
61
62# If the user has not set CFLAGS, do something appropriate
63test_CFLAGS=${CFLAGS+set}
64if test "$test_CFLAGS" != set; then
65 if test "$DEBUG" == "yes"; then
66 CFLAGS="-O0 -g -DDEBUG"
67 else
68 CFLAGS="-g -O2"
69 fi
70elif test "$DEBUG" == "yes"; then
71 CFLAGS="$CFLAGS -O0 -g -DDEBUG"
72fi
73
e46a2b66
SB
74AC_HEADER_STDC
75AC_C_CONST
76AC_C_INLINE
77
78AC_TYPE_SIZE_T
79AC_TYPE_SIGNAL
80
baecda40
SB
81AC_PROG_CC
82AC_PROG_INSTALL
3cb54a5d 83AC_PROG_MKDIR_P
e46a2b66 84
ec37bb56
SB
85AC_ARG_WITH([selinux],
86 AS_HELP_STRING([--with-selinux],
87 [add SELinux policy extensions @<:@default=check@:>@]))
88m4_divert_text([DEFAULTS], [with_selinux=check])
89
90dnl Check for SELinux policy support
91
92if test "$with_selinux" != "no"; then
93 if test "$with_selinux" = "check" || test "$with_selinux" = "yes"; then
94 if ! test -f /usr/share/selinux/devel/Makefile; then
95 if test "$with_selinux" = "yes"; then
96 AC_MSG_ERROR("Is selinux-policy-devel installed?")
97 else
98 with_selinux="no"
99 fi
100 fi
101 AC_PATH_PROG([SEMODULE], semodule)
102 if test "x$SEMODULE" == "x"; then
103 if test "$with_selinux" = "yes"; then
104 AC_MSG_ERROR("Is selinux-policy-devel installed?")
105 else
106 with_selinux="no"
107 fi
108 fi
109 if test "$with_selinux" = "check"; then
110 with_selinux="yes"
111 fi
112 fi
113fi
114AM_CONDITIONAL([WITH_SELINUX], [test "x$with_selinux" == "xyes"])
115
f163b202
SB
116GLIB_CFLAGS=$(pkg-config --cflags glib-2.0)
117if test $? -ne 0; then
118 AC_MSG_ERROR("Is glib-2.0 installed? -- could not get cflags")
119fi
baecda40 120AC_SUBST([GLIB_CFLAGS])
f163b202 121
baecda40 122GLIB_LIBS=$(pkg-config --libs glib-2.0)
f163b202
SB
123if test $? -ne 0; then
124 AC_MSG_ERROR("Is glib-2.0 installed? -- could not get libs")
125fi
baecda40 126AC_SUBST([GLIB_LIBS])
f163b202 127
baecda40 128GTHREAD_LIBS=$(pkg-config --libs gthread-2.0)
f163b202
SB
129if test $? -ne 0; then
130 AC_MSG_ERROR("Is glib-2.0 installed? -- could not get libs for gthread-2.0")
131fi
baecda40 132AC_SUBST([GTHREAD_LIBS])
f163b202 133
3bbdd7bc
SB
134cryptolib=freebl
135
136AC_ARG_WITH([openssl],
137 AC_HELP_STRING([--with-openssl],
213677a2 138 [build with openssl library]),
3bbdd7bc
SB
139 [AC_CHECK_LIB(crypto,
140 [AES_set_encrypt_key],
141 [],
142 AC_MSG_ERROR(Faulty openssl crypto library))
143 AC_CHECK_HEADERS([openssl/aes.h],[],
144 AC_MSG_ERROR(Is openssl-devel/libssl-dev installed?))
145 AC_MSG_RESULT([Building with openssl crypto library])
146 cryptolib=openssl
147 ]
148)
149
150case "$cryptolib" in
151freebl)
152 AM_CONDITIONAL(SWTPM_USE_FREEBL, true)
153 AM_CONDITIONAL(SWTPM_USE_OPENSSL, false)
154 AC_DEFINE([USE_FREEBL_CRYPTO_LIBRARY],
155 [1],
156 [use freebl crypto library])
157
158 NSPR_CFLAGS=$(nspr-config --cflags)
159 if test $? -ne 0; then
160 AC_MSG_ERROR("Could not find nspr-config. Is nspr-devel/libnspr4-dev installed?")
161 fi
162 AC_SUBST([NSPR_CFLAGS])
163
164 NSS_CFLAGS=$(nss-config --cflags)
165 if test $? -ne 0; then
166 AC_MSG_ERROR("Could not find nss-config. Is nss-devel/libnss3-dev installed?")
167 fi
168 AC_SUBST([NSS_CFLAGS])
169
170 NSS_LIBS=$(nss-config --libs)
171 if test $? -ne 0; then
172 AC_MSG_ERROR("Is nss-devel/libnss3-dev installed? -- could not get libs for nss")
173 fi
174 dnl On RHEL 7 ppc64 we need an explicit -lfreebl
175 NSS_LIBS="$NSS_LIBS -lfreebl"
176 AC_SUBST([NSS_LIBS])
177
178 CPPFLAGS="$NSS_CFLAGS $NSPR_CFLAGS"
179 AC_CHECK_HEADERS([sslerr.h],[],
180 AC_MSG_ERROR(nss-devel/libnss3-dev is bad))
181
182 # Check for missing headers
183 CFLAGS_save="$CFLAGS"
184 CFLAGS="$NSS_CFLAGS $NSPR_CFLAGS"
185 AC_CHECK_HEADERS([blapi.h],[],
186 AC_MSG_ERROR(nss-softokn-freebl-devel/libnss3-dev is missing blapi.h))
187 # Check for missing freebl library or missing library functions
188 LIBS_save="$LIBS"
189 LIBS="$(nss-config --libs) $(nspr-config --libs)"
190 AC_SEARCH_LIBS([AES_CreateContext], [freebl],[],
191 AC_MSG_ERROR("Could not find AES_CreateContext(). Is nss-softokn-freebl-devel/libnss3-dev installed?"),
192 [])
193 LIBS="$LIBS_save"
194 CPPFLAGS=""
195 CFLAGS="$CFLAGS_save"
196
197 ;;
198openssl)
199 AM_CONDITIONAL(SWTPM_USE_FREEBL, false)
200 AM_CONDITIONAL(SWTPM_USE_OPENSSL, true)
201 AC_DEFINE([USE_OPENSSL_CRYPTO_LIBRARY],
202 [1],
203 [use openssl crypto library])
204 ;;
205esac
833a5416 206
baecda40
SB
207LIBTASN1_LIBS=$(pkg-config --libs libtasn1)
208if test $? -ne 0; then
209 AC_MSG_ERROR("Is libtasn1-devel installed? -- could not get libs for libtasn1")
210fi
211AC_SUBST([LIBTASN1_LIBS])
f163b202 212
baecda40
SB
213LIBTPMS_LIBS=$(pkg-config --libs libtpms)
214if test $? -ne 0; then
215 AC_MSG_ERROR("Is libtpms-devel installed? -- could not get libs for libtpms")
216fi
217AC_SUBST([LIBTPMS_LIBS])
f163b202 218
e46a2b66
SB
219AC_PATH_PROG([TPM_NVDEFINE], tpm_nvdefine)
220if test "x$TPM_NVDEFINE" == "x"; then
221 AC_MSG_ERROR([NVRAM area tools are need: tpm-tools package])
222fi
223
baecda40
SB
224LIBFUSE_CFLAGS=$(pkg-config fuse --cflags)
225if test $? -ne 0; then
226 AC_MSG_ERROR("Is fuse-devel installed? -- could not get cflags for libfuse")
227fi
228AC_SUBST([LIBFUSE_CFLAGS])
f163b202 229
baecda40
SB
230LIBFUSE_LIBS=$(pkg-config fuse --libs)
231if test $? -ne 0; then
232 AC_MSG_ERROR("Is fuse-devel installed? -- could not get libs for libfuse")
233fi
234AC_SUBST([LIBFUSE_LIBS])
f163b202 235
e46a2b66
SB
236if test "x$with_gnutls" != "xno"; then
237 GNUTLS_LDFLAGS=$(pkg-config --libs gnutls)
238 if test $? -ne 0; then
239 if "x$with_gnutls" == "xyes"; then
240 AC_MSG_ERROR("Is gnutls installed? -- could not get libs for gnutls")
241 else
242 with_gnutls=no
243 fi
244 fi
245fi
f163b202 246
e46a2b66 247if test "x$with_gnutls" != "xno"; then
baecda40
SB
248 GNUTLS_CFLAGS=$(pkg-config gnutls --cflags)
249 AC_CHECK_LIB([gnutls], [gnutls_x509_crt_set_key], [
250 GNUTLS_LIBS=-lgnutls
251 ],
e46a2b66
SB
252 [if test "x$with_gnutls" == "xyes"; then
253 AC_MSG_ERROR([GNUTLS >= 3.1.0 library not found: libgnutls.so])
254 else
255 with_gnutls="no"
256 fi])
257fi
258
259if test "x$with_gnutls" != "xno"; then
260 AC_CHECK_HEADER(gnutls/abstract.h, [], \
261 [if test "x$with_gnutls" == "xyes"; then
262 AC_MSG_ERROR([GNUTLS >= 3.1.0 library header not found: gnutls/abstract.h])
263 else
264 with_gnutls="no"
265 fi])
266fi
267
268if test "x$with_gnutls" != "xno"; then
269 with_gnutls="yes"
270fi
271AM_CONDITIONAL([WITH_GNUTLS], [test "x$with_gnutls" == "xyes"])
baecda40 272AC_SUBST([GNUTLS_LIBS])
f163b202 273
48abfbb1
SB
274AC_PATH_PROG([EXPECT], expect)
275if test "x$EXPECT" == "x"; then
276 AC_MSG_ERROR([expect is required: expect package])
277fi
278
b080afb5
SB
279AC_PATH_PROG([GAWK], gawk)
280if test "x$GAWK" == "x"; then
281 AC_MSG_ERROR([gawk is required: gawk package])
282fi
283
8cb126e4
SB
284AC_PATH_PROG([SOCAT], socat)
285if test "x$SOCAT" == "x"; then
286 AC_MSG_ERROR([socat is required: socat package])
287fi
288
08f1e70d
SB
289TMP="$($CC -fstack-protector-strong 2>&1)"
290if echo $TMP | $GREP 'unrecognized command line option' >/dev/null; then
291 HARDENING_CFLAGS="-fstack-protector -Wstack-protector "
f77427eb 292else
08f1e70d 293 HARDENING_CFLAGS="-fstack-protector-strong -Wstack-protector "
f77427eb 294fi
a76b4eeb
SB
295
296dnl Must not have -O0 but must have a -O for -D_FORTIFY_SOURCE=2
297TMP1="$(echo $CFLAGS | sed -n 's/.*\(-O0\).*/\1/p')"
298TMP2="$(echo $CFLAGS | sed -n 's/.*\(-O\).*/\1/p')"
299if test -z "$TMP1" && test -n "$TPM2"; then
300 HARDENING_CFLAGS+="-D_FORTIFY_SOURCE=2 "
301fi
302dnl Check ld for 'relro' and 'now'
303if $LD --help 2>&1 | $GREP '\-z relro ' > /dev/null; then
304 HARDENING_CFLAGS+="-Wl,-z,relro "
305fi
306if $LD --help 2>&1 | $GREP '\-z now ' > /dev/null; then
307 HARDENING_CFLAGS+="-Wl,-z,now "
308fi
e6085e96
SB
309AC_SUBST([HARDENING_CFLAGS])
310
c4ac0a11
SB
311AC_ARG_WITH([tss-user],
312 AC_HELP_STRING([--with-tss-user=TSS_USER],
313 [The tss user to use]),
314 [TSS_USER="$withval"],
315 [TSS_USER="tss"]
316)
317
318AC_ARG_WITH([tss-group],
319 AC_HELP_STRING([--with-tss-group=TSS_GROUP],
320 [The tss group to use]),
321 [TSS_GROUP="$withval"],
322 [TSS_GROUP="tss"]
323)
324AC_SUBST([TSS_USER])
325AC_SUBST([TSS_GROUP])
326
f163b202
SB
327CFLAGS="$CFLAGS -Wreturn-type -Wsign-compare -Wswitch-enum"
328CFLAGS="$CFLAGS -Wmissing-prototypes -Wall -Werror"
e6085e96 329CFLAGS="$CFLAGS -Wformat -Wformat-security"
f163b202 330
58774fd6 331AC_CONFIG_FILES([Makefile \
f163b202 332 dist/swtpm.spec \
e46a2b66
SB
333 etc/Makefile \
334 samples/Makefile \
f163b202
SB
335 include/Makefile \
336 include/swtpm/Makefile \
337 src/Makefile \
338 src/selinux/Makefile \
339 src/swtpm/Makefile \
340 src/swtpm/swtpm.h \
e46a2b66
SB
341 src/swtpm_bios/Makefile \
342 src/swtpm_cert/Makefile \
343 src/swtpm_ioctl/Makefile \
344 src/swtpm_setup/Makefile \
c4ac0a11
SB
345 src/swtpm_setup/swtpm_setup.h \
346 src/swtpm_setup/swtpm_setup.sh \
f163b202 347 man/Makefile \
39d0c3de 348 man/man3/Makefile \
f163b202 349 man/man8/Makefile \
e46a2b66 350 tests/Makefile \
c4ac0a11 351 tests/test_config \
58774fd6 352 ], [chmod 755 src/swtpm_setup/swtpm_setup.sh])
f163b202
SB
353AC_OUTPUT
354
e46a2b66 355echo
ec37bb56
SB
356printf "with_gnutls : %5s (no = swtpm_cert will NOT be built)\n" $with_gnutls
357printf "with_selinux: %5s (no = SELinux policy extenions will NOT be build)\n" $with_selinux
e46a2b66 358echo
f163b202 359echo "CFLAGS=$CFLAGS"
a76b4eeb 360echo "HARDENING_CFLAGS=$HARDENING_CFLAGS"
f163b202 361echo "LDFLAGS=$LDFLAGS"
c4ac0a11
SB
362echo
363echo "TSS_USER=$TSS_USER"
364echo "TSS_GROUP=$TSS_GROUP"
365echo