@@ -1,63 +1,49 @@
1−{ stdenv, fetchurl, findXMLCatalogs
1+{ stdenv, fetchurl, zlib, xz, python ? null, pythonSupport ? true, findXMLCatalogs }:
22
3−# Optional Dependencies
4−, icu ? null, python ? null, readline ? null, zlib ? null, xz ? null
5−}:
3+assert pythonSupport -> python != null;
64
75#TODO: share most stuff between python and non-python builds, perhaps via multiple-output
86
97let
10− mkFlag = trueStr: falseStr: cond: name: val:
11− if cond == null then null else
12− "--${if cond != false then trueStr else falseStr}${name}${if val != null && cond != false then "=${val}" else ""}";
13− mkEnable = mkFlag "enable-" "disable-";
14− mkWith = mkFlag "with-" "without-";
15− mkOther = mkFlag "" "" true;
16−
17− shouldUsePkg = pkg: if pkg != null && stdenv.lib.any (x: x == stdenv.system) pkg.meta.platforms then pkg else null;
18−
19− optIcu = shouldUsePkg icu;
20− optPython = shouldUsePkg python;
21− optReadline = shouldUsePkg readline;
22− optZlib = shouldUsePkg zlib;
23− optXz = shouldUsePkg xz;
24−
25− sitePackages = if optPython == null then null else
26− "\${out}/lib/${python.libPrefix}/site-packages";
8+ version = "2.9.2";
279in
28−stdenv.mkDerivation rec {
10+
11+stdenv.mkDerivation (rec {
2912 name = "libxml2-${version}";
30− version = "2.9.2";
3113
3214 src = fetchurl {
3315 url = "http://xmlsoft.org/sources/${name}.tar.gz";
3416 sha256 = "1g6mf03xcabmk5ing1lwqmasr803616gb2xhn7pll10x2l5w6y2i";
3517 };
3618
37− buildInputs = [ optIcu optPython optReadline optZlib optXz ];
38− propagatedBuildInputs = [ findXMLCatalogs ];
19+ buildInputs = stdenv.lib.optional pythonSupport python
20+ # Libxml2 has an optional dependency on liblzma. However, on impure
21+ # platforms, it may end up using that from /usr/lib, and thus lack a
22+ # RUNPATH for that, leading to undefined references for its users.
23+ ++ (stdenv.lib.optional stdenv.isFreeBSD xz);
24+
25+ propagatedBuildInputs = [ zlib findXMLCatalogs ];
3926
40− configureFlags = [
41− (mkWith (optIcu != null) "icu" optIcu)
42− (mkWith (optPython != null) "python" optPython)
43− (mkWith (optPython != null) "python-install-dir" sitePackages)
44− (mkWith (optReadline != null) "readline" optReadline)
45− (mkWith (optZlib != null) "zlib" optZlib)
46− (mkWith (optXz != null) "lzma" optXz)
47− ];
27+ passthru = { inherit pythonSupport version; };
4828
4929 enableParallelBuilding = true;
5030
51− meta = with stdenv.lib; {
31+ meta = {
5232 homepage = http://xmlsoft.org/;
5333 description = "An XML parsing library for C";
54− license = licenses.mit;
55− platforms = platforms.unix;
56− maintainers = with maintainers; [ eelco wkennington ];
34+ license = "bsd";
35+ platforms = stdenv.lib.platforms.unix;
36+ maintainers = [ stdenv.lib.maintainers.eelco ];
5737 };
5838
59− passthru = {
60− inherit version;
61− pythonSupport = python != null;
62− };
63−}
39+} // stdenv.lib.optionalAttrs pythonSupport {
40+ configureFlags = "--with-python=${python}";
41+
42+ # this is a pair of ugly hacks to make python stuff install into the right place
43+ preInstall = ''substituteInPlace python/libxml2mod.la --replace "${python}" "$out"'';
44+ installFlags = ''pythondir="$(out)/lib/${python.libPrefix}/site-packages"'';
45+
46+} // stdenv.lib.optionalAttrs (!pythonSupport) {
47+ configureFlags = "--with-python=no"; # otherwise build impurity bites us
48+})
49+