Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / cf / hcrypto.m4
1 dnl Run this if we are using the bundled hcrypto for everything
2 AC_DEFUN([_OPENAFS_HCRYPTO_INTERNAL], [
3 CPPFLAGS_hcrypto=
4 LDFLAGS_hcrypto="-L\$(TOP_LIBDIR)"
5 LIB_hcrypto="-lafshcrypto"
6 hcrypto_all_target="all-internal"
7 hcrypto_install_target="install-internal"
8 ])
9
10 dnl _OPENAFS_HCRYPTO_PATHS()
11 dnl Set LDFLAGS_hcrypto and LIB_hcrypto based on the values of hcrypto_root,
12 dnl hcrypto_libdir, and hcrypto_includedir
13 AC_DEFUN([_OPENAFS_HCRYPTO_PATHS], [
14 AS_IF([test x"$hcrypto_libdir" != x],
15 [LDFLAGS_hcrypto="-L$hcrypto_libdir"],
16 [AS_IF([test x"$hcrypto_root" != x],
17 [LDFLAGS_hcrypto="-L$hcrypto_root/lib"])])
18 AS_IF([test x"$hcrypto_includedir" != x],
19 [CPPFLAGS_hcrypto="-I$hcrypto_includedir -I$hcrypto_includedir/hcrypto"],
20 [AS_IF([test x"$hcrypto_root" != x],
21 [CPPFLAGS_hcrypto="-I$hcrypto_root/include -I$hcrypto_root/include/hcrypto"])])
22 LIB_hcrypto="-lhcrypto"
23 hcrypto_all_target="all-lwp"
24 hcrypto_install_target=
25 ]
26 )
27
28 dnl _OPENAFS_HCRYPTO_CHECK($action-if-found,
29 dnl $action-if-not-found)
30 dnl Find an hcrypto library using $hcrypto_root, $hcrypto_libdir, and
31 dnl $hcrypto_includedir (global variables)
32 dnl
33 dnl If no paths were given and no usable hcrypto is found in the standard
34 dnl search paths, fall back to the built-in one. Otherwise, if no usable
35 dnl hcrypto is found, bail out.
36 AC_DEFUN([_OPENAFS_HCRYPTO_CHECK], [
37
38 _OPENAFS_HCRYPTO_PATHS()
39 save_CPPFLAGS=$CPPFLAGS
40 save_LDFLAGS=$LDFLAGS
41 save_LIBS=$LIBS
42 AS_IF([test x"$CPPFLAGS_hcrypto" != x],
43 [CPPFLAGS="$CPPFLAGS_hcrypto $CPPFLAGS"])
44 AS_IF([test x"$LDFLAGS_hcrypto" != x],
45 [LDFLAGS="$LDFLAGS_hcrypto $LDFLAGS"])
46 AS_IF([test x"$LIB_hcrypto" != x],
47 [LIBS="$LIB_hcrypto $LIBS"])
48 AS_IF([test x"$hcrypto_libdir" != x || test x"$hcrypto_includedir" != x],
49 [checkstr=" with specified include and lib paths"],
50 [AS_IF([test x"$hcrypto_root" != x],
51 [checkstr=" in $hcrypto_root"])])
52
53 AC_MSG_CHECKING([for usable system libhcrypto$checkstr])
54
55 dnl Could probably be more clever about what to check for here, but
56 dnl what we need from hcrypto should be pretty stable.
57 AC_LINK_IFELSE(
58 [AC_LANG_PROGRAM(
59 [[#include <sys/types.h>
60 #include <stdio.h>
61 #include <evp.h>
62 #include <hmac.h>]],
63 [[EVP_aes_256_cbc();
64 HMAC_Init_ex(NULL, NULL, 0, NULL, NULL);
65 RAND_bytes(NULL, 0);]])],
66 [hcrypto_found=true
67 AC_MSG_RESULT([yes])],
68 [AC_MSG_RESULT([no])])
69
70 CPPFLAGS=$save_CPPFLAGS
71 LDFLAGS=$save_LDFLAGS
72 LIBS=$save_LIBS
73
74 AS_IF([test x"$hcrypto_found" = xtrue],
75 [$1], [$2])
76 ])
77
78 AC_DEFUN([OPENAFS_HCRYPTO], [
79 AC_SUBST(CPPFLAGS_hcrypto)
80 AC_SUBST(LDFLAGS_hcrypto)
81 AC_SUBST(LIB_hcrypto)
82 AC_SUBST(hcrypto_all_target)
83 AC_SUBST(hcrypto_install_target)
84
85 AC_ARG_WITH([hcrypto],
86 [AS_HELP_STRING(
87 [--with-hcrypto=DIR],
88 [Location of the hcrypto library, or 'internal'])],
89 [AS_IF([test x"$withval" = xno],
90 [AC_MSG_ERROR("OpenAFS requires hcrypto to build")],
91 [AS_IF([test x"$withval" != xyes],
92 [hcrypto_root="$withval"])])]
93 )
94 AC_ARG_WITH([hcrypto-include],
95 [AS_HELP_STRING(
96 [--with-hcrypto-include=DIR],
97 [Location of hcrypto headers])],
98 [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
99 [hcrypto_includedir=$withval])])
100 AC_ARG_WITH([hcrypto-lib],
101 [AS_HELP_STRING(
102 [--with-hcrypto-lib=DIR],
103 [Location of the hcrypto library])],
104 [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
105 [hcrypto_libdir=$withval])])
106
107 AS_IF([test x"$hcrypto_root" = xinternal],
108 [_OPENAFS_HCRYPTO_INTERNAL()],
109 [AS_IF([test x"$hcrypto_root" = x && test x"$hcrypto_libdir" = x &&
110 test x"$hcrypto_includedir" = x],
111 [_OPENAFS_HCRYPTO_CHECK([], [_OPENAFS_HCRYPTO_INTERNAL])],
112 [_OPENAFS_HCRYPTO_CHECK([],
113 [AC_MSG_ERROR([Cannot find hcrypto at that location])])]
114 )]
115 )
116
117 ])