1{ stdenv, fetchurl, gettext, libgpgerror, enableCapabilities ? false, libcap
2, buildPackages
3}:
4
5assert enableCapabilities -> stdenv.isLinux;
6
7stdenv.mkDerivation rec {
8 name = "libgcrypt-${version}";
9 version = "1.8.4";
10
11 src = fetchurl {
12 url = "mirror://gnupg/libgcrypt/${name}.tar.bz2";
13 sha256 = "09r27ywj9zplq6n9qw3mn7zmvf6y2jdmwx5d1kg8yqkj0qx18f7n";
14 };
15
16 outputs = [ "out" "dev" "info" ];
17 outputBin = "dev";
18
19 # The CPU Jitter random number generator must not be compiled with
20 # optimizations and the optimize -O0 pragma only works for gcc.
21 # The build enables -O2 by default for everything else.
22 hardeningDisable = stdenv.lib.optional stdenv.cc.isClang "fortify";
23
24 depsBuildBuild = [ buildPackages.stdenv.cc ];
25
26 buildInputs = [ libgpgerror ]
27 ++ stdenv.lib.optional stdenv.isDarwin gettext
28 ++ stdenv.lib.optional enableCapabilities libcap;
29
30 configureFlags = [ "--with-libgpg-error-prefix=${libgpgerror.dev}" ];
31
32 # Make sure libraries are correct for .pc and .la files
33 # Also make sure includes are fixed for callers who don't use libgpgcrypt-config
34 postFixup = ''
35 sed -i 's,#include <gpg-error.h>,#include "${libgpgerror.dev}/include/gpg-error.h",g' "$dev/include/gcrypt.h"
36 '' + stdenv.lib.optionalString enableCapabilities ''
37 sed -i 's,\(-lcap\),-L${libcap.lib}/lib \1,' $out/lib/libgcrypt.la
38 '';
39
40 # TODO: figure out why this is even necessary and why the missing dylib only crashes
41 # random instead of every test
42 preCheck = stdenv.lib.optionalString stdenv.isDarwin ''
43 mkdir -p $out/lib
44 cp src/.libs/libgcrypt.20.dylib $out/lib
45 '';
46
47 doCheck = true;
48
49 meta = with stdenv.lib; {
50 homepage = https://www.gnu.org/software/libgcrypt/;
51 description = "General-purpose cryptographic library";
52 license = licenses.lgpl2Plus;
53 platforms = platforms.all;
54 maintainers = with maintainers; [ vrthra ];
55 repositories.git = git://git.gnupg.org/libgcrypt.git;
56 };
57}