about summary refs log tree commit diff
path: root/pkgs/tools/typesetting/lowdown/default.nix
blob: 88e3a9720d0474e6ef0c7440ab0a9338dd86fe0c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{ lib, stdenv, fetchurl, fixDarwinDylibNames, which
, enableShared ? !(stdenv.hostPlatform.isStatic)
, enableStatic ? stdenv.hostPlatform.isStatic
}:

stdenv.mkDerivation rec {
  pname = "lowdown";
  version = "0.11.1";

  outputs = [ "out" "lib" "dev" "man" ];

  src = fetchurl {
    url = "https://kristaps.bsd.lv/lowdown/snapshots/lowdown-${version}.tar.gz";
    sha512 = "1l0055g8v0dygyxvk5rchp4sn1g2lakbf6hhq0wkj6nxkfpl43mkyc4vpb02r7v6iqfdwq4461dmdi78blsb3nj8b1gcjx75v7x9pa1";
  };

  # Upstream always passes GNU-style "soname", but cctools expects "install_name".
  # Whatever name is inserted will be replaced by fixDarwinDylibNames.
  # https://github.com/kristapsdz/lowdown/issues/87
  postPatch = lib.optionalString stdenv.isDarwin ''
    substituteInPlace Makefile --replace soname install_name
  '';

  nativeBuildInputs = [ which ]
    ++ lib.optionals stdenv.isDarwin [ fixDarwinDylibNames ];

  preConfigure = lib.optionalString (stdenv.isDarwin && stdenv.isAarch64) ''
    echo 'HAVE_SANDBOX_INIT=0' > configure.local
  '';

  configurePhase = ''
    runHook preConfigure
    ./configure PREFIX=''${!outputDev} \
                BINDIR=''${!outputBin}/bin \
                LIBDIR=''${!outputLib}/lib \
                MANDIR=''${!outputMan}/share/man
    runHook postConfigure
  '';

  makeFlags = [
    "bins" # prevents shared object from being built unnecessarily
  ];

  installTargets = [
    "install"
  ] ++ lib.optionals enableShared [
    "install_shared"
  ] ++ lib.optionals enableStatic [
    "install_static"
  ];

  # Fix lib extension so that fixDarwinDylibNames detects it
  # Symlink liblowdown.so to liblowdown.so.1 (or equivalent)
  postInstall =
    let
      inherit (stdenv.hostPlatform.extensions) sharedLibrary;
    in

    lib.optionalString (enableShared && stdenv.isDarwin) ''
      mv $lib/lib/liblowdown.{so.1,1.dylib}
    '' + lib.optionalString enableShared ''
      ln -s $lib/lib/liblowdown*${sharedLibrary}* $lib/lib/liblowdown${sharedLibrary}
    '';

  doInstallCheck = stdenv.hostPlatform == stdenv.buildPlatform;
  installCheckPhase = ''
    runHook preInstallCheck
    echo '# TEST' > test.md
    $out/bin/lowdown test.md
    runHook postInstallCheck
  '';

  doCheck = stdenv.hostPlatform == stdenv.buildPlatform;
  checkTarget = "regress";

  meta = with lib; {
    homepage = "https://kristaps.bsd.lv/lowdown/";
    description = "Simple markdown translator";
    license = licenses.isc;
    maintainers = [ maintainers.sternenseemann ];
    platforms = platforms.unix;
  };
}