1{
2 lib,
3 stdenv,
4 fetchurl,
5 autoreconfHook,
6 cxxSupport ? true,
7 compat185 ? true,
8 dbmSupport ? false,
9
10 # Options from inherited versions
11 version,
12 sha256,
13 extraPatches ? [ ],
14 license ? lib.licenses.sleepycat,
15 drvArgs ? { },
16}:
17
18stdenv.mkDerivation (
19 rec {
20 pname = "db";
21 inherit version;
22
23 src = fetchurl {
24 url = "https://download.oracle.com/berkeley-db/${pname}-${version}.tar.gz";
25 sha256 = sha256;
26 };
27
28 # The provided configure script features `main` returning implicit `int`, which causes
29 # configure checks to work incorrectly with clang 16.
30 nativeBuildInputs = [ autoreconfHook ];
31
32 patches = extraPatches;
33
34 outputs = [
35 "bin"
36 "out"
37 "dev"
38 ];
39
40 # Required when regenerated the configure script to make sure the vendored macros are found.
41 autoreconfFlags = [
42 "-fi"
43 "-Iaclocal"
44 "-Iaclocal_java"
45 ];
46
47 preAutoreconf = ''
48 pushd dist
49 # Upstream’s `dist/s_config` cats everything into `aclocal.m4`, but that doesn’t work with
50 # autoreconfHook, so cat `config.m4` to another file. Otherwise, it won’t be found by `aclocal`.
51 cat aclocal/config.m4 >> aclocal/options.m4
52 '';
53
54 # This isn’t pretty. The version information is kept separate from the configure script.
55 # After the configure script is regenerated, the version information has to be replaced with the
56 # contents of `dist/RELEASE`.
57 postAutoreconf = ''
58 (
59 declare -a vars=(
60 "DB_VERSION_FAMILY"
61 "DB_VERSION_RELEASE"
62 "DB_VERSION_MAJOR"
63 "DB_VERSION_MINOR"
64 "DB_VERSION_PATCH"
65 "DB_VERSION_STRING"
66 "DB_VERSION_FULL_STRING"
67 "DB_VERSION_UNIQUE_NAME"
68 "DB_VERSION"
69 )
70 source RELEASE
71 for var in "''${vars[@]}"; do
72 sed -e "s/__EDIT_''${var}__/''${!var}/g" -i configure
73 done
74 )
75 popd
76 '';
77
78 configureFlags =
79 [
80 (if cxxSupport then "--enable-cxx" else "--disable-cxx")
81 (if compat185 then "--enable-compat185" else "--disable-compat185")
82 ]
83 ++ lib.optional dbmSupport "--enable-dbm"
84 ++ lib.optional stdenv.hostPlatform.isFreeBSD "--with-pic";
85
86 preConfigure = ''
87 cd build_unix
88 configureScript=../dist/configure
89 '';
90
91 postInstall = ''
92 rm -rf $out/docs
93 '';
94
95 enableParallelBuilding = true;
96
97 doCheck = true;
98
99 checkPhase = ''
100 make examples_c examples_cxx
101 '';
102
103 meta = with lib; {
104 homepage = "https://www.oracle.com/database/technologies/related/berkeleydb.html";
105 description = "Berkeley DB";
106 license = license;
107 platforms = platforms.unix;
108 };
109 }
110 // drvArgs
111)