phash: compilation fixes

This includes a patch already sent upstream that fixes compilation with Werror due to a lacking return, as well as adding a linker flag to include a threaded version of a library.
The fftw3_threads part stems from cimg requiring this apparently when linking the examples:

> test_texthash.cpp:(.text.startup+0x1c1): undefined reference to `fftw_init_threads'

I wouldn't know how to patch this upstream, however other packages in nixpkgs seem to provide the LDFLAGS too.

Signed-off-by: benaryorg <binary@benary.org>

+48 -1
+40
pkgs/by-name/ph/phash/0001-proper-pthread-return-value.patch
··· 1 + From 6ac2f207e8d8e1d16ee73198abccc64d20c5f608 Mon Sep 17 00:00:00 2001 2 + From: benaryorg <binary@benary.org> 3 + Date: Thu, 7 Nov 2024 03:27:52 +0000 4 + Subject: [PATCH 1/2] proper pthread return value 5 + 6 + *pthread_create(3)* states that the ways for a pthread to exit includes: 7 + 8 + > It returns from start_routine(). This is equivalent to calling pthread_exit(3) with the value supplied in the return statement. 9 + 10 + This "retval" is a void pointer which can be anything. 11 + In this case, since all threads are always joined with a parameter of NULL for the `void**` to store the retval this isn't really relevant for providing a meaningful return value. 12 + However a `void*` function must return a `void*`, otherwise compilers will complain: 13 + 14 + > pHash.cpp:416:1: warning: no return statement in function returning non-void [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wreturn-type-Wreturn-type8;;] 15 + 16 + Therefore returning NULL seems reasonable. 17 + As for the choice of NULL vs. nullptr or any other value, NULL is already widely used in the file. 18 + 19 + Long story short: this fixes a compiler warning/error. 20 + 21 + Signed-off-by: benaryorg <binary@benary.org> 22 + --- 23 + src/pHash.cpp | 1 + 24 + 1 file changed, 1 insertion(+) 25 + 26 + diff --git a/src/pHash.cpp b/src/pHash.cpp 27 + index 07b03ad..23bbbf3 100644 28 + --- a/src/pHash.cpp 29 + +++ b/src/pHash.cpp 30 + @@ -417,6 +417,7 @@ void *ph_image_thread(void *p) 31 + memcpy(dp->hash, &hash, sizeof(hash)); 32 + dp->hash_length = 1; 33 + } 34 + + return NULL; 35 + } 36 + 37 + DP** ph_dct_image_hashes(char *files[], int count, int threads) 38 + -- 39 + 2.44.1 40 +
+8 -1
pkgs/by-name/ph/phash/package.nix
··· 1 - { lib, stdenv, fetchFromGitHub, pkg-config, cimg, imagemagick }: 1 + { lib, stdenv, fetchFromGitHub, fetchpatch, pkg-config, cimg, imagemagick }: 2 2 3 3 stdenv.mkDerivation rec { 4 4 pname = "pHash"; ··· 23 23 rev = version; 24 24 sha256 = "sha256-frISiZ89ei7XfI5F2nJJehfQZsk0Mlb4n91q/AiZ2vA="; 25 25 }; 26 + 27 + NIX_LDFLAGS = "-lfftw3_threads"; 28 + 29 + patches = [ 30 + # proper pthread return value (https://github.com/clearscene/pHash/pull/20) 31 + ./0001-proper-pthread-return-value.patch 32 + ]; 26 33 27 34 meta = with lib; { 28 35 description = "Compute the perceptual hash of an image";