1{
2 lib,
3 stdenv,
4 fetchurl,
5 makeWrapper,
6 apr,
7 expat,
8 gnused,
9 sslSupport ? true,
10 openssl,
11 bdbSupport ? true,
12 db,
13 ldapSupport ? !stdenv.hostPlatform.isCygwin,
14 openldap,
15 libiconv,
16 libxcrypt,
17 cyrus_sasl,
18 autoreconfHook,
19}:
20
21assert sslSupport -> openssl != null;
22assert bdbSupport -> db != null;
23assert ldapSupport -> openldap != null;
24
25stdenv.mkDerivation rec {
26 pname = "apr-util";
27 version = "1.6.3";
28
29 src = fetchurl {
30 url = "mirror://apache/apr/${pname}-${version}.tar.bz2";
31 sha256 = "sha256-pBB243EHRjJsOUUEKZStmk/KwM4Cd92P6gdv7DyXcrU=";
32 };
33
34 patches = [
35 ./fix-libxcrypt-build.patch
36 # Fix incorrect Berkeley DB detection with newer versions of clang due to implicit `int` on main errors.
37 ./clang-bdb.patch
38 ]
39 ++ lib.optional stdenv.hostPlatform.isFreeBSD ./include-static-dependencies.patch;
40
41 NIX_CFLAGS_LINK = [ "-lcrypt" ];
42
43 outputs = [
44 "out"
45 "dev"
46 ];
47 outputBin = "dev";
48
49 nativeBuildInputs = [
50 makeWrapper
51 autoreconfHook
52 ];
53
54 configureFlags = [
55 "--with-apr=${apr.dev}"
56 "--with-expat=${expat.dev}"
57 ]
58 ++ lib.optional (!stdenv.hostPlatform.isCygwin) "--with-crypto"
59 ++ lib.optional sslSupport "--with-openssl=${openssl.dev}"
60 ++ lib.optional bdbSupport "--with-berkeley-db=${db.dev}"
61 ++ lib.optional ldapSupport "--with-ldap=ldap"
62 ++ lib.optionals stdenv.hostPlatform.isCygwin [
63 "--without-pgsql"
64 "--without-sqlite2"
65 "--without-sqlite3"
66 "--without-freetds"
67 "--without-berkeley-db"
68 "--without-crypto"
69 ];
70
71 postConfigure = ''
72 echo '#define APR_HAVE_CRYPT_H 1' >> confdefs.h
73 ''
74 +
75 # For some reason, db version 6.9 is selected when cross-compiling.
76 # It's unclear as to why, it requires someone with more autotools / configure knowledge to go deeper into that.
77 # Always replacing the link flag with a generic link flag seems to help though, so let's do that for now.
78 lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
79 substituteInPlace Makefile \
80 --replace "-ldb-6.9" "-ldb"
81 substituteInPlace apu-1-config \
82 --replace "-ldb-6.9" "-ldb"
83 '';
84
85 propagatedBuildInputs = [
86 apr
87 expat
88 libiconv
89 libxcrypt
90 ]
91 ++ lib.optional sslSupport openssl
92 ++ lib.optional bdbSupport db
93 ++ lib.optional ldapSupport openldap
94 ++ lib.optional stdenv.hostPlatform.isFreeBSD cyrus_sasl;
95
96 postInstall = ''
97 for f in $out/lib/*.la $out/lib/apr-util-1/*.la $dev/bin/apu-1-config; do
98 substituteInPlace $f \
99 --replace "${expat.dev}/lib" "${expat.out}/lib" \
100 --replace "${db.dev}/lib" "${db.out}/lib" \
101 --replace "${openssl.dev}/lib" "${lib.getLib openssl}/lib"
102 done
103
104 # Give apr1 access to sed for runtime invocations.
105 wrapProgram $dev/bin/apu-1-config --prefix PATH : "${gnused}/bin"
106 '';
107
108 enableParallelBuilding = true;
109
110 passthru = {
111 inherit sslSupport bdbSupport ldapSupport;
112 };
113
114 meta = with lib; {
115 homepage = "https://apr.apache.org/";
116 description = "Companion library to APR, the Apache Portable Runtime";
117 mainProgram = "apu-1-config";
118 maintainers = [ ];
119 platforms = platforms.unix;
120 license = licenses.asl20;
121 };
122}