forgejo-lts: 7.0.10 -> 7.0.11
[NixPkgs.git] / pkgs / development / libraries / libxml2 / default.nix
blob6924c71fab662c27ab121e1fe5ad8d4ea199c6a0
1 { stdenv
2 , lib
3 , fetchurl
4 , pkg-config
5 , autoreconfHook
6 , libintl
7 , python
8 , gettext
9 , ncurses
10 , findXMLCatalogs
11 , libiconv
12 # Python limits cross-compilation to an allowlist of host OSes.
13 # https://github.com/python/cpython/blob/dfad678d7024ab86d265d84ed45999e031a03691/configure.ac#L534-L562
14 , pythonSupport ? enableShared &&
15     (stdenv.hostPlatform == stdenv.buildPlatform || stdenv.hostPlatform.isCygwin || stdenv.hostPlatform.isLinux || stdenv.hostPlatform.isWasi)
16 , icuSupport ? false
17 , icu
18 , enableShared ? !stdenv.hostPlatform.isMinGW && !stdenv.hostPlatform.isStatic
19 , enableStatic ? !enableShared
20 , gnome
21 , testers
22 , enableHttp ? false
25 stdenv.mkDerivation (finalAttrs: {
26   pname = "libxml2";
27   version = "2.13.4";
29   outputs = [ "bin" "dev" "out" "devdoc" ]
30     ++ lib.optional pythonSupport "py"
31     ++ lib.optional (enableStatic && enableShared) "static";
32   outputMan = "bin";
34   src = fetchurl {
35     url = "mirror://gnome/sources/libxml2/${lib.versions.majorMinor finalAttrs.version}/libxml2-${finalAttrs.version}.tar.xz";
36     hash = "sha256-ZdBC4cgBAkPmF++wKv2iC4XCFgrNv7y1smuAzsZRVlA=";
37   };
39   strictDeps = true;
41   nativeBuildInputs = [
42     pkg-config
43     autoreconfHook
44   ];
46   buildInputs = lib.optionals pythonSupport [
47     python
48   ] ++ lib.optionals (pythonSupport && python?isPy2 && python.isPy2) [
49     gettext
50   ] ++ lib.optionals (pythonSupport && python?isPy3 && python.isPy3) [
51     ncurses
52   ] ++ lib.optionals (stdenv.hostPlatform.isDarwin && pythonSupport && python?isPy2 && python.isPy2) [
53     libintl
54   ];
56   propagatedBuildInputs = [
57     findXMLCatalogs
58   ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
59     libiconv
60   ] ++ lib.optionals icuSupport [
61     icu
62   ];
64   configureFlags = [
65     "--exec-prefix=${placeholder "dev"}"
66     (lib.enableFeature enableStatic "static")
67     (lib.enableFeature enableShared "shared")
68     (lib.withFeature icuSupport "icu")
69     (lib.withFeature pythonSupport "python")
70     (lib.optionalString pythonSupport "PYTHON=${python.pythonOnBuildForHost.interpreter}")
71   ] ++ lib.optional enableHttp "--with-http";
73   installFlags = lib.optionals pythonSupport [
74     "pythondir=\"${placeholder "py"}/${python.sitePackages}\""
75     "pyexecdir=\"${placeholder "py"}/${python.sitePackages}\""
76   ];
78   enableParallelBuilding = true;
80   doCheck =
81     (stdenv.hostPlatform == stdenv.buildPlatform) &&
82     stdenv.hostPlatform.libc != "musl";
83   preCheck = lib.optional stdenv.hostPlatform.isDarwin ''
84     export DYLD_LIBRARY_PATH="$PWD/.libs:$DYLD_LIBRARY_PATH"
85   '';
87   preConfigure = lib.optionalString (lib.versionAtLeast stdenv.hostPlatform.darwinMinVersion "11") ''
88     MACOSX_DEPLOYMENT_TARGET=10.16
89   '';
91   preInstall = lib.optionalString pythonSupport ''
92     substituteInPlace python/libxml2mod.la --replace-fail "$dev/${python.sitePackages}" "$py/${python.sitePackages}"
93   '';
95   postFixup = ''
96     moveToOutput bin/xml2-config "$dev"
97     moveToOutput lib/xml2Conf.sh "$dev"
98   '' + lib.optionalString (enableStatic && enableShared) ''
99     moveToOutput lib/libxml2.a "$static"
100   '';
102   passthru = {
103     inherit pythonSupport;
105     updateScript = gnome.updateScript {
106       packageName = "libxml2";
107       versionPolicy = "none";
108     };
109     tests = {
110       pkg-config = testers.hasPkgConfigModules {
111         package = finalAttrs.finalPackage;
112       };
113     };
114   };
116   meta = with lib; {
117     homepage = "https://gitlab.gnome.org/GNOME/libxml2";
118     description = "XML parsing library for C";
119     license = licenses.mit;
120     platforms = platforms.all;
121     maintainers = with maintainers; [ jtojnar ];
122     pkgConfigModules = [ "libxml-2.0" ];
123   };