summary refs log tree commit diff
path: root/pkgs/development/tools/literate-programming/noweb/default.nix
blob: 7a2252c6b2738cb37b3f9e40aae82569365e1c10 (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
{ stdenv, fetchFromGitHub, gawk, groff, icon-lang ? null }:

let noweb = stdenv.mkDerivation rec {
  pname = "noweb";
  version = "2.12";

  src = fetchFromGitHub {
    owner = "nrnrnr";
    repo = "noweb";
    rev = "v${builtins.replaceStrings ["."] ["_"] version}";
    sha256 = "1160i2ghgzqvnb44kgwd6s3p4jnk9668rmc15jlcwl7pdf3xqm95";
  };

  patches = [ ./no-FAQ.patch ];

  nativeBuildInputs = [ groff ] ++ stdenv.lib.optionals (!isNull icon-lang) [ icon-lang ];

  preBuild = ''
    mkdir -p "$out/lib/noweb"
    cd src
  '';

  makeFlags = stdenv.lib.optionals (!isNull icon-lang) [
    "LIBSRC=icon"
    "ICONC=icont"
  ] ++ stdenv.lib.optionals stdenv.isDarwin [
    "CC=clang"
  ];

  installFlags = [
    "BIN=$(out)/bin"
    "ELISP=$(out)/share/emacs/site-lisp"
    "LIB=$(out)/lib/noweb"
    "MAN=$(out)/share/man"
    "TEXINPUTS=$(tex)/tex/latex/noweb"
  ];

  preInstall = ''
    mkdir -p "$tex/tex/latex/noweb"
  '';

  installTargets = [ "install-code" "install-tex" "install-elisp" ];

  postInstall = ''
    substituteInPlace "$out/bin/cpif" --replace "PATH=/bin:/usr/bin" ""

    for f in $out/bin/no{index,roff,roots,untangle,web} \
             $out/lib/noweb/to{ascii,html,roff,tex} \
             $out/lib/noweb/{bt,empty}defn \
             $out/lib/noweb/{noidx,unmarkup}; do
        # NOTE: substituteInPlace breaks Icon binaries, so make sure the script
        #       uses (n)awk before calling.
        if grep -q nawk "$f"; then
            substituteInPlace "$f" --replace "nawk" "${gawk}/bin/awk"
        fi
    done

    # HACK: This is ugly, but functional.
    PATH=$out/bin:$PATH make -BC xdoc
    make "''${installFlags[@]}" install-man

    ln -s "$tex" "$out/share/texmf"
  '';

  outputs = [ "out" "tex" ];

  tlType = "run";
  passthru.pkgs = [ noweb.tex ];

  meta = with stdenv.lib; {
    description = "A simple, extensible literate-programming tool";
    homepage = https://www.cs.tufts.edu/~nr/noweb;
    license = licenses.bsd2;
    maintainers = with maintainers; [ yurrriq ];
    platforms = with platforms; linux ++ darwin;
  };
}; in noweb