zip: fix build with clang 16

Fix implicit declarations of `memset` and `open/closedir` resulting in
incorrect feature detection and conflicts with libc headers.
This commit is contained in:
Randy Eckenrode 2023-07-11 10:33:43 -06:00
parent 72d5519b60
commit c407e3cbba
No known key found for this signature in database
GPG key ID: 64C1CD4EC2A600D9
3 changed files with 45 additions and 2 deletions

View file

@ -13,7 +13,7 @@ stdenv.mkDerivation rec {
];
sha256 = "0sb3h3067pzf3a7mlxn1hikpcjrsvycjcnj9hl9b1c3ykcgvps7h";
};
patchPhase = ''
prePatch = ''
substituteInPlace unix/Makefile --replace 'CC = cc' ""
'';
@ -26,7 +26,14 @@ stdenv.mkDerivation rec {
"INSTALL=cp"
];
patches = lib.optionals (enableNLS && !stdenv.isCygwin) [ ./natspec-gentoo.patch.bz2 ];
patches = [
# Trying to use `memset` without declaring it is flagged as an error with clang 16, causing
# the `configure` script to incorrectly define `ZMEM`. That causes the build to fail due to
# incompatible redeclarations of `memset`, `memcpy`, and `memcmp` in `zip.h`.
./fix-memset-detection.patch
# Implicit declaration of `closedir` and `opendir` cause dirent detection to fail with clang 16.
./fix-implicit-declarations.patch
] ++ lib.optionals (enableNLS && !stdenv.isCygwin) [ ./natspec-gentoo.patch.bz2 ];
buildInputs = lib.optional enableNLS libnatspec
++ lib.optional stdenv.isCygwin libiconv;

View file

@ -0,0 +1,21 @@
--- a/unix/configure 2009-04-16 15:25:12.000000000 -0400
+++ b/unix/configure 2023-05-30 15:18:33.670321348 -0400
@@ -408,7 +408,7 @@
echo Check for errno declaration
cat > conftest.c << _EOF_
#include <errno.h>
-main()
+int main()
{
errno = 0;
return 0;
@@ -419,6 +419,8 @@
echo Check for directory libraries
cat > conftest.c << _EOF_
+#include <sys/types.h>
+#include <dirent.h>
int main() { return closedir(opendir(".")); }
_EOF_

View file

@ -0,0 +1,15 @@
diff -ur a/unix/configure b/unix/configure
--- a/unix/configure 2008-06-19 21:32:20.000000000 -0600
+++ b/unix/configure 2023-07-11 10:02:57.809867694 -0600
@@ -519,7 +519,10 @@
echo Check for memset
-echo "int main(){ char k; memset(&k,0,0); return 0; }" > conftest.c
+cat > conftest.c << _EOF_
+#include <string.h>
+int main(){ char k; memset(&k,0,0); return 0; }
+_EOF_
$CC -o conftest conftest.c >/dev/null 2>/dev/null
[ $? -ne 0 ] && CFLAGS="${CFLAGS} -DZMEM"