Allow external hcrypto
authorBenjamin Kaduk <kaduk@mit.edu>
Tue, 23 Sep 2014 22:19:09 +0000 (18:19 -0400)
committerD Brashear <shadow@your-file-system.com>
Wed, 8 Oct 2014 14:54:40 +0000 (10:54 -0400)
Put the configure checks into a separate file in src/cf, following
the same general structure as the roken checks.

Allow explicitly requesting the internal version, or checking
what's in the default paths, or providing a specific hcrypto root
or lib/include dirs for Debian compatibility.

We must still always compile libafshcrypto_lwp.a for use by LWP
binaries, from the bundled sources, but other binaries will use
the system version.

The hcrypto headers have an unfortunately large number of dependencies,
including depending on being able to find each other by including
<hcrypto/foo.h> paths.  As such we must pass both the user-supplied
directory and $dir/hcrypto to the preprocessor in order for things
to work, and we also may need to revisit the includes used in the
configure check for use on non-linux systems due to the dependencies
on system headers.

Change-Id: Idcba1418a19a7b562335524c911d69dc84268177
Reviewed-on: http://gerrit.openafs.org/11481
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: D Brashear <shadow@your-file-system.com>
Tested-by: D Brashear <shadow@your-file-system.com>

acinclude.m4
src/cf/hcrypto.m4 [new file with mode: 0644]
src/crypto/hcrypto/Makefile.in

index 7c277ac..85a4854 100644 (file)
@@ -1561,6 +1561,7 @@ AC_CHECK_FUNCS([ \
 ])
 
 OPENAFS_ROKEN()
+OPENAFS_HCRYPTO()
 OPENAFS_C_ATTRIBUTE()
 
 dnl Functions that Heimdal's libroken provides, but that we
@@ -1982,12 +1983,6 @@ OPENAFS_HAVE_STRUCT_FIELD(struct rusage, ru_idrss,
 #include <sys/resource.h>
 #endif])
 
-dnl Eventually, this will look for the system one, or for OpenSSL
-LIB_hcrypto="-lafshcrypto"
-LDFLAGS_hcrypto="-L\$(TOP_LIBDIR)"
-AC_SUBST(LIB_hcrypto)
-AC_SUBST(LDFLAGS_hcrypto)
-
 dnl Check for UUID library
 AC_CHECK_HEADERS([uuid/uuid.h])
 AC_CHECK_LIB(uuid, uuid_generate, LIBS_uuid="-luuid")
diff --git a/src/cf/hcrypto.m4 b/src/cf/hcrypto.m4
new file mode 100644 (file)
index 0000000..2a99988
--- /dev/null
@@ -0,0 +1,114 @@
+dnl Run this if we are using the bundled hcrypto for everything
+AC_DEFUN([_OPENAFS_HCRYPTO_INTERNAL], [
+  CPPFLAGS_hcrypto=
+  LDFLAGS_hcrypto="-L\$(TOP_LIBDIR)"
+  LIB_hcrypto="-lafshcrypto"
+  hcrypto_all_target="all-internal"
+  hcrypto_install_target="install-internal"
+])
+
+dnl _OPENAFS_HCRYPTO_PATHS()
+dnl Set LDFLAGS_hcrypto and LIB_hcrypto based on the values of hcrypto_root,
+dnl hcrypto_libdir, and hcrypto_includedir
+AC_DEFUN([_OPENAFS_HCRYPTO_PATHS], [
+  AS_IF([test x"$hcrypto_libdir" != x],
+    [LDFLAGS_hcrypto="-L$hcrypto_libdir"],
+    [AS_IF([test x"$hcrypto_root" != x],
+      [LDFLAGS_hcrypto="-L$hcrypto_root/lib"])])
+  AS_IF([test x"$hcrypto_includedir" != x],
+    [CPPFLAGS_hcrypto="-I$hcrypto_includedir -I$hcrypto_includedir/hcrypto"],
+    [AS_IF([test x"$hcrypto_root" != x],
+      [CPPFLAGS_hcrypto="-I$hcrypto_root/include -I$hcrypto_root/include/hcrypto"])])
+  LIB_hcrypto="-lhcrypto"
+  hcrypto_all_target="all-lwp"
+  hcrypto_install_target=
+  ]
+)
+
+dnl _OPENAFS_HCRYPTO_CHECK($action-if-found,
+dnl                        $action-if-not-found)
+dnl Find an hcrypto library using $hcrypto_root, $hcrypto_libdir, and
+dnl $hcrypto_includedir (global variables)
+dnl
+dnl If no paths were given and no usable hcrypto is found in the standard
+dnl search paths, fall back to the built-in one.  Otherwise, if no usable
+dnl hcrypto is found, bail out.
+AC_DEFUN([_OPENAFS_HCRYPTO_CHECK], [
+
+  _OPENAFS_HCRYPTO_PATHS()
+  save_CPPFLAGS=$CPPFLAGS
+  save_LDFLAGS=$LDFLAGS
+  save_LIBS=$LIBS
+  AS_IF([test x"$CPPFLAGS_hcrypto" != x],
+    [CPPFLAGS="$CPPFLAGS_hcrypto $CPPFLAGS"])
+  AS_IF([test x"$LDFLAGS_hcrypto" != x],
+    [LDFLAGS="$LDFLAGS_hcrypto $LDFLAGS"])
+  AS_IF([test x"$LIB_hcrypto" != x],
+    [LIBS="$LIB_hcrypto $LIBS"])
+  AS_IF([test x"$hcrypto_libdir" != x || test x"$hcrypto_includedir" != x],
+    [checkstr=" with specified include and lib paths"],
+    [AS_IF([test x"$hcrypto_root" != x],
+      [checkstr=" in $hcrypto_root"])])
+
+  AC_MSG_CHECKING([for usable system libhcrypto$checkstr])
+
+  dnl Could probably be more clever about what to check for here, but
+  dnl what we need from hcrypto should be pretty stable.
+  AC_LINK_IFELSE(
+    [AC_LANG_PROGRAM(
+      [[#include <sys/types.h>
+#include <stdio.h>
+#include <evp.h>
+#include <hmac.h>]],
+      [[EVP_aes_256_cbc();
+HMAC_Init_ex(NULL, NULL, 0, NULL, NULL);
+RAND_bytes(NULL, 0);]])],
+    [hcrypto_found=true
+    AC_MSG_RESULT([yes])],
+    [AC_MSG_RESULT([no])])
+
+  CPPFLAGS=$save_CPPFLAGS
+  LDFLAGS=$save_LDFLAGS
+  LIBS=$save_LIBS
+
+  AS_IF([test x"$hcrypto_found" = xtrue],
+    [$1], [$2])
+])
+
+AC_DEFUN([OPENAFS_HCRYPTO], [
+  AC_SUBST(CPPFLAGS_hcrypto)
+  AC_SUBST(LDFLAGS_hcrypto)
+  AC_SUBST(LIB_hcrypto)
+  AC_SUBST(hcrypto_all_target)
+  AC_SUBST(hcrypto_install_target)
+
+  AC_ARG_WITH([hcrypto],
+    [AC_HELP_STRING([--with-hcrypto=DIR],
+      [Location of the hcrypto library, or 'internal'])],
+    [AS_IF([test x"$withval" = xno],
+      [AC_ERROR("OpenAFS requires hcrypto to build")],
+      [AS_IF([test x"$withval" != xyes],
+       [hcrypto_root="$withval"])])]
+  )
+  AC_ARG_WITH([hcrypto-include],
+    [AC_HELP_STRING([--with-hcrypto-include=DIR],
+      [Location of hcrypto headers])],
+    [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
+      [hcrypto_includedir=$withval])])
+  AC_ARG_WITH([hcrypto-lib],
+    [AC_HELP_STRING([--with-hcrypto-lib=DIR],
+      [Location of the hcrypto library])],
+    [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
+      [hcrypto_libdir=$withval])])
+
+  AS_IF([test x"$hcrypto_root" = xinternal],
+    [_OPENAFS_HCRYPTO_INTERNAL()],
+    [AS_IF([test x"$hcrypto_root" = x && test x"$hcrypto_libdir" = x &&
+       test x"$hcrypto_includedir" = x],
+      [_OPENAFS_HCRYPTO_CHECK([], [_OPENAFS_HCRYPTO_INTERNAL])],
+      [_OPENAFS_HCRYPTO_CHECK([],
+       [AC_MSG_ERROR([Cannot find hcrypto at that location])])]
+      )]
+  )
+
+])
index 6a0eb44..77e8fdb 100644 (file)
@@ -35,13 +35,19 @@ MODULE_INCLUDE=-I${srcdir} -I${TOP_INCDIR}/hcrypto -I$(UPSTREAM)/hcrypto
 
 SHLIBOBJ= libafshcrypto.${SHLIB_SUFFIX}.${LIBMAJOR}.${LIBMINOR}
 
-all: ${HEADERS} ${TOP_LIBDIR}/${SHLIBOBJ} \
+all: @hcrypto_all_target@
+
+all-internal: ${HEADERS} ${TOP_LIBDIR}/${SHLIBOBJ} \
        ${TOP_LIBDIR}/libafshcrypto.a \
        ${TOP_LIBDIR}/libafshcrypto_lwp.a
 
+all-lwp: ${HEADERS} ${TOP_LIBDIR}/libafshcrypto_lwp.a
+
 buildtools: ${HEADERS} ${TOP_LIBDIR}/libafshcrypto.a
 
-install: libafshcrypto.a ${SHLIBOBJ}
+install: @hcrypto_install_target@
+
+install-internal: libafshcrypto.a ${SHLIBOBJ}
        ${TOP_OBJDIR}/src/config/shlib-install -d ${DESTDIR}${libdir} \
                -l libafshcrypto -M ${LIBMAJOR} -m ${LIBMINOR}
        ${INSTALL_DATA} libafshcrypto.a ${DESTDIR}${libdir}/libafshcrypto.a