From 3aa316cbcf696304c13f295e70b40c94ac75d17d Mon Sep 17 00:00:00 2001 From: Thomas Adam Date: Sun, 26 Feb 2023 19:22:52 +0000 Subject: [PATCH] portable: improve SHA detection Original patch from Omar Polo. Tweak by me. --- configure.ac | 31 +++++++++++++------------------ include/got_compat.h | 2 +- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/configure.ac b/configure.ac index 613855f1..35053180 100644 --- a/configure.ac +++ b/configure.ac @@ -88,24 +88,19 @@ fi AM_CONDITIONAL([HAVE_SHA2], [test "x$ac_cv_header_sha2_h" = xyes]) # Check for SHA1_DIGEST_LENGTH -if test "x$ac_cv_header_sha_h" = xyes; then -AC_CHECK_DECL([SHA_DIGEST_LENGTH], - [AC_DEFINE(HAVE_SHA_AS_SHA1)], - [AC_DEFINE(NEEDS_SHA1_DEFS)], - [#include ]) -fi - -if test "x$ac_cv_header_sha1_h" = xyes; then -AC_CHECK_DECL([SHA_DIGEST_LENGTH], - [AC_DEFINE(HAVE_SHA1_AS_SHA1)], - [AC_DEFINE(NEEDS_SHA1_DEFS)], - [#include ]) -fi - -if test "x$ac_cv_header_sha_h" = xno || test "x$ac_cv_header_sha1_h" = xno -then - AC_DEFINE(NEEDS_SHA1_DEFS) -fi +AC_CHECK_DECL([SHA1_DIGEST_LENGTH], + [AC_DEFINE(HAVE_SHA1_AS_SHA1)], + [ + dnl maybe sha.h is available + AC_CHECK_DECL([SHA_DIGEST_LENGTH], + [AC_DEFINE(HAVE_SHA_AS_SHA1)], + [], + [#include ]) + ], + [ + #include + #include + ]) # Checks for typ edefs, structures, and compiler characteristics. AC_CHECK_HEADER_STDBOOL diff --git a/include/got_compat.h b/include/got_compat.h index 1ca8f7f5..847c7695 100644 --- a/include/got_compat.h +++ b/include/got_compat.h @@ -240,7 +240,7 @@ typedef struct _SHA2_CTX { #include #endif -#ifdef NEEDS_SHA1_DEFS +#ifndef SHA1_DIGEST_LENGTH #define SHA1_DIGEST_LENGTH SHA_DIGEST_LENGTH #define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1) -- 2.11.4.GIT