]> git.proxmox.com Git - swtpm.git/blame - configure.ac
build-sys: Fix hard coded /etc path and replace with @SYSCONFDIR@
[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
908afaf5 43LT_INIT
f163b202 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
33be7be2 66 if test "$DEBUG" = "yes"; then
f163b202
SB
67 CFLAGS="-O0 -g -DDEBUG"
68 else
69 CFLAGS="-g -O2"
70 fi
33be7be2 71elif test "$DEBUG" = "yes"; then
f163b202
SB
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)
33be7be2 103 if test "x$SEMODULE" = "x"; then
ec37bb56
SB
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
33be7be2 115AM_CONDITIONAL([WITH_SELINUX], [test "x$with_selinux" = "xyes"])
ec37bb56 116
b096be26
SB
117if test "$prefix" = "/usr" && test "$sysconfdir" = '${prefix}/etc'; then
118 sysconfdir="/etc"
119fi
120if test "$prefix" = "" && test "$datarootdir" = '${prefix}/share'; then
121 datarootdir="/usr/share"
122fi
0432b653
SB
123SYSCONFDIR=`eval echo $sysconfdir`
124DATAROOTDIR=`eval echo $datarootdir`
125AC_SUBST([SYSCONFDIR])
126AC_SUBST([DATAROOTDIR])
b096be26 127
7849b6c6 128cryptolib=openssl
3bbdd7bc
SB
129
130AC_ARG_WITH([openssl],
7849b6c6
SB
131 [AS_HELP_STRING([--with-openssl],
132 [build with openssl library])],
133 [],
134 [])
3bbdd7bc
SB
135
136case "$cryptolib" in
3bbdd7bc 137openssl)
7849b6c6
SB
138 AC_CHECK_LIB(crypto,
139 [AES_set_encrypt_key],
b78b6af2 140 [true],
7849b6c6
SB
141 AC_MSG_ERROR(Faulty openssl crypto library))
142 AC_CHECK_HEADERS([openssl/aes.h],[],
143 AC_MSG_ERROR(Is openssl-devel/libssl-dev installed?))
144 AC_MSG_RESULT([Building with openssl crypto library])
145 ;;
3bbdd7bc 146esac
833a5416 147
baecda40
SB
148LIBTASN1_LIBS=$(pkg-config --libs libtasn1)
149if test $? -ne 0; then
150 AC_MSG_ERROR("Is libtasn1-devel installed? -- could not get libs for libtasn1")
151fi
152AC_SUBST([LIBTASN1_LIBS])
f163b202 153
baecda40
SB
154LIBTPMS_LIBS=$(pkg-config --libs libtpms)
155if test $? -ne 0; then
156 AC_MSG_ERROR("Is libtpms-devel installed? -- could not get libs for libtpms")
157fi
fbc596ab 158AC_CHECK_LIB(tpms,
b78b6af2 159 TPMLIB_ChooseTPMVersion,[true],
fbc596ab
SB
160 AC_MSG_ERROR("libtpms 0.6 or later is required")
161)
baecda40 162AC_SUBST([LIBTPMS_LIBS])
f163b202 163
5478de0a
SB
164AC_CHECK_LIB(c, clock_gettime, LIBRT_LIBS="", LIBRT_LIBS="-lrt")
165AC_SUBST([LIBRT_LIBS])
166
e46a2b66 167AC_PATH_PROG([TPM_NVDEFINE], tpm_nvdefine)
ef606d4a 168if test "x$TPM_NVDEFINE" = "x"; then
64faf455 169 have_tcsd=no
ef606d4a
SB
170 AC_MSG_WARN([NVRAM area tools are needed for TPM 1.2 certificate injection: tpm-tools package])
171else
172 have_tcsd=yes
173fi
64faf455
SB
174with_swtpm_setup=yes
175AM_CONDITIONAL([HAVE_TCSD], test "$have_tcsd" != "no")
e46a2b66 176
5cd844d0
SB
177dnl If we have the tcsd package, we can build swtpm_setup, but need netstat also
178AC_PATH_PROG([NETSTAT], [netstat])
179case $host_os in
180linux-*)
33be7be2 181 if test "x$NETSTAT" = "x" && test "have_tcsd" != "no"; then
64faf455 182 AC_MSG_ERROR([netstat tool is missing for tests: net-tools package])
5cd844d0
SB
183 fi
184 ;;
185esac
186
09d1a532
SB
187AC_MSG_CHECKING([for whether to build with CUSE interface])
188AC_ARG_WITH([cuse],
189 AC_HELP_STRING([--with-cuse],
190 [build with CUSE interface]),
191 [],
192 [with_cuse=check]
193)
f163b202 194
09d1a532
SB
195if test "$with_cuse" != "no"; then
196 LIBFUSE_CFLAGS=$(pkg-config fuse --cflags 2>/dev/null)
197 if test $? -ne 0; then
198 if test "$with_cuse" = "yes"; then
199 AC_MSG_ERROR("Is fuse-devel installed? -- could not get cflags for libfuse")
200 else
201 with_cuse=no
202 fi
203 else
204 with_cuse=yes
205 fi
498433f7 206fi
09d1a532
SB
207
208dnl with_cuse is now yes or no
209if test "$with_cuse" != "no"; then
210 LIBFUSE_LIBS=$(pkg-config fuse --libs)
211 if test $? -ne 0; then
212 AC_MSG_ERROR("Is fuse-devel installed? -- could not get libs for libfuse")
213 fi
214 AC_SUBST([LIBFUSE_CFLAGS])
215 AC_SUBST([LIBFUSE_LIBS])
216 AC_DEFINE_UNQUOTED([WITH_CUSE], 1,
217 [whether to build with CUSE interface])
ebf1557d
SB
218
219 GLIB_CFLAGS=$(pkg-config --cflags glib-2.0)
220 if test $? -ne 0; then
221 AC_MSG_ERROR("Is glib-2.0 installed? -- could not get cflags")
222 fi
223 AC_SUBST([GLIB_CFLAGS])
224
225 GLIB_LIBS=$(pkg-config --libs glib-2.0)
226 if test $? -ne 0; then
227 AC_MSG_ERROR("Is glib-2.0 installed? -- could not get libs")
228 fi
229 AC_SUBST([GLIB_LIBS])
230
231 GTHREAD_LIBS=$(pkg-config --libs gthread-2.0)
232 if test $? -ne 0; then
233 AC_MSG_ERROR("Is glib-2.0 installed? -- could not get libs for gthread-2.0")
234 fi
235 AC_SUBST([GTHREAD_LIBS])
baecda40 236fi
09d1a532
SB
237AM_CONDITIONAL([WITH_CUSE],[test "$with_cuse" = "yes"])
238AC_MSG_RESULT($with_cuse)
f163b202 239
498433f7
SB
240AC_MSG_CHECKING([for whether to build with chardev interface])
241case $host_os in
242linux-*)
243 with_chardev=yes
244 AC_DEFINE_UNQUOTED([WITH_CHARDEV], 1,
245 [whether to build with chardev interface])
246 ;;
247*)
248 with_chardev=no
249esac
250AM_CONDITIONAL([WITH_CHARDEV],[test "$with_chardev" = "yes"])
251AC_MSG_RESULT($with_cuse)
252
10002933
SB
253AC_ARG_WITH([gnutls],
254 AC_HELP_STRING([--with-gnutls],
255 [build with gnutls library]),
256 [],
257 [with_gnutls=check]
258)
259
e46a2b66
SB
260if test "x$with_gnutls" != "xno"; then
261 GNUTLS_LDFLAGS=$(pkg-config --libs gnutls)
262 if test $? -ne 0; then
33be7be2 263 if test "x$with_gnutls" = "xyes"; then
e46a2b66
SB
264 AC_MSG_ERROR("Is gnutls installed? -- could not get libs for gnutls")
265 else
266 with_gnutls=no
267 fi
268 fi
269fi
f163b202 270
1828edee
SB
271if test "x$with_gnutls" != "xno"; then
272 AC_PATH_PROG([GNUTLS_CERTTOOL], certtool)
33be7be2
SB
273 if test "x$GNUTLS_CERTTOOL" = "x"; then
274 if test "x$with_gnutls" = "xyes"; then
1828edee
SB
275 AC_MSG_ERROR("Could not find certtool. Is gnutls-utils/gnutls-bin installed?")
276 else
277 with_gnutls=no
278 fi
279 fi
280fi
281
e46a2b66 282if test "x$with_gnutls" != "xno"; then
571a8eed 283 ORIG_CFLAGS="$CFLAGS"
baecda40 284 GNUTLS_CFLAGS=$(pkg-config gnutls --cflags)
571a8eed 285 CFLAGS="$CFLAGS $GNUTLS_CFLAGS $GNUTLS_LDFLAGS"
10002933 286 AC_CHECK_LIB([gnutls], [gnutls_load_file], [
baecda40
SB
287 GNUTLS_LIBS=-lgnutls
288 ],
33be7be2 289 [if test "x$with_gnutls" = "xyes"; then
e46a2b66
SB
290 AC_MSG_ERROR([GNUTLS >= 3.1.0 library not found: libgnutls.so])
291 else
292 with_gnutls="no"
293 fi])
571a8eed 294 CFLAGS="$ORIG_CFLAGS"
e46a2b66
SB
295fi
296
297if test "x$with_gnutls" != "xno"; then
571a8eed
SB
298 ORIG_CFLAGS="$CFLAGS"
299 CFLAGS="$CFLAGS $GNUTLS_CFLAGS"
e46a2b66 300 AC_CHECK_HEADER(gnutls/abstract.h, [], \
33be7be2 301 [if test "x$with_gnutls" = "xyes"; then
e46a2b66
SB
302 AC_MSG_ERROR([GNUTLS >= 3.1.0 library header not found: gnutls/abstract.h])
303 else
304 with_gnutls="no"
305 fi])
571a8eed 306 CFLAGS="$ORIG_CFLAGS"
e46a2b66
SB
307fi
308
309if test "x$with_gnutls" != "xno"; then
310 with_gnutls="yes"
311fi
33be7be2 312AM_CONDITIONAL([WITH_GNUTLS], [test "x$with_gnutls" = "xyes"])
baecda40 313AC_SUBST([GNUTLS_LIBS])
f163b202 314
48abfbb1 315AC_PATH_PROG([EXPECT], expect)
33be7be2 316if test "x$EXPECT" = "x"; then
48abfbb1
SB
317 AC_MSG_ERROR([expect is required: expect package])
318fi
319
b080afb5 320AC_PATH_PROG([GAWK], gawk)
33be7be2 321if test "x$GAWK" = "x"; then
b080afb5
SB
322 AC_MSG_ERROR([gawk is required: gawk package])
323fi
324
8cb126e4 325AC_PATH_PROG([SOCAT], socat)
33be7be2 326if test "x$SOCAT" = "x"; then
8cb126e4
SB
327 AC_MSG_ERROR([socat is required: socat package])
328fi
329
b4372fe5 330AC_PATH_PROG([PYTHON], python3)
33be7be2 331if test "x$PYTHON" = "x"; then
b4372fe5 332 AC_MSG_ERROR([python3 is required])
dbb399de
SB
333fi
334
5eeea357
SB
335AC_ARG_ENABLE([hardening],
336 AS_HELP_STRING([--disable-hardening], [Disable hardening flags]))
a76b4eeb 337
5eeea357
SB
338if test "x$enable_hardening" != "xno"; then
339 TMP="$($CC -fstack-protector-strong $srcdir/include/swtpm/tpm_ioctl.h 2>&1)"
340 if echo $TMP | $GREP 'unrecognized command line option' >/dev/null; then
341 HARDENING_CFLAGS="-fstack-protector -Wstack-protector "
342 else
343 HARDENING_CFLAGS="-fstack-protector-strong -Wstack-protector "
344 fi
345
346 dnl Must not have -O0 but must have a -O for -D_FORTIFY_SOURCE=2
347 TMP1="$(echo $CFLAGS | sed -n 's/.*\(-O0\).*/\1/p')"
348 TMP2="$(echo $CFLAGS | sed -n 's/.*\(-O\).*/\1/p')"
349 if test -z "$TMP1" && test -n "$TPM2"; then
350 HARDENING_CFLAGS="$HARDENING_CFLAGS -D_FORTIFY_SOURCE=2 "
351 fi
352 dnl Check ld for 'relro' and 'now'
353 if $LD --help 2>&1 | $GREP '\-z relro ' > /dev/null; then
354 HARDENING_CFLAGS="$HARDENING_CFLAGS -Wl,-z,relro "
355 fi
356 if $LD --help 2>&1 | $GREP '\-z now ' > /dev/null; then
357 HARDENING_CFLAGS="$HARDENING_CFLAGS -Wl,-z,now "
358 fi
359 AC_SUBST([HARDENING_CFLAGS])
a76b4eeb 360fi
e6085e96 361
b8421f3d
SB
362AC_ARG_ENABLE([test-coverage],
363 AS_HELP_STRING([--enable-test-coverage], [Enable test coverage flags]))
364
365if test "x$enable_test_coverage" = "xyes"; then
366 COVERAGE_CFLAGS="-fprofile-arcs -ftest-coverage"
367 COVERAGE_LDFLAGS="-fprofile-arcs"
368fi
369
c4ac0a11
SB
370AC_ARG_WITH([tss-user],
371 AC_HELP_STRING([--with-tss-user=TSS_USER],
372 [The tss user to use]),
373 [TSS_USER="$withval"],
374 [TSS_USER="tss"]
375)
376
377AC_ARG_WITH([tss-group],
378 AC_HELP_STRING([--with-tss-group=TSS_GROUP],
379 [The tss group to use]),
380 [TSS_GROUP="$withval"],
381 [TSS_GROUP="tss"]
382)
383AC_SUBST([TSS_USER])
384AC_SUBST([TSS_GROUP])
385
f163b202
SB
386CFLAGS="$CFLAGS -Wreturn-type -Wsign-compare -Wswitch-enum"
387CFLAGS="$CFLAGS -Wmissing-prototypes -Wall -Werror"
e6085e96 388CFLAGS="$CFLAGS -Wformat -Wformat-security"
b8421f3d
SB
389CFLAGS="$CFLAGS $GNUTLS_CFLAGS $COVERAGE_CFLAGS"
390
391LDFLAGS="$LDFLAGS $COVERAGE_LDFLAGS"
f163b202 392
f2458ef7
SB
393dnl Simulate the following for systems with pkg-config < 0.28:
394dnl PKG_CHECK_VAR([libtpms_cryptolib], [libtpms], [cryptolib],
395dnl [], AC_MSG_ERROR([Could not determine libtpms crypto library.]))
396PKG_PROG_PKG_CONFIG
397
398AC_MSG_CHECKING([Checking the crypto library libtpms is linked to])
399libtpms_cryptolib=`$PKG_CONFIG --variable cryptolib libtpms`
33be7be2 400if test "x$libtpms_cryptolib" = "x"; then
f2458ef7
SB
401 AC_MSG_ERROR([Could not determine the crypto library libtpms is using])
402fi
403AC_MSG_RESULT($libtpms_cryptolib)
86cc4527
SB
404
405if test "$libtpms_cryptolib" != "$cryptolib"; then
406 echo "libtpms is using $libtpms_cryptolib; we have to use the same"
33be7be2 407 if test "$cryptolib" = "openssl"; then
86cc4527
SB
408 AC_MSG_ERROR([do not use --with-openssl])
409 else
410 AC_MSG_ERROR([use --with-openssl])
411 fi
412fi
413
c751e32e
SB
414with_vtpm_proxy=no
415case $host_os in
f071d820 416linux-*)
c751e32e
SB
417 with_vtpm_proxy=yes
418 AC_DEFINE_UNQUOTED([WITH_VTPM_PROXY], 1,
419 [whether to build in vTPM proxy support (Linux only)])
420esac
421
6286beac
SB
422case $host_os in
423cygwin)
424 CFLAGS="$CFLAGS -D__USE_LINUX_IOCTL_DEFS"
425esac
426
58774fd6 427AC_CONFIG_FILES([Makefile \
f163b202 428 dist/swtpm.spec \
e46a2b66 429 etc/Makefile \
0432b653 430 etc/swtpm_setup.conf \
e46a2b66 431 samples/Makefile \
f163b202
SB
432 include/Makefile \
433 include/swtpm/Makefile \
a1fa5d77 434 include/swtpm.h \
f163b202
SB
435 src/Makefile \
436 src/selinux/Makefile \
437 src/swtpm/Makefile \
e46a2b66
SB
438 src/swtpm_bios/Makefile \
439 src/swtpm_cert/Makefile \
440 src/swtpm_ioctl/Makefile \
441 src/swtpm_setup/Makefile \
c4ac0a11 442 src/swtpm_setup/swtpm_setup.h \
f163b202 443 man/Makefile \
39d0c3de 444 man/man3/Makefile \
f163b202 445 man/man8/Makefile \
e46a2b66 446 tests/Makefile \
c4ac0a11 447 tests/test_config \
10002933
SB
448 ])
449AC_CONFIG_FILES([src/swtpm_setup/swtpm_setup.sh],
450 [chmod 755 src/swtpm_setup/swtpm_setup.sh])
0432b653
SB
451AC_CONFIG_FILES([samples/swtpm-localca],
452 [chmod 755 samples/swtpm-localca])
f163b202
SB
453AC_OUTPUT
454
e46a2b66 455echo
c3fdf688
SB
456printf "with_gnutls : %5s (no = swtpm_cert will NOT be built)\n" $with_gnutls
457printf "with_selinux : %5s (no = SELinux policy extenions will NOT be built)\n" $with_selinux
458printf "with_cuse : %5s (no = no CUSE interface)\n" $with_cuse
498433f7 459printf "with_chardev : %5s (no = no chardev interface)\n" $with_chardev
c3fdf688 460printf "with_swtpm_setup: %5s (no = swtpm_setup will NOT be built)\n" $with_swtpm_setup
c751e32e 461printf "with_vtpm_proxy : %5s (no = no vtpm proxy support; Linux only)\n" $with_vtpm_proxy
e46a2b66 462echo
10002933
SB
463echo "cryptolib: $cryptolib"
464echo
f163b202 465echo "CFLAGS=$CFLAGS"
a76b4eeb 466echo "HARDENING_CFLAGS=$HARDENING_CFLAGS"
f163b202 467echo "LDFLAGS=$LDFLAGS"
c4ac0a11
SB
468echo
469echo "TSS_USER=$TSS_USER"
470echo "TSS_GROUP=$TSS_GROUP"
471echo