1{ lib
2, stdenv
3, fetchFromGitHub
4, autoreconfHook
5, writeShellScript
6, pkg-config
7, texinfo
8, pcre2
9, swig
10, libxml2
11, ncurses
12, enablePython ? false
13, python ? null
14}:
15let
16 isPython3 = enablePython && python.pythonAtLeast "3";
17in
18stdenv.mkDerivation rec {
19 pname = "libredwg";
20 version = "0.13.3";
21
22 src = fetchFromGitHub {
23 owner = "LibreDWG";
24 repo = pname;
25 rev = version;
26 hash = "sha256-FlBHwNsqVSBE8dTDewoKkCbs8Jd/4d69MPpEFzg6Ruc=";
27 fetchSubmodules = true;
28 };
29
30 postPatch = let
31 printVersion = writeShellScript "print-version" ''
32 echo -n ${lib.escapeShellArg version}
33 '';
34 in ''
35 # avoid git dependency
36 cp ${printVersion} build-aux/git-version-gen
37 '';
38
39 preConfigure = lib.optionalString (stdenv.isDarwin && enablePython) ''
40 # prevent configure picking up stack_size from distutils.sysconfig
41 export PYTHON_EXTRA_LDFLAGS=" "
42 '';
43
44 nativeBuildInputs = [ autoreconfHook pkg-config texinfo ]
45 ++ lib.optional enablePython swig;
46
47 buildInputs = [ pcre2 ]
48 ++ lib.optionals enablePython [ python ]
49 # configurePhase fails with python 3 when ncurses is missing
50 ++ lib.optional isPython3 ncurses
51 ;
52
53 # prevent python tests from running when not building with python
54 configureFlags = lib.optional (!enablePython) "--disable-python";
55
56 # FAIL: alive.test
57 doCheck = !stdenv.isLinux;
58
59 # the "xmlsuite" test requires the libxml2 c library as well as the python module
60 nativeCheckInputs = lib.optionals enablePython [ libxml2 libxml2.dev ];
61
62 meta = with lib; {
63 description = "Free implementation of the DWG file format";
64 homepage = "https://savannah.gnu.org/projects/libredwg/";
65 maintainers = with maintainers; [ tweber ];
66 license = licenses.gpl3Plus;
67 platforms = platforms.all;
68 };
69}