1{ stdenv, lib, fetchurl, fetchpatch
2, zlib, xz, python2, findXMLCatalogs, libiconv
3, buildPlatform, hostPlatform
4, pythonSupport ? buildPlatform == hostPlatform
5, icuSupport ? false, icu ? null
6}:
7
8let
9 python = python2;
10
11in stdenv.mkDerivation rec {
12 name = "libxml2-${version}";
13 version = "2.9.4";
14
15 src = fetchurl {
16 url = "http://xmlsoft.org/sources/${name}.tar.gz";
17 sha256 = "0g336cr0bw6dax1q48bblphmchgihx9p1pjmxdnrd6sh3qci3fgz";
18 };
19
20 patches = [
21 (fetchpatch {
22 # Contains fixes for CVE-2016-{4658,5131} and other bugs.
23 name = "misc.patch";
24 url = "https://git.gnome.org/browse/libxml2/patch/?id=e905f081&id2=v2.9.4";
25 sha256 = "14rnzilspmh92bcpwbd6kqikj36gx78al42ilgpqgl1609krb5m5";
26 })
27 ];
28
29 outputs = [ "bin" "dev" "out" "man" "doc" ]
30 ++ lib.optional pythonSupport "py";
31 propagatedBuildOutputs = "out bin" + lib.optionalString pythonSupport " py";
32
33 buildInputs = lib.optional pythonSupport python
34 # Libxml2 has an optional dependency on liblzma. However, on impure
35 # platforms, it may end up using that from /usr/lib, and thus lack a
36 # RUNPATH for that, leading to undefined references for its users.
37 ++ lib.optional stdenv.isFreeBSD xz;
38
39 propagatedBuildInputs = [ zlib findXMLCatalogs ] ++ lib.optional icuSupport icu;
40
41 configureFlags =
42 lib.optional pythonSupport "--with-python=${python}"
43 ++ lib.optional icuSupport "--with-icu"
44 ++ [ "--exec_prefix=$dev" ];
45
46 enableParallelBuilding = true;
47
48 doCheck = !stdenv.isDarwin;
49
50 crossAttrs = lib.optionalAttrs (hostPlatform.libc == "msvcrt") {
51 # creating the DLL is broken ATM
52 dontDisableStatic = true;
53 configureFlags = configureFlags ++ [ "--disable-shared" ];
54
55 # libiconv is a header dependency - propagating is enough
56 propagatedBuildInputs = [ findXMLCatalogs libiconv ];
57 };
58
59 preInstall = lib.optionalString pythonSupport
60 ''substituteInPlace python/libxml2mod.la --replace "${python}" "$py"'';
61 installFlags = lib.optionalString pythonSupport
62 ''pythondir="$(py)/lib/${python.libPrefix}/site-packages"'';
63
64 postFixup = ''
65 moveToOutput bin/xml2-config "$dev"
66 moveToOutput lib/xml2Conf.sh "$dev"
67 moveToOutput share/man/man1 "$bin"
68 '';
69
70 passthru = { inherit version; pythonSupport = pythonSupport; };
71
72 meta = {
73 homepage = http://xmlsoft.org/;
74 description = "An XML parsing library for C";
75 license = lib.licenses.mit;
76 platforms = lib.platforms.unix;
77 maintainers = [ lib.maintainers.eelco ];
78 };
79}