Add --enable-fips option. Request new gcrypt if set.
[platform/upstream/cryptsetup.git] / configure.in
1 AC_PREREQ([2.67])
2 AC_INIT([cryptsetup],[1.4.3-git])
3
4 dnl library version from <major>.<minor>.<release>[-<suffix>]
5 LIBCRYPTSETUP_VERSION=$(echo $PACKAGE_VERSION | cut -f1 -d-)
6 LIBCRYPTSETUP_VERSION_INFO=5:0:1
7
8 AC_CONFIG_SRCDIR(src/cryptsetup.c)
9 AC_CONFIG_MACRO_DIR([m4])
10
11 AC_CONFIG_HEADERS([config.h:config.h.in])
12 AM_INIT_AUTOMAKE(dist-bzip2)
13
14 if test "x$prefix" = "xNONE"; then
15         sysconfdir=/etc
16 fi
17 AC_PREFIX_DEFAULT(/usr)
18
19 AC_CANONICAL_HOST
20 AC_USE_SYSTEM_EXTENSIONS
21 AC_PROG_CC
22 AM_PROG_CC_C_O
23 AC_PROG_CPP
24 AC_PROG_INSTALL
25 AC_PROG_MAKE_SET
26 AC_ENABLE_STATIC(no)
27 LT_INIT
28
29 AC_HEADER_DIRENT
30 AC_HEADER_STDC
31 AC_CHECK_HEADERS(fcntl.h malloc.h inttypes.h sys/ioctl.h sys/mman.h \
32         ctype.h unistd.h locale.h)
33
34 AC_CHECK_HEADERS(uuid/uuid.h,,[AC_MSG_ERROR([You need the uuid library.])])
35 AC_CHECK_HEADER(libdevmapper.h,,[AC_MSG_ERROR([You need the device-mapper library.])])
36
37 saved_LIBS=$LIBS
38 AC_CHECK_LIB(uuid, uuid_clear, ,[AC_MSG_ERROR([You need the uuid library.])])
39 AC_SUBST(UUID_LIBS, $LIBS)
40 LIBS=$saved_LIBS
41
42 AC_CHECK_FUNCS([posix_memalign])
43
44 AC_C_CONST
45 AC_C_BIGENDIAN
46 AC_TYPE_OFF_T
47 AC_SYS_LARGEFILE
48
49 AC_PROG_GCC_TRADITIONAL
50
51 dnl ==========================================================================
52
53 AM_GNU_GETTEXT([external],[need-ngettext])
54 AM_GNU_GETTEXT_VERSION([0.15])
55
56 dnl ==========================================================================
57
58 saved_LIBS=$LIBS
59 AC_CHECK_LIB(popt, poptConfigFileToString,,
60         [AC_MSG_ERROR([You need popt 1.7 or newer to compile.])])
61 AC_SUBST(POPT_LIBS, $LIBS)
62 LIBS=$saved_LIBS
63
64 dnl ==========================================================================
65 dnl FIPS extensions
66 AC_ARG_ENABLE([fips], AS_HELP_STRING([--enable-fips],[enable FIPS mode restrictions]),
67 [with_fips=$enableval],
68 [with_fips=no])
69
70 if test "x$with_fips" = "xyes"; then
71         AC_DEFINE(ENABLE_FIPS, 1, [Enable FIPS mode restrictions])
72 fi
73
74 AC_DEFUN([NO_FIPS], [
75         if test "x$with_fips" = "xyes"; then
76                 AC_MSG_ERROR([This option is not compatible with FIPS.])
77         fi
78 ])
79
80 dnl ==========================================================================
81 dnl Crypto backend functions
82
83 AC_DEFUN([CONFIGURE_GCRYPT], [
84         if test "x$with_fips" = "xyes"; then
85                 GCRYPT_REQ_VERSION=1.4.5
86         else
87                 GCRYPT_REQ_VERSION=1.1.42
88         fi
89         AM_PATH_LIBGCRYPT($GCRYPT_REQ_VERSION,,[AC_MSG_ERROR([You need the gcrypt library.])])
90
91         if test x$enable_static_cryptsetup = xyes; then
92                 saved_LIBS=$LIBS
93                 LIBS="$saved_LIBS $LIBGCRYPT_LIBS -static"
94                 AC_CHECK_LIB(gcrypt, gcry_check_version,,
95                         AC_MSG_ERROR([Cannot find static gcrypt library.]),
96                         [-lgpg-error])
97                 LIBGCRYPT_STATIC_LIBS="$LIBGCRYPT_LIBS -lgpg-error"
98                 LIBS=$saved_LIBS
99         fi
100
101         CRYPTO_CFLAGS=$LIBGCRYPT_CFLAGS
102         CRYPTO_LIBS=$LIBGCRYPT_LIBS
103         CRYPTO_STATIC_LIBS=$LIBGCRYPT_STATIC_LIBS
104
105         AC_DEFINE_UNQUOTED(GCRYPT_REQ_VERSION, ["$GCRYPT_REQ_VERSION"], [Requested gcrypt version])
106 ])
107
108 AC_DEFUN([CONFIGURE_OPENSSL], [
109         PKG_CHECK_MODULES([OPENSSL], [openssl >= 0.9.8],,
110                 AC_MSG_ERROR([You need openssl library.]))
111         CRYPTO_CFLAGS=$OPENSSL_CFLAGS
112         CRYPTO_LIBS=$OPENSSL_LIBS
113
114         if test x$enable_static_cryptsetup = xyes; then
115                 saved_PKG_CONFIG=$PKG_CONFIG
116                 PKG_CONFIG="$PKG_CONFIG --static"
117                 PKG_CHECK_MODULES([OPENSSL], [openssl])
118                 CRYPTO_STATIC_LIBS=$OPENSSL_LIBS
119                 PKG_CONFIG=$saved_PKG_CONFIG
120         fi
121         NO_FIPS([])
122 ])
123
124 AC_DEFUN([CONFIGURE_NSS], [
125         if test x$enable_static_cryptsetup = xyes; then
126                 AC_MSG_ERROR([Static build of cryptsetup is not supported with NSS.])
127         fi
128
129         AC_MSG_WARN([NSS backend does NOT provide backward compatibility (missing ripemd160 hash).])
130
131         PKG_CHECK_MODULES([NSS], [nss],,
132                 AC_MSG_ERROR([You need nss library.]))
133         CRYPTO_CFLAGS=$NSS_CFLAGS
134         CRYPTO_LIBS=$NSS_LIBS
135         NO_FIPS([])
136 ])
137
138 AC_DEFUN([CONFIGURE_KERNEL], [
139         AC_CHECK_HEADERS(linux/if_alg.h,,
140                 [AC_MSG_ERROR([You need Linux kernel with userspace crypto interface.])])
141 #       AC_CHECK_DECLS([AF_ALG],,
142 #               [AC_MSG_ERROR([You need Linux kernel with userspace crypto interface.])],
143 #               [#include <sys/socket.h>])
144         NO_FIPS([])
145 ])
146
147 AC_DEFUN([CONFIGURE_NETTLE], [
148         AC_CHECK_HEADERS(nettle/sha.h,,
149                 [AC_MSG_ERROR([You need Nettle cryptographic library.])])
150
151         saved_LIBS=$LIBS
152         AC_CHECK_LIB(nettle, nettle_ripemd160_init,,
153                 [AC_MSG_ERROR([You need Nettle library version 2.4 or more recent.])])
154         CRYPTO_LIBS=$LIBS
155         LIBS=$saved_LIBS
156
157         CRYPTO_STATIC_LIBS=$CRYPTO_LIBS
158         NO_FIPS([])
159 ])
160
161 dnl ==========================================================================
162 saved_LIBS=$LIBS
163
164 AC_ARG_ENABLE([static-cryptsetup],
165         AS_HELP_STRING([--enable-static-cryptsetup],
166         [enable build of static cryptsetup binary]))
167 if test x$enable_static_cryptsetup = xyes; then
168         if test x$enable_static = xno; then
169                 AC_MSG_WARN([Requested static cryptsetup build, enabling static library.])
170                 enable_static=yes
171         fi
172 fi
173 AM_CONDITIONAL(STATIC_CRYPTSETUP, test x$enable_static_cryptsetup = xyes)
174
175 AC_ARG_ENABLE(selinux,
176         AS_HELP_STRING([--disable-selinux],
177         [disable selinux support [default=auto]]),[], [])
178
179 AC_ARG_ENABLE([udev],
180         AS_HELP_STRING([--disable-udev],
181         [disable udev support]),[], enable_udev=yes)
182
183 dnl Try to use pkg-config for devmapper, but fallback to old detection
184 PKG_CHECK_MODULES([DEVMAPPER], [devmapper >= 1.02.03],, [
185         AC_CHECK_LIB(devmapper, dm_task_set_name,,
186                 [AC_MSG_ERROR([You need the device-mapper library.])])
187         AC_CHECK_LIB(devmapper, dm_task_set_message,,
188                 [AC_MSG_ERROR([The device-mapper library on your system is too old.])])
189         DEVMAPPER_LIBS=$LIBS
190 ])
191 LIBS=$saved_LIBS
192
193 LIBS="$LIBS $DEVMAPPER_LIBS"
194 AC_CHECK_DECLS([dm_task_secure_data], [], [], [#include <libdevmapper.h>])
195 AC_CHECK_DECLS([dm_task_retry_remove], [], [], [#include <libdevmapper.h>])
196 AC_CHECK_DECLS([DM_UDEV_DISABLE_DISK_RULES_FLAG], [have_cookie=yes], [have_cookie=no], [#include <libdevmapper.h>])
197 if test "x$enable_udev" = xyes; then
198         if test "x$have_cookie" = xno; then
199                 AC_MSG_WARN([The device-mapper library on your system has no udev support, udev support disabled.])
200         else
201                 AC_DEFINE(USE_UDEV, 1, [Try to use udev synchronisation?])
202         fi
203 fi
204 LIBS=$saved_LIBS
205
206 dnl Crypto backend configuration.
207 AC_ARG_WITH([crypto_backend],
208         AS_HELP_STRING([--with-crypto_backend=BACKEND], [crypto backend (gcrypt/openssl/nss/kernel/nettle) [gcrypt]]),
209         [], with_crypto_backend=gcrypt
210 )
211 case $with_crypto_backend in
212         gcrypt)  CONFIGURE_GCRYPT([]) ;;
213         openssl) CONFIGURE_OPENSSL([]) ;;
214         nss)     CONFIGURE_NSS([]) ;;
215         kernel)  CONFIGURE_KERNEL([]) ;;
216         nettle)  CONFIGURE_NETTLE([]) ;;
217         *) AC_MSG_ERROR([Unknown crypto backend.]) ;;
218 esac
219 AM_CONDITIONAL(CRYPTO_BACKEND_GCRYPT,  test $with_crypto_backend = gcrypt)
220 AM_CONDITIONAL(CRYPTO_BACKEND_OPENSSL, test $with_crypto_backend = openssl)
221 AM_CONDITIONAL(CRYPTO_BACKEND_NSS,     test $with_crypto_backend = nss)
222 AM_CONDITIONAL(CRYPTO_BACKEND_KERNEL,  test $with_crypto_backend = kernel)
223 AM_CONDITIONAL(CRYPTO_BACKEND_NETTLE,  test $with_crypto_backend = nettle)
224
225 dnl Magic for cryptsetup.static build.
226 if test x$enable_static_cryptsetup = xyes; then
227         saved_PKG_CONFIG=$PKG_CONFIG
228         PKG_CONFIG="$PKG_CONFIG --static"
229
230         LIBS="$saved_LIBS -static"
231         AC_CHECK_LIB(popt, poptGetContext,,
232                 AC_MSG_ERROR([Cannot find static popt library.]))
233
234         dnl Try to detect needed device-mapper static libraries, try pkg-config first.
235         LIBS="$saved_LIBS -static"
236         PKG_CHECK_MODULES([DEVMAPPER_STATIC], [devmapper >= 1.02.27],,[
237                 DEVMAPPER_STATIC_LIBS=$DEVMAPPER_LIBS
238                 if test "x$enable_selinux" != xno; then
239                         AC_CHECK_LIB(sepol, sepol_bool_set)
240                         AC_CHECK_LIB(selinux, is_selinux_enabled)
241                         DEVMAPPER_STATIC_LIBS="$DEVMAPPER_STATIC_LIBS $LIBS"
242                 fi
243         ])
244         LIBS="$saved_LIBS $DEVMAPPER_STATIC_LIBS"
245         AC_CHECK_LIB(devmapper, dm_task_set_uuid,,
246                 AC_MSG_ERROR([Cannot link with static device-mapper library.]))
247
248         dnl Try to detect uuid static library.
249         LIBS="$saved_LIBS -static"
250         AC_CHECK_LIB(uuid, uuid_generate,,
251                 AC_MSG_ERROR([Cannot find static uuid library.]))
252
253         LIBS=$saved_LIBS
254         PKG_CONFIG=$saved_PKG_CONFIG
255 fi
256
257 AC_SUBST([DEVMAPPER_LIBS])
258 AC_SUBST([DEVMAPPER_STATIC_LIBS])
259
260 AC_SUBST([CRYPTO_CFLAGS])
261 AC_SUBST([CRYPTO_LIBS])
262 AC_SUBST([CRYPTO_STATIC_LIBS])
263
264 AC_SUBST([LIBCRYPTSETUP_VERSION])
265 AC_SUBST([LIBCRYPTSETUP_VERSION_INFO])
266
267 dnl ==========================================================================
268 AC_ARG_ENABLE([dev-random], AS_HELP_STRING([--enable-dev-random],
269 [use blocking /dev/random by default for key generator (otherwise use /dev/urandom)]),
270 [default_rng=/dev/random], [default_rng=/dev/urandom])
271 AC_DEFINE_UNQUOTED(DEFAULT_RNG, ["$default_rng"], [default RNG type for key generator])
272
273 dnl ==========================================================================
274 AC_DEFUN([CS_DEFINE],
275         [AC_DEFINE_UNQUOTED(DEFAULT_[]m4_translit([$1], [-a-z], [_A-Z]), [$2], [$3])
276 ])
277
278 AC_DEFUN([CS_STR_WITH], [AC_ARG_WITH([$1],
279         [AS_HELP_STRING(--with-[$1], [default $2 [$3]])],
280         [CS_DEFINE([$1], ["$withval"], [$2])],
281         [CS_DEFINE([$1], ["$3"], [$2])]
282 )])
283
284 AC_DEFUN([CS_NUM_WITH], [AC_ARG_WITH([$1],
285         [AS_HELP_STRING(--with-[$1], [default $2 [$3]])],
286         [CS_DEFINE([$1], [$withval], [$2])],
287         [CS_DEFINE([$1], [$3], [$2])]
288 )])
289
290 dnl ==========================================================================
291 dnl Python bindings
292 AC_ARG_ENABLE([python], AS_HELP_STRING([--enable-python],[enable Python bindings]),
293 [with_python=$enableval],
294 [with_python=no])
295
296 if test "x$with_python" = "xyes"; then
297         AM_PATH_PYTHON([2.4])
298
299         if ! test -x "$PYTHON-config" ; then
300             AC_MSG_ERROR([Cannot find python development packages to build bindings])
301         fi
302
303         PYTHON_INCLUDES=$($PYTHON-config --includes)
304         AC_SUBST(PYTHON_INCLUDES)
305 fi
306 AM_CONDITIONAL([PYTHON_CRYPTSETUP], [test "x$with_python" = "xyes"])
307
308 dnl ==========================================================================
309 CS_STR_WITH([plain-hash],   [password hashing function for plain mode], [ripemd160])
310 CS_STR_WITH([plain-cipher], [cipher for plain mode], [aes])
311 CS_STR_WITH([plain-mode],   [cipher mode for plain mode], [cbc-essiv:sha256])
312 CS_NUM_WITH([plain-keybits],[key length in bits for plain mode], [256])
313
314 CS_STR_WITH([luks1-hash],   [hash function for LUKS1 header], [sha1])
315 CS_STR_WITH([luks1-cipher], [cipher for LUKS1], [aes])
316 CS_STR_WITH([luks1-mode],   [cipher mode for LUKS1], [cbc-essiv:sha256])
317 CS_NUM_WITH([luks1-keybits],[key length in bits for LUKS1], [256])
318
319 CS_STR_WITH([loopaes-cipher], [cipher for loop-AES mode], [aes])
320 CS_NUM_WITH([loopaes-keybits],[key length in bits for loop-AES mode], [256])
321
322 CS_NUM_WITH([keyfile-size-maxkb],[maximum keyfile size (in kilobytes)], [8192])
323 CS_NUM_WITH([passphrase-size-max],[maximum keyfile size (in kilobytes)], [512])
324
325 dnl ==========================================================================
326
327 AC_CONFIG_FILES([ Makefile
328 lib/Makefile
329 lib/libcryptsetup.pc
330 lib/crypto_backend/Makefile
331 lib/luks1/Makefile
332 lib/loopaes/Makefile
333 src/Makefile
334 po/Makefile.in
335 man/Makefile
336 tests/Makefile
337 python/Makefile
338 ])
339 AC_OUTPUT