summaryrefslogtreecommitdiffstats
path: root/pkgs/development/skaware-packages/execline/default.nix
blob: 52a2902a3e2e4697569c5b04fb61d35787cadc71 (plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{
  lib,
  skawarePackages,
  skalibs,
  execline,
  writeTextFile,
}:

let
  version = "2.9.9.2";
in
skawarePackages.buildPackage {
  inherit version;

  pname = "execline";
  # ATTN: also check whether there is a new manpages version
  sha256 = "sha256-kI7U2zprOiOiBdj9TPKnEIkVbyrq4PVGVgRar60t7jI=";

  # Maintainer of manpages uses following versioning scheme: for every
  # upstream $version he tags manpages release as ${version}.1, and,
  # in case of extra fixes to manpages, new tags in form ${version}.2,
  # ${version}.3 and so on are created.
  manpages = skawarePackages.buildManPages {
    pname = "execline-man-pages";
    version = "2.9.9.1.1";
    sha256 = "sha256-SMQLeiS03fW9HGDmk+MMfUbnvRGqTzXc/4CuS5LW18U=";
    description = "Port of the documentation for the execline suite to mdoc";
    maintainers = [ lib.maintainers.sternenseemann ];
  };

  meta.description = "Small scripting language, to be used in place of a shell in non-interactive scripts";

  outputs = [
    "bin"
    "lib"
    "dev"
    "doc"
    "out"
  ];
  buildInputs = [ skalibs ];

  # TODO: nsss support
  configureFlags = [
    "--libdir=${placeholder "lib"}/lib"
    "--dynlibdir=${placeholder "out"}/lib"
    "--libexecdir=${placeholder "lib"}/libexec"
    "--bindir=${placeholder "bin"}/bin"
    "--includedir=${placeholder "dev"}/include"
    "--pkgconfdir=${placeholder "dev"}/lib/pkgconfig"
    "--with-sysdeps=${skalibs.lib}/lib/skalibs/sysdeps"
  ];

  postInstall = ''
    # remove all execline executables from build directory
    rm $(find -type f -mindepth 1 -maxdepth 1 -executable)
    rm libexecline.*

    mv doc $doc/share/doc/execline/html
    mv examples $doc/share/doc/execline/examples

    mv $bin/bin/execlineb $bin/bin/.execlineb-wrapped

    # A wrapper around execlineb, which provides all execline
    # tools on `execlineb`’s PATH.
    # It is implemented as a C script, because on non-Linux,
    # nested shebang lines are not supported.
    # The -lskarnet has to come at the end to support static builds.
    $CC \
      -O \
      -Wall -Wpedantic \
      -D "EXECLINEB_PATH()=\"$bin/bin/.execlineb-wrapped\"" \
      -D "EXECLINE_BIN_PATH()=\"$bin/bin\"" \
      $(pkg-config --cflags libskarnet) \
      -o "$bin/bin/execlineb" \
      ${./execlineb-wrapper.c} \
      $(pkg-config --libs libskarnet)
  '';

  # Write an execline script.
  # Documented in ../../../../doc/build-helpers/trivial-build-helpers.chapter.md
  passthru.writeScript =
    name: options: script:
    writeTextFile {
      inherit name;
      text = ''
        #!${execline}/bin/execlineb ${toString options}
        ${script}
      '';

      executable = true;
      derivationArgs.nativeBuildInputs = [ execline ];
      checkPhase = ''
        echo redirfd -w 1 /dev/null echo >test.el
        cat <$target >>test.el
        execlineb -W test.el
      '';
    };
}