]> git.proxmox.com Git - swtpm.git/blame - configure.ac
Announce the TPM frontend device name and major/minor numbers
[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
c3fdf688 47AC_CANONICAL_HOST
f163b202
SB
48AM_INIT_AUTOMAKE([foreign 1.6])
49
50DEBUG=""
51AC_MSG_CHECKING([for debug-enabled build])
52AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [create a debug build]),
53 [if test "$enableval" = "yes"; then
54 DEBUG="yes"
55 AC_MSG_RESULT([yes])
56 else
57 DEBUG="no"
58 AC_MSG_RESULT([no])
59 fi],
60 [DEBUG="no",
61 AC_MSG_RESULT([no])])
62
63# If the user has not set CFLAGS, do something appropriate
64test_CFLAGS=${CFLAGS+set}
65if test "$test_CFLAGS" != set; then
66 if test "$DEBUG" == "yes"; then
67 CFLAGS="-O0 -g -DDEBUG"
68 else
69 CFLAGS="-g -O2"
70 fi
71elif test "$DEBUG" == "yes"; then
72 CFLAGS="$CFLAGS -O0 -g -DDEBUG"
73fi
74
e46a2b66
SB
75AC_HEADER_STDC
76AC_C_CONST
77AC_C_INLINE
78
79AC_TYPE_SIZE_T
80AC_TYPE_SIGNAL
81
baecda40
SB
82AC_PROG_CC
83AC_PROG_INSTALL
3cb54a5d 84AC_PROG_MKDIR_P
e46a2b66 85
ec37bb56
SB
86AC_ARG_WITH([selinux],
87 AS_HELP_STRING([--with-selinux],
88 [add SELinux policy extensions @<:@default=check@:>@]))
89m4_divert_text([DEFAULTS], [with_selinux=check])
90
91dnl Check for SELinux policy support
92
93if test "$with_selinux" != "no"; then
94 if test "$with_selinux" = "check" || test "$with_selinux" = "yes"; then
95 if ! test -f /usr/share/selinux/devel/Makefile; then
96 if test "$with_selinux" = "yes"; then
97 AC_MSG_ERROR("Is selinux-policy-devel installed?")
98 else
99 with_selinux="no"
100 fi
101 fi
102 AC_PATH_PROG([SEMODULE], semodule)
103 if test "x$SEMODULE" == "x"; then
104 if test "$with_selinux" = "yes"; then
105 AC_MSG_ERROR("Is selinux-policy-devel installed?")
106 else
107 with_selinux="no"
108 fi
109 fi
110 if test "$with_selinux" = "check"; then
111 with_selinux="yes"
112 fi
113 fi
114fi
115AM_CONDITIONAL([WITH_SELINUX], [test "x$with_selinux" == "xyes"])
116
f163b202
SB
117GLIB_CFLAGS=$(pkg-config --cflags glib-2.0)
118if test $? -ne 0; then
119 AC_MSG_ERROR("Is glib-2.0 installed? -- could not get cflags")
120fi
baecda40 121AC_SUBST([GLIB_CFLAGS])
f163b202 122
baecda40 123GLIB_LIBS=$(pkg-config --libs glib-2.0)
f163b202
SB
124if test $? -ne 0; then
125 AC_MSG_ERROR("Is glib-2.0 installed? -- could not get libs")
126fi
baecda40 127AC_SUBST([GLIB_LIBS])
f163b202 128
baecda40 129GTHREAD_LIBS=$(pkg-config --libs gthread-2.0)
f163b202
SB
130if test $? -ne 0; then
131 AC_MSG_ERROR("Is glib-2.0 installed? -- could not get libs for gthread-2.0")
132fi
baecda40 133AC_SUBST([GTHREAD_LIBS])
f163b202 134
3bbdd7bc
SB
135cryptolib=freebl
136
137AC_ARG_WITH([openssl],
138 AC_HELP_STRING([--with-openssl],
213677a2 139 [build with openssl library]),
3bbdd7bc
SB
140 [AC_CHECK_LIB(crypto,
141 [AES_set_encrypt_key],
142 [],
143 AC_MSG_ERROR(Faulty openssl crypto library))
144 AC_CHECK_HEADERS([openssl/aes.h],[],
145 AC_MSG_ERROR(Is openssl-devel/libssl-dev installed?))
146 AC_MSG_RESULT([Building with openssl crypto library])
147 cryptolib=openssl
148 ]
149)
150
151case "$cryptolib" in
152freebl)
153 AM_CONDITIONAL(SWTPM_USE_FREEBL, true)
154 AM_CONDITIONAL(SWTPM_USE_OPENSSL, false)
155 AC_DEFINE([USE_FREEBL_CRYPTO_LIBRARY],
156 [1],
157 [use freebl crypto library])
158
159 NSPR_CFLAGS=$(nspr-config --cflags)
160 if test $? -ne 0; then
161 AC_MSG_ERROR("Could not find nspr-config. Is nspr-devel/libnspr4-dev installed?")
162 fi
163 AC_SUBST([NSPR_CFLAGS])
164
165 NSS_CFLAGS=$(nss-config --cflags)
166 if test $? -ne 0; then
167 AC_MSG_ERROR("Could not find nss-config. Is nss-devel/libnss3-dev installed?")
168 fi
169 AC_SUBST([NSS_CFLAGS])
170
171 NSS_LIBS=$(nss-config --libs)
172 if test $? -ne 0; then
173 AC_MSG_ERROR("Is nss-devel/libnss3-dev installed? -- could not get libs for nss")
174 fi
175 dnl On RHEL 7 ppc64 we need an explicit -lfreebl
176 NSS_LIBS="$NSS_LIBS -lfreebl"
177 AC_SUBST([NSS_LIBS])
178
179 CPPFLAGS="$NSS_CFLAGS $NSPR_CFLAGS"
180 AC_CHECK_HEADERS([sslerr.h],[],
181 AC_MSG_ERROR(nss-devel/libnss3-dev is bad))
182
183 # Check for missing headers
184 CFLAGS_save="$CFLAGS"
185 CFLAGS="$NSS_CFLAGS $NSPR_CFLAGS"
186 AC_CHECK_HEADERS([blapi.h],[],
187 AC_MSG_ERROR(nss-softokn-freebl-devel/libnss3-dev is missing blapi.h))
188 # Check for missing freebl library or missing library functions
189 LIBS_save="$LIBS"
190 LIBS="$(nss-config --libs) $(nspr-config --libs)"
191 AC_SEARCH_LIBS([AES_CreateContext], [freebl],[],
192 AC_MSG_ERROR("Could not find AES_CreateContext(). Is nss-softokn-freebl-devel/libnss3-dev installed?"),
193 [])
194 LIBS="$LIBS_save"
195 CPPFLAGS=""
196 CFLAGS="$CFLAGS_save"
197
198 ;;
199openssl)
200 AM_CONDITIONAL(SWTPM_USE_FREEBL, false)
201 AM_CONDITIONAL(SWTPM_USE_OPENSSL, true)
202 AC_DEFINE([USE_OPENSSL_CRYPTO_LIBRARY],
203 [1],
204 [use openssl crypto library])
205 ;;
206esac
833a5416 207
baecda40
SB
208LIBTASN1_LIBS=$(pkg-config --libs libtasn1)
209if test $? -ne 0; then
210 AC_MSG_ERROR("Is libtasn1-devel installed? -- could not get libs for libtasn1")
211fi
212AC_SUBST([LIBTASN1_LIBS])
f163b202 213
baecda40
SB
214LIBTPMS_LIBS=$(pkg-config --libs libtpms)
215if test $? -ne 0; then
216 AC_MSG_ERROR("Is libtpms-devel installed? -- could not get libs for libtpms")
217fi
218AC_SUBST([LIBTPMS_LIBS])
f163b202 219
e46a2b66 220AC_PATH_PROG([TPM_NVDEFINE], tpm_nvdefine)
c3fdf688
SB
221case $host_os in
222linux-*)
223 if test "x$TPM_NVDEFINE" == "x"; then
224 AC_MSG_ERROR([NVRAM area tools are needed: tpm-tools package])
225 fi
226 with_tcsd=yes
227 ;;
228*)
229 with_tcsd=no
230esac
231with_swtpm_setup=$with_tcsd
232AM_CONDITIONAL([WITH_SWTPM_SETUP], test "$with_swtpm_setup" != "no")
e46a2b66 233
09d1a532
SB
234AC_MSG_CHECKING([for whether to build with CUSE interface])
235AC_ARG_WITH([cuse],
236 AC_HELP_STRING([--with-cuse],
237 [build with CUSE interface]),
238 [],
239 [with_cuse=check]
240)
f163b202 241
09d1a532
SB
242if test "$with_cuse" != "no"; then
243 LIBFUSE_CFLAGS=$(pkg-config fuse --cflags 2>/dev/null)
244 if test $? -ne 0; then
245 if test "$with_cuse" = "yes"; then
246 AC_MSG_ERROR("Is fuse-devel installed? -- could not get cflags for libfuse")
247 else
248 with_cuse=no
249 fi
250 else
251 with_cuse=yes
252 fi
498433f7 253fi
09d1a532
SB
254
255dnl with_cuse is now yes or no
256if test "$with_cuse" != "no"; then
257 LIBFUSE_LIBS=$(pkg-config fuse --libs)
258 if test $? -ne 0; then
259 AC_MSG_ERROR("Is fuse-devel installed? -- could not get libs for libfuse")
260 fi
261 AC_SUBST([LIBFUSE_CFLAGS])
262 AC_SUBST([LIBFUSE_LIBS])
263 AC_DEFINE_UNQUOTED([WITH_CUSE], 1,
264 [whether to build with CUSE interface])
baecda40 265fi
09d1a532
SB
266AM_CONDITIONAL([WITH_CUSE],[test "$with_cuse" = "yes"])
267AC_MSG_RESULT($with_cuse)
f163b202 268
498433f7
SB
269AC_MSG_CHECKING([for whether to build with chardev interface])
270case $host_os in
271linux-*)
272 with_chardev=yes
273 AC_DEFINE_UNQUOTED([WITH_CHARDEV], 1,
274 [whether to build with chardev interface])
275 ;;
276*)
277 with_chardev=no
278esac
279AM_CONDITIONAL([WITH_CHARDEV],[test "$with_chardev" = "yes"])
280AC_MSG_RESULT($with_cuse)
281
10002933
SB
282AC_ARG_WITH([gnutls],
283 AC_HELP_STRING([--with-gnutls],
284 [build with gnutls library]),
285 [],
286 [with_gnutls=check]
287)
288
e46a2b66
SB
289if test "x$with_gnutls" != "xno"; then
290 GNUTLS_LDFLAGS=$(pkg-config --libs gnutls)
291 if test $? -ne 0; then
1828edee 292 if test "x$with_gnutls" == "xyes"; then
e46a2b66
SB
293 AC_MSG_ERROR("Is gnutls installed? -- could not get libs for gnutls")
294 else
295 with_gnutls=no
296 fi
297 fi
298fi
f163b202 299
1828edee
SB
300if test "x$with_gnutls" != "xno"; then
301 AC_PATH_PROG([GNUTLS_CERTTOOL], certtool)
302 if test "x$GNUTLS_CERTTOOL" == "x"; then
303 if test "x$with_gnutls" == "xyes"; then
304 AC_MSG_ERROR("Could not find certtool. Is gnutls-utils/gnutls-bin installed?")
305 else
306 with_gnutls=no
307 fi
308 fi
309fi
310
e46a2b66 311if test "x$with_gnutls" != "xno"; then
baecda40 312 GNUTLS_CFLAGS=$(pkg-config gnutls --cflags)
10002933 313 AC_CHECK_LIB([gnutls], [gnutls_load_file], [
baecda40
SB
314 GNUTLS_LIBS=-lgnutls
315 ],
e46a2b66
SB
316 [if test "x$with_gnutls" == "xyes"; then
317 AC_MSG_ERROR([GNUTLS >= 3.1.0 library not found: libgnutls.so])
318 else
319 with_gnutls="no"
320 fi])
321fi
322
323if test "x$with_gnutls" != "xno"; then
324 AC_CHECK_HEADER(gnutls/abstract.h, [], \
325 [if test "x$with_gnutls" == "xyes"; then
326 AC_MSG_ERROR([GNUTLS >= 3.1.0 library header not found: gnutls/abstract.h])
327 else
328 with_gnutls="no"
329 fi])
330fi
331
332if test "x$with_gnutls" != "xno"; then
333 with_gnutls="yes"
334fi
335AM_CONDITIONAL([WITH_GNUTLS], [test "x$with_gnutls" == "xyes"])
baecda40 336AC_SUBST([GNUTLS_LIBS])
f163b202 337
48abfbb1
SB
338AC_PATH_PROG([EXPECT], expect)
339if test "x$EXPECT" == "x"; then
340 AC_MSG_ERROR([expect is required: expect package])
341fi
342
b080afb5
SB
343AC_PATH_PROG([GAWK], gawk)
344if test "x$GAWK" == "x"; then
345 AC_MSG_ERROR([gawk is required: gawk package])
346fi
347
8cb126e4
SB
348AC_PATH_PROG([SOCAT], socat)
349if test "x$SOCAT" == "x"; then
350 AC_MSG_ERROR([socat is required: socat package])
351fi
352
08f1e70d
SB
353TMP="$($CC -fstack-protector-strong 2>&1)"
354if echo $TMP | $GREP 'unrecognized command line option' >/dev/null; then
355 HARDENING_CFLAGS="-fstack-protector -Wstack-protector "
f77427eb 356else
08f1e70d 357 HARDENING_CFLAGS="-fstack-protector-strong -Wstack-protector "
f77427eb 358fi
a76b4eeb
SB
359
360dnl Must not have -O0 but must have a -O for -D_FORTIFY_SOURCE=2
361TMP1="$(echo $CFLAGS | sed -n 's/.*\(-O0\).*/\1/p')"
362TMP2="$(echo $CFLAGS | sed -n 's/.*\(-O\).*/\1/p')"
363if test -z "$TMP1" && test -n "$TPM2"; then
364 HARDENING_CFLAGS+="-D_FORTIFY_SOURCE=2 "
365fi
366dnl Check ld for 'relro' and 'now'
367if $LD --help 2>&1 | $GREP '\-z relro ' > /dev/null; then
368 HARDENING_CFLAGS+="-Wl,-z,relro "
369fi
370if $LD --help 2>&1 | $GREP '\-z now ' > /dev/null; then
371 HARDENING_CFLAGS+="-Wl,-z,now "
372fi
e6085e96
SB
373AC_SUBST([HARDENING_CFLAGS])
374
c4ac0a11
SB
375AC_ARG_WITH([tss-user],
376 AC_HELP_STRING([--with-tss-user=TSS_USER],
377 [The tss user to use]),
378 [TSS_USER="$withval"],
379 [TSS_USER="tss"]
380)
381
382AC_ARG_WITH([tss-group],
383 AC_HELP_STRING([--with-tss-group=TSS_GROUP],
384 [The tss group to use]),
385 [TSS_GROUP="$withval"],
386 [TSS_GROUP="tss"]
387)
388AC_SUBST([TSS_USER])
389AC_SUBST([TSS_GROUP])
390
f163b202
SB
391CFLAGS="$CFLAGS -Wreturn-type -Wsign-compare -Wswitch-enum"
392CFLAGS="$CFLAGS -Wmissing-prototypes -Wall -Werror"
e6085e96 393CFLAGS="$CFLAGS -Wformat -Wformat-security"
f163b202 394
86cc4527
SB
395dnl We have to make sure libtpms is using the same crypto library
396dnl to avoid problems
397AC_MSG_CHECKING([the crypto library libtpms is using])
398dirs=$($CC $CFLAGS -Xlinker --verbose 2>/dev/null | \
399 sed -n '/SEARCH_DIR/p' | \
400 sed 's/SEARCH_DIR("=\?\(@<:@^"@:>@\+\)"); */\1\n/g')
4c0b273b 401for dir in $dirs $LIBRARY_PATH; do
86cc4527
SB
402 if test -r $dir/libtpms.so; then
403 if test -n "`ldd $dir/libtpms.so | grep libcrypto.so`"; then
404 libtpms_cryptolib="openssl"
405 break
406 fi
407 if test -n "`ldd $dir/libtpms.so | grep libnss3.so`"; then
408 libtpms_cryptolib="freebl"
409 break
410 fi
411 fi
6286beac
SB
412 case $host_os in
413 cygwin)
414 if test -r $dir/libtpms.a; then
415 if test -n "$(nm $dir/libtpms.a | grep "U AES_encrypt")"; then
416 libtpms_cryptolib="openssl"
417 fi
418 fi
419 esac
86cc4527
SB
420done
421
422if test -z "$libtpms_cryptolib"; then
423 AC_MSG_ERROR([Could not determine libtpms crypto library.])
424fi
425
426AC_MSG_RESULT([$libtpms_cryptolib])
427
428if test "$libtpms_cryptolib" != "$cryptolib"; then
429 echo "libtpms is using $libtpms_cryptolib; we have to use the same"
430 if test "$cryptolib" == "openssl"; then
431 AC_MSG_ERROR([do not use --with-openssl])
432 else
433 AC_MSG_ERROR([use --with-openssl])
434 fi
435fi
436
6286beac
SB
437case $host_os in
438cygwin)
439 CFLAGS="$CFLAGS -D__USE_LINUX_IOCTL_DEFS"
440esac
441
58774fd6 442AC_CONFIG_FILES([Makefile \
f163b202 443 dist/swtpm.spec \
e46a2b66
SB
444 etc/Makefile \
445 samples/Makefile \
f163b202
SB
446 include/Makefile \
447 include/swtpm/Makefile \
a1fa5d77 448 include/swtpm.h \
f163b202
SB
449 src/Makefile \
450 src/selinux/Makefile \
451 src/swtpm/Makefile \
e46a2b66
SB
452 src/swtpm_bios/Makefile \
453 src/swtpm_cert/Makefile \
454 src/swtpm_ioctl/Makefile \
455 src/swtpm_setup/Makefile \
c4ac0a11 456 src/swtpm_setup/swtpm_setup.h \
f163b202 457 man/Makefile \
39d0c3de 458 man/man3/Makefile \
f163b202 459 man/man8/Makefile \
e46a2b66 460 tests/Makefile \
c4ac0a11 461 tests/test_config \
10002933
SB
462 ])
463AC_CONFIG_FILES([src/swtpm_setup/swtpm_setup.sh],
464 [chmod 755 src/swtpm_setup/swtpm_setup.sh])
f163b202
SB
465AC_OUTPUT
466
e46a2b66 467echo
c3fdf688
SB
468printf "with_gnutls : %5s (no = swtpm_cert will NOT be built)\n" $with_gnutls
469printf "with_selinux : %5s (no = SELinux policy extenions will NOT be built)\n" $with_selinux
470printf "with_cuse : %5s (no = no CUSE interface)\n" $with_cuse
498433f7 471printf "with_chardev : %5s (no = no chardev interface)\n" $with_chardev
c3fdf688 472printf "with_swtpm_setup: %5s (no = swtpm_setup will NOT be built)\n" $with_swtpm_setup
e46a2b66 473echo
10002933
SB
474echo "cryptolib: $cryptolib"
475echo
f163b202 476echo "CFLAGS=$CFLAGS"
a76b4eeb 477echo "HARDENING_CFLAGS=$HARDENING_CFLAGS"
f163b202 478echo "LDFLAGS=$LDFLAGS"
c4ac0a11
SB
479echo
480echo "TSS_USER=$TSS_USER"
481echo "TSS_GROUP=$TSS_GROUP"
482echo