@@ -0,0 +1,50 @@
1+{ stdenv, fetchurl
2+, libgpgerror
3+
4+# Optional Dependencies
5+, libcap ? null
6+}:
7+
8+let
9+ mkFlag = trueStr: falseStr: cond: name: val:
10+ if cond == null then null else
11+ "--${if cond != false then trueStr else falseStr}${name}${if val != null && cond != false then "=${val}" else ""}";
12+ mkWith = mkFlag "with-" "without-";
13+
14+ shouldUsePkg = pkg: if pkg != null && stdenv.lib.any (x: x == stdenv.system) pkg.meta.platforms then pkg else null;
15+
16+ optLibcap = shouldUsePkg libcap;
17+in
18+stdenv.mkDerivation rec {
19+ name = "libgcrypt-1.5.4";
20+
21+ src = fetchurl {
22+ url = "mirror://gnupg/libgcrypt/${name}.tar.bz2";
23+ sha256 = "0czvqxkzd5y872ipy6s010ifwdwv29sqbnqc4pf56sd486gqvy6m";
24+ };
25+
26+ buildInputs = [ libgpgerror optLibcap ];
27+
28+ configureFlags = [
29+ (mkWith (optLibcap != null) "capabilities" null)
30+ ];
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+ postInstall = ''
35+ sed -i 's,#include <gpg-error.h>,#include "${libgpgerror}/include/gpg-error.h",g' $out/include/gcrypt.h
36+ '' + stdenv.lib.optionalString (!stdenv.isDarwin && optLibcap != null) ''
37+ sed -i 's,\(-lcap\),-L${optLibcap}/lib \1,' $out/lib/libgcrypt.la
38+ '';
39+
40+ doCheck = true;
41+
42+ meta = with stdenv.lib; {
43+ homepage = https://www.gnu.org/software/libgcrypt/;
44+ description = "General-pupose cryptographic library";
45+ license = licenses.lgpl2Plus;
46+ platforms = platforms.all;
47+ maintainers = with maintainers; [ wkennington ];
48+ repositories.git = git://git.gnupg.org/libgcrypt.git;
49+ };
50+}