Commit 7673806a30f8a3460debe61833021d1d49586e89

Thomas de Grivel 2023-01-25T22:16:51

sha.h

diff --git a/config.subr b/config.subr
index edeceeb..f5160ce 100644
--- a/config.subr
+++ b/config.subr
@@ -70,6 +70,21 @@ config_gnu() {
     fi
 }
 
+config_include() {
+    OUT=".config_$1.c"
+    shift
+    echo "/* generated by configure */" > "$OUT"
+    while [ $# -gt 1 ]; do
+        echo "#include <$1>" >> "$OUT"
+        shift
+    done
+    echo "int main () { return 0; }" >> "$OUT"
+    if ${CC} ${CPPFLAGS} ${CFLAGS} "$OUT" -o /dev/null 2>/dev/null; then
+        CPPFLAGS="$CPPFLAGS -D$1=1"
+    fi
+    rm "$OUT"
+}
+
 pkg_config() {
     if pkg-config "$1"; then
 	CFLAGS="$CFLAGS $(pkg-config --cflags "$1")"
diff --git a/libc3/configure b/libc3/configure
index 58475e5..ce8512c 100755
--- a/libc3/configure
+++ b/libc3/configure
@@ -45,6 +45,8 @@ config_gnu
 pkg_config libbsd-overlay
 pkg_config libffi
 pkg_config libmd
+config_include sha_h sys/types.h sha.h HAVE_SHA_H
+config_include sha1_h sys/types.h sha1.h HAVE_SHA1_H
 
 # Address Sanitizer config
 CFLAGS_ASAN="$CFLAGS -fsanitize=address -O1 -fno-omit-frame-pointer -g"
diff --git a/libc3/types.h b/libc3/types.h
index 756682c..d5728fa 100644
--- a/libc3/types.h
+++ b/libc3/types.h
@@ -18,7 +18,13 @@
 #include <setjmp.h>
 #include <stdio.h>
 #include <sys/types.h>
-#include <sha1.h>
+#ifdef HAVE_SHA1_H
+# include <sha1.h>
+#else
+# ifdef HAVE_SHA_H
+#  include <sha.h>
+# endif
+#endif
 #include "../libtommath/tommath.h"
 
 /* Basic integer types. */