From a6d7014187e238c9659141919d3c0934aac61f3b Mon Sep 17 00:00:00 2001 From: Benjamin Kaduk Date: Tue, 23 Sep 2014 18:19:09 -0400 Subject: [PATCH] Allow external hcrypto 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 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 Reviewed-by: D Brashear Tested-by: D Brashear --- acinclude.m4 | 7 +- src/cf/hcrypto.m4 | 114 +++++++++++++++++++++++++++++++++ src/crypto/hcrypto/Makefile.in | 10 ++- 3 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 src/cf/hcrypto.m4 diff --git a/acinclude.m4 b/acinclude.m4 index 7c277acba..85a4854f7 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -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 #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 index 000000000..2a9998884 --- /dev/null +++ b/src/cf/hcrypto.m4 @@ -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 +#include +#include +#include ]], + [[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])])] + )] + ) + +]) diff --git a/src/crypto/hcrypto/Makefile.in b/src/crypto/hcrypto/Makefile.in index 6a0eb44e4..77e8fdbca 100644 --- a/src/crypto/hcrypto/Makefile.in +++ b/src/crypto/hcrypto/Makefile.in @@ -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 -- 2.39.5