1dnl Checks for libhmac required headers and functions 2dnl 3dnl Version: 20200104 4 5dnl Function to detect if libhmac is available 6dnl ac_libhmac_dummy is used to prevent AC_CHECK_LIB adding unnecessary -l<library> arguments 7AC_DEFUN([AX_LIBHMAC_CHECK_LIB], 8 [AS_IF( 9 [test "x$ac_cv_enable_shared_libs" = xno || test "x$ac_cv_with_libhmac" = xno], 10 [ac_cv_libhmac=no], 11 [ac_cv_libhmac=check 12 dnl Check if the directory provided as parameter exists 13 AS_IF( 14 [test "x$ac_cv_with_libhmac" != x && test "x$ac_cv_with_libhmac" != xauto-detect], 15 [AS_IF( 16 [test -d "$ac_cv_with_libhmac"], 17 [CFLAGS="$CFLAGS -I${ac_cv_with_libhmac}/include" 18 LDFLAGS="$LDFLAGS -L${ac_cv_with_libhmac}/lib"], 19 [AC_MSG_FAILURE( 20 [no such directory: $ac_cv_with_libhmac], 21 [1]) 22 ]) 23 ], 24 [dnl Check for a pkg-config file 25 AS_IF( 26 [test "x$cross_compiling" != "xyes" && test "x$PKGCONFIG" != "x"], 27 [PKG_CHECK_MODULES( 28 [libhmac], 29 [libhmac >= 20200104], 30 [ac_cv_libhmac=yes], 31 [ac_cv_libhmac=check]) 32 ]) 33 AS_IF( 34 [test "x$ac_cv_libhmac" = xyes], 35 [ac_cv_libhmac_CPPFLAGS="$pkg_cv_libhmac_CFLAGS" 36 ac_cv_libhmac_LIBADD="$pkg_cv_libhmac_LIBS"]) 37 ]) 38 39 AS_IF( 40 [test "x$ac_cv_libhmac" = xcheck], 41 [dnl Check for headers 42 AC_CHECK_HEADERS([libhmac.h]) 43 44 AS_IF( 45 [test "x$ac_cv_header_libhmac_h" = xno], 46 [ac_cv_libhmac=no], 47 [dnl Check for the individual functions 48 ac_cv_libhmac=yes 49 50 AC_CHECK_LIB( 51 hmac, 52 libhmac_get_version, 53 [ac_cv_libhmac_dummy=yes], 54 [ac_cv_libhmac=no]) 55 56 dnl MD5 functions 57 AC_CHECK_LIB( 58 hmac, 59 libhmac_md5_initialize, 60 [ac_cv_libhmac_dummy=yes], 61 [ac_cv_libhmac=no]) 62 AC_CHECK_LIB( 63 hmac, 64 libhmac_md5_update, 65 [ac_cv_libhmac_dummy=yes], 66 [ac_cv_libhmac=no]) 67 AC_CHECK_LIB( 68 hmac, 69 libhmac_md5_finalize, 70 [ac_cv_libhmac_dummy=yes], 71 [ac_cv_libhmac=no]) 72 AC_CHECK_LIB( 73 hmac, 74 libhmac_md5_free, 75 [ac_cv_libhmac_dummy=yes], 76 [ac_cv_libhmac=no]) 77 78 dnl SHA1 functions 79 AC_CHECK_LIB( 80 hmac, 81 libhmac_sha1_initialize, 82 [ac_cv_libhmac_dummy=yes], 83 [ac_cv_libhmac=no]) 84 AC_CHECK_LIB( 85 hmac, 86 libhmac_sha1_update, 87 [ac_cv_libhmac_dummy=yes], 88 [ac_cv_libhmac=no]) 89 AC_CHECK_LIB( 90 hmac, 91 libhmac_sha1_finalize, 92 [ac_cv_libhmac_dummy=yes], 93 [ac_cv_libhmac=no]) 94 AC_CHECK_LIB( 95 hmac, 96 libhmac_sha1_free, 97 [ac_cv_libhmac_dummy=yes], 98 [ac_cv_libhmac=no]) 99 100 dnl SHA224 functions 101 AC_CHECK_LIB( 102 hmac, 103 libhmac_sha224_initialize, 104 [ac_cv_libhmac_dummy=yes], 105 [ac_cv_libhmac=no]) 106 AC_CHECK_LIB( 107 hmac, 108 libhmac_sha224_update, 109 [ac_cv_libhmac_dummy=yes], 110 [ac_cv_libhmac=no]) 111 AC_CHECK_LIB( 112 hmac, 113 libhmac_sha224_finalize, 114 [ac_cv_libhmac_dummy=yes], 115 [ac_cv_libhmac=no]) 116 AC_CHECK_LIB( 117 hmac, 118 libhmac_sha224_free, 119 [ac_cv_libhmac_dummy=yes], 120 [ac_cv_libhmac=no]) 121 122 dnl SHA256 functions 123 AC_CHECK_LIB( 124 hmac, 125 libhmac_sha256_initialize, 126 [ac_cv_libhmac_dummy=yes], 127 [ac_cv_libhmac=no]) 128 AC_CHECK_LIB( 129 hmac, 130 libhmac_sha256_update, 131 [ac_cv_libhmac_dummy=yes], 132 [ac_cv_libhmac=no]) 133 AC_CHECK_LIB( 134 hmac, 135 libhmac_sha256_finalize, 136 [ac_cv_libhmac_dummy=yes], 137 [ac_cv_libhmac=no]) 138 AC_CHECK_LIB( 139 hmac, 140 libhmac_sha256_free, 141 [ac_cv_libhmac_dummy=yes], 142 [ac_cv_libhmac=no]) 143 144 dnl SHA512 functions 145 AC_CHECK_LIB( 146 hmac, 147 libhmac_sha512_initialize, 148 [ac_cv_libhmac_dummy=yes], 149 [ac_cv_libhmac=no]) 150 AC_CHECK_LIB( 151 hmac, 152 libhmac_sha512_update, 153 [ac_cv_libhmac_dummy=yes], 154 [ac_cv_libhmac=no]) 155 AC_CHECK_LIB( 156 hmac, 157 libhmac_sha512_finalize, 158 [ac_cv_libhmac_dummy=yes], 159 [ac_cv_libhmac=no]) 160 AC_CHECK_LIB( 161 hmac, 162 libhmac_sha512_free, 163 [ac_cv_libhmac_dummy=yes], 164 [ac_cv_libhmac=no]) 165 166 ac_cv_libhmac_LIBADD="-lhmac"]) 167 ]) 168 AS_IF( 169 [test "x$ac_cv_with_libhmac" != x && test "x$ac_cv_with_libhmac" != xauto-detect && test "x$ac_cv_libhmac" != xyes], 170 [AC_MSG_FAILURE( 171 [unable to find supported libhmac in directory: $ac_cv_with_libhmac], 172 [1]) 173 ]) 174 ]) 175 176 AS_IF( 177 [test "x$ac_cv_libhmac" = xyes], 178 [AC_DEFINE( 179 [HAVE_LIBHMAC], 180 [1], 181 [Define to 1 if you have the `hmac' library (-lhmac).]) 182 ]) 183 184 AS_IF( 185 [test "x$ac_cv_libhmac" = xyes], 186 [ac_cv_libhmac_md5=libhmac 187 ac_cv_libhmac_sha1=libhmac 188 ac_cv_libhmac_sha224=libhmac 189 ac_cv_libhmac_sha256=libhmac 190 ac_cv_libhmac_sha512=libhmac], 191 [ac_cv_libhmac_md5=no 192 ac_cv_libhmac_sha1=no 193 ac_cv_libhmac_sha224=no 194 ac_cv_libhmac_sha256=no 195 ac_cv_libhmac_sha512=no]) 196 197 AS_IF( 198 [test "x$ac_cv_libhmac" = xyes], 199 [AC_SUBST( 200 [HAVE_LIBHMAC], 201 [1]) ], 202 [AC_SUBST( 203 [HAVE_LIBHMAC], 204 [0]) 205 ]) 206 ]) 207 208dnl Function to detect if libhmac dependencies are available 209AC_DEFUN([AX_LIBHMAC_CHECK_LOCAL], 210 [dnl Check for libcrypto (openssl) support 211 AX_LIBCRYPTO_CHECK_ENABLE 212 213 AS_IF( 214 [test "x$ac_cv_libcrypto" != xno], 215 [AX_LIBCRYPTO_CHECK_MD5 216 AX_LIBCRYPTO_CHECK_SHA1 217 AX_LIBCRYPTO_CHECK_SHA224 218 AX_LIBCRYPTO_CHECK_SHA256 219 AX_LIBCRYPTO_CHECK_SHA512]) 220 221 dnl Fallback to local versions if necessary 222 AS_IF( 223 [test "x$ac_cv_libcrypto" = xno || test "x$ac_cv_libcrypto_md5" = xno], 224 [ac_cv_libhmac_md5=local], 225 [ac_cv_libhmac_md5=$ac_cv_libcrypto_md5]) 226 227 AS_IF( 228 [test "x$ac_cv_libcrypto" = xno || test "x$ac_cv_libcrypto_sha1" = xno], 229 [ac_cv_libhmac_sha1=local], 230 [ac_cv_libhmac_sha1=$ac_cv_libcrypto_sha1]) 231 232 AS_IF( 233 [test "x$ac_cv_libcrypto" = xno || test "x$ac_cv_libcrypto_sha224" = xno], 234 [ac_cv_libhmac_sha224=local], 235 [ac_cv_libhmac_sha224=$ac_cv_libcrypto_sha224]) 236 237 AS_IF( 238 [test "x$ac_cv_libcrypto" = xno || test "x$ac_cv_libcrypto_sha256" = xno], 239 [ac_cv_libhmac_sha256=local], 240 [ac_cv_libhmac_sha256=$ac_cv_libcrypto_sha256]) 241 242 AS_IF( 243 [test "x$ac_cv_libcrypto" = xno || test "x$ac_cv_libcrypto_sha512" = xno], 244 [ac_cv_libhmac_sha512=local], 245 [ac_cv_libhmac_sha512=$ac_cv_libcrypto_sha512]) 246 247 ac_cv_libhmac_CPPFLAGS="-I../libhmac"; 248 ac_cv_libhmac_LIBADD="../libhmac/libhmac.la"; 249 250 ac_cv_libhmac=local 251 ]) 252 253dnl Function to detect how to enable libhmac 254AC_DEFUN([AX_LIBHMAC_CHECK_ENABLE], 255 [AX_COMMON_ARG_WITH( 256 [libhmac], 257 [libhmac], 258 [search for libhmac in includedir and libdir or in the specified DIR, or no if to use local version], 259 [auto-detect], 260 [DIR]) 261 262 dnl Check for a shared library version 263 AX_LIBHMAC_CHECK_LIB 264 265 dnl Check if the dependencies for the local library version 266 AS_IF( 267 [test "x$ac_cv_libhmac" != xyes], 268 [AX_LIBHMAC_CHECK_LOCAL 269 270 AC_DEFINE( 271 [HAVE_LOCAL_LIBHMAC], 272 [1], 273 [Define to 1 if the local version of libhmac is used.]) 274 AC_SUBST( 275 [HAVE_LOCAL_LIBHMAC], 276 [1]) 277 ]) 278 279 AM_CONDITIONAL( 280 [HAVE_LOCAL_LIBHMAC], 281 [test "x$ac_cv_libhmac" = xlocal]) 282 AS_IF( 283 [test "x$ac_cv_libhmac_CPPFLAGS" != "x"], 284 [AC_SUBST( 285 [LIBHMAC_CPPFLAGS], 286 [$ac_cv_libhmac_CPPFLAGS]) 287 ]) 288 AS_IF( 289 [test "x$ac_cv_libhmac_LIBADD" != "x"], 290 [AC_SUBST( 291 [LIBHMAC_LIBADD], 292 [$ac_cv_libhmac_LIBADD]) 293 ]) 294 295 AS_IF( 296 [test "x$ac_cv_libhmac" = xyes], 297 [AC_SUBST( 298 [ax_libhmac_pc_libs_private], 299 [-lhmac]) 300 ]) 301 302 AS_IF( 303 [test "x$ac_cv_libhmac" = xyes], 304 [AC_SUBST( 305 [ax_libhmac_spec_requires], 306 [libhmac]) 307 AC_SUBST( 308 [ax_libhmac_spec_build_requires], 309 [libhmac-devel]) 310 ]) 311 ]) 312 313