1{ lib, stdenv, fetchFromGitHub, nawk, groff, icon-lang, useIcon ? true }:
2
3stdenv.mkDerivation (finalAttrs: {
4 pname = "noweb";
5 version = "2.13";
6
7 src = fetchFromGitHub {
8 owner = "nrnrnr";
9 repo = "noweb";
10 rev = "v${builtins.replaceStrings ["."] ["_"] finalAttrs.version}";
11 sha256 = "sha256-COcWyrYkheRaSr2gqreRRsz9SYRTX2PSl7km+g98ljs=";
12 };
13
14 sourceRoot = "${finalAttrs.src.name}/src";
15
16 patches = [
17 # Remove FAQ
18 ./no-FAQ.patch
19 ];
20
21 postPatch = ''
22 substituteInPlace Makefile --replace 'strip' '${stdenv.cc.targetPrefix}strip'
23 substituteInPlace Makefile --replace '`./gitversion`' '${finalAttrs.src.rev}'
24 '';
25
26 nativeBuildInputs = [ groff ] ++ lib.optionals useIcon [ icon-lang ];
27 buildInputs = [ nawk ];
28
29 preBuild = ''
30 mkdir -p "$out/lib/noweb"
31 '';
32
33 makeFlags = lib.optionals useIcon [
34 "LIBSRC=icon"
35 "ICONC=icont"
36 ] ++ [ "CC=${stdenv.cc.targetPrefix}cc" ];
37
38 preInstall = ''
39 mkdir -p "$tex/tex/latex/noweb"
40 installFlagsArray+=( \
41 "BIN=${placeholder "out"}/bin" \
42 "ELISP=${placeholder "out"}/share/emacs/site-lisp" \
43 "LIB=${placeholder "out"}/lib/noweb" \
44 "MAN=${placeholder "out"}/share/man" \
45 "TEXINPUTS=${placeholder "tex"}/tex/latex/noweb" \
46 )
47 '';
48
49 installTargets = [ "install-code" "install-tex" "install-elisp" ];
50
51 postInstall = ''
52 substituteInPlace "$out/bin/cpif" --replace "PATH=/bin:/usr/bin" ""
53
54 for f in $out/bin/no{index,roff,roots,untangle,web} \
55 $out/lib/noweb/to{ascii,html,roff,tex} \
56 $out/lib/noweb/{bt,empty}defn \
57 $out/lib/noweb/{noidx,pipedocs,unmarkup}; do
58 # NOTE: substituteInPlace breaks Icon binaries, so make sure the script
59 # uses (n)awk before calling.
60 if grep -q nawk "$f"; then
61 substituteInPlace "$f" --replace "nawk" "${nawk}/bin/nawk"
62 fi
63 done
64
65 # HACK: This is ugly, but functional.
66 PATH=$out/bin:$PATH make -BC xdoc
67 make "''${installFlagsArray[@]}" install-man
68
69 ln -s "$tex" "$out/share/texmf"
70 '';
71
72 outputs = [ "out" "tex" ];
73
74 passthru = {
75 tlType = "run";
76 pkgs = [ finalAttrs.finalPackage.tex ];
77 };
78
79 meta = with lib; {
80 description = "A simple, extensible literate-programming tool";
81 homepage = "https://www.cs.tufts.edu/~nr/noweb";
82 license = licenses.bsd2;
83 maintainers = with maintainers; [ yurrriq ];
84 platforms = with platforms; linux ++ darwin;
85 };
86})