1*bf6873c5SCy Schubertdnl Use krb5-config to get link paths for Kerberos libraries. 2*bf6873c5SCy Schubertdnl 3*bf6873c5SCy Schubertdnl Provides one macro, RRA_KRB5_CONFIG, which attempts to get compiler and 4*bf6873c5SCy Schubertdnl linker flags for a library via krb5-config and sets the appropriate shell 5*bf6873c5SCy Schubertdnl variables. Defines the Autoconf variable PATH_KRB5_CONFIG, which can be 6*bf6873c5SCy Schubertdnl used to find the default path to krb5-config. 7*bf6873c5SCy Schubertdnl 8*bf6873c5SCy Schubertdnl Depends on RRA_ENABLE_REDUCED_DEPENDS. 9*bf6873c5SCy Schubertdnl 10*bf6873c5SCy Schubertdnl The canonical version of this file is maintained in the rra-c-util 11*bf6873c5SCy Schubertdnl package, available at <https://www.eyrie.org/~eagle/software/rra-c-util/>. 12*bf6873c5SCy Schubertdnl 13*bf6873c5SCy Schubertdnl Written by Russ Allbery <eagle@eyrie.org> 14*bf6873c5SCy Schubertdnl Copyright 2018, 2021 Russ Allbery <eagle@eyrie.org> 15*bf6873c5SCy Schubertdnl Copyright 2011-2012 16*bf6873c5SCy Schubertdnl The Board of Trustees of the Leland Stanford Junior University 17*bf6873c5SCy Schubertdnl 18*bf6873c5SCy Schubertdnl This file is free software; the authors give unlimited permission to copy 19*bf6873c5SCy Schubertdnl and/or distribute it, with or without modifications, as long as this 20*bf6873c5SCy Schubertdnl notice is preserved. 21*bf6873c5SCy Schubertdnl 22*bf6873c5SCy Schubertdnl SPDX-License-Identifier: FSFULLR 23*bf6873c5SCy Schubert 24*bf6873c5SCy Schubertdnl Check for krb5-config in the user's path and set PATH_KRB5_CONFIG. This 25*bf6873c5SCy Schubertdnl is moved into a separate macro so that it can be loaded via AC_REQUIRE, 26*bf6873c5SCy Schubertdnl meaning it will only be run once even if we link with multiple krb5-config 27*bf6873c5SCy Schubertdnl libraries. 28*bf6873c5SCy SchubertAC_DEFUN([_RRA_KRB5_CONFIG_PATH], 29*bf6873c5SCy Schubert[AC_ARG_VAR([PATH_KRB5_CONFIG], [Path to krb5-config]) 30*bf6873c5SCy Schubert AC_PATH_PROG([PATH_KRB5_CONFIG], [krb5-config], [], 31*bf6873c5SCy Schubert [${PATH}:/usr/kerberos/bin])]) 32*bf6873c5SCy Schubert 33*bf6873c5SCy Schubertdnl Check whether the --deps flag is supported by krb5-config. Takes the path 34*bf6873c5SCy Schubertdnl to krb5-config to use. Note that this path is not embedded in the cache 35*bf6873c5SCy Schubertdnl variable, so this macro implicitly assumes that we will always use the 36*bf6873c5SCy Schubertdnl same krb5-config program. 37*bf6873c5SCy SchubertAC_DEFUN([_RRA_KRB5_CONFIG_DEPS], 38*bf6873c5SCy Schubert[AC_REQUIRE([_RRA_KRB5_CONFIG_PATH]) 39*bf6873c5SCy Schubert AC_CACHE_CHECK([for --deps support in krb5-config], 40*bf6873c5SCy Schubert [rra_cv_krb5_config_deps], 41*bf6873c5SCy Schubert [AS_IF(["$1" 2>&1 | grep deps >/dev/null 2>&1], 42*bf6873c5SCy Schubert [rra_cv_krb5_config_deps=yes], 43*bf6873c5SCy Schubert [rra_cv_krb5_config_deps=no])])]) 44*bf6873c5SCy Schubert 45*bf6873c5SCy Schubertdnl Obtain the library flags for a particular library using krb5-config. 46*bf6873c5SCy Schubertdnl Takes the path to the krb5-config program to use, the argument to 47*bf6873c5SCy Schubertdnl krb5-config to use, and the variable prefix under which to store the 48*bf6873c5SCy Schubertdnl library flags. 49*bf6873c5SCy SchubertAC_DEFUN([_RRA_KRB5_CONFIG_LIBS], 50*bf6873c5SCy Schubert[AC_REQUIRE([_RRA_KRB5_CONFIG_PATH]) 51*bf6873c5SCy Schubert AC_REQUIRE([RRA_ENABLE_REDUCED_DEPENDS]) 52*bf6873c5SCy Schubert _RRA_KRB5_CONFIG_DEPS([$1]) 53*bf6873c5SCy Schubert AS_IF([test x"$rra_reduced_depends" = xfalse \ 54*bf6873c5SCy Schubert && test x"$rra_cv_krb5_config_deps" = xyes], 55*bf6873c5SCy Schubert [$3[]_LIBS=`"$1" --deps --libs $2 2>/dev/null`], 56*bf6873c5SCy Schubert [$3[]_LIBS=`"$1" --libs $2 2>/dev/null`])]) 57*bf6873c5SCy Schubert 58*bf6873c5SCy Schubertdnl Attempt to find the flags for a library using krb5-config. Takes the 59*bf6873c5SCy Schubertdnl following arguments (in order): 60*bf6873c5SCy Schubertdnl 61*bf6873c5SCy Schubertdnl 1. The root directory for the library in question, generally from an 62*bf6873c5SCy Schubertdnl Autoconf --with flag. Used by preference as the path to krb5-config. 63*bf6873c5SCy Schubertdnl 64*bf6873c5SCy Schubertdnl 2. The argument to krb5-config to retrieve flags for this particular 65*bf6873c5SCy Schubertdnl library. 66*bf6873c5SCy Schubertdnl 67*bf6873c5SCy Schubertdnl 3. The variable prefix to use when setting CPPFLAGS and LIBS variables 68*bf6873c5SCy Schubertdnl based on the result of krb5-config. 69*bf6873c5SCy Schubertdnl 70*bf6873c5SCy Schubertdnl 4. Further actions to take if krb5-config was found and supported that 71*bf6873c5SCy Schubertdnl library type. 72*bf6873c5SCy Schubertdnl 73*bf6873c5SCy Schubertdnl 5. Further actions to take if krb5-config could not be used to get flags 74*bf6873c5SCy Schubertdnl for that library type. 75*bf6873c5SCy Schubertdnl 76*bf6873c5SCy Schubertdnl Special-case a krb5-config argument of krb5 and run krb5-config without an 77*bf6873c5SCy Schubertdnl argument if that option was requested and not supported. Old versions of 78*bf6873c5SCy Schubertdnl krb5-config didn't take an argument to specify the library type, but 79*bf6873c5SCy Schubertdnl always returned the flags for libkrb5. 80*bf6873c5SCy SchubertAC_DEFUN([RRA_KRB5_CONFIG], 81*bf6873c5SCy Schubert[rra_krb5_config_$3= 82*bf6873c5SCy Schubert rra_krb5_config_$3[]_ok= 83*bf6873c5SCy Schubert AS_IF([test x"$1" != x && test -x "$1/bin/krb5-config"], 84*bf6873c5SCy Schubert [rra_krb5_config_$3="$1/bin/krb5-config"], 85*bf6873c5SCy Schubert [_RRA_KRB5_CONFIG_PATH 86*bf6873c5SCy Schubert rra_krb5_config_$3="$PATH_KRB5_CONFIG"]) 87*bf6873c5SCy Schubert AS_IF([test x"$rra_krb5_config_$3" != x && test -x "$rra_krb5_config_$3"], 88*bf6873c5SCy Schubert [AC_CACHE_CHECK([for $2 support in krb5-config], [rra_cv_lib_$3[]_config], 89*bf6873c5SCy Schubert [AS_IF(["$rra_krb5_config_$3" 2>&1 | grep $2 >/dev/null 2>&1], 90*bf6873c5SCy Schubert [rra_cv_lib_$3[]_config=yes], 91*bf6873c5SCy Schubert [rra_cv_lib_$3[]_config=no])]) 92*bf6873c5SCy Schubert AS_IF([test "$rra_cv_lib_$3[]_config" = yes], 93*bf6873c5SCy Schubert [$3[]_CPPFLAGS=`"$rra_krb5_config_$3" --cflags $2 2>/dev/null` 94*bf6873c5SCy Schubert _RRA_KRB5_CONFIG_LIBS([$rra_krb5_config_$3], [$2], [$3]) 95*bf6873c5SCy Schubert rra_krb5_config_$3[]_ok=yes], 96*bf6873c5SCy Schubert [AS_IF([test x"$2" = xkrb5], 97*bf6873c5SCy Schubert [$3[]_CPPFLAGS=`"$rra_krb5_config_$3" --cflags 2>/dev/null` 98*bf6873c5SCy Schubert $3[]_LIBS=`"$rra_krb5_config_$3" --libs $2 2>/dev/null` 99*bf6873c5SCy Schubert rra_krb5_config_$3[]_ok=yes])])]) 100*bf6873c5SCy Schubert AS_IF([test x"$rra_krb5_config_$3[]_ok" = xyes], 101*bf6873c5SCy Schubert [$3[]_CPPFLAGS=`AS_ECHO(["$$3[]_CPPFLAGS"]) | sed 's%-I/usr/include %%'` 102*bf6873c5SCy Schubert $3[]_CPPFLAGS=`AS_ECHO(["$$3[]_CPPFLAGS"]) | sed 's%-I/usr/include$%%'` 103*bf6873c5SCy Schubert $4], 104*bf6873c5SCy Schubert [$5])]) 105