summaryrefslogtreecommitdiffstats
path: root/pkgs/development/interpreters/tcl/mk-tcl-derivation.nix
blob: f73d80849e9b118cda647008dda05c55cb43bb6d (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
# Generic builder for tcl packages/applications
{
  tcl,
  lib,
  makeWrapper,
}:

let
  inherit (tcl) stdenv;
  inherit (lib) getExe' optionalAttrs;

  defaultTclPkgConfigureFlags = [
    "--with-tcl=${tcl}/lib"
    "--with-tclinclude=${tcl}/include"
    "--exec-prefix=${placeholder "out"}"
    # Enable stubs by default for compatibility across minor versions
    "--enable-stubs"
  ];

in
lib.extendMkDerivation {
  constructDrv = stdenv.mkDerivation;
  excludeDrvArgNames = [
    "addTclConfigureFlags"
    "checkPhase"
    "checkInputs"
    "nativeCheckInputs"
    "doCheck"
  ];
  extendDrvArgs =
    finalAttrs:
    args@{
      # true if we should skip the configuration phase altogether
      dontConfigure ? false,

      # Extra flags passed to configure step
      configureFlags ? [ ],

      # Whether or not we should add common Tcl-related configure flags
      addTclConfigureFlags ? true,
      ...
    }:
    (
      {
        buildInputs = args.buildInputs or [ ] ++ [ tcl.tclPackageHook ];

        nativeBuildInputs =
          args.nativeBuildInputs or [ ]
          ++ [
            makeWrapper
            tcl
          ]
          ++ lib.optionals (stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
            tcl.tclRequiresCheckHook
          ];

        propagatedBuildInputs = args.propagatedBuildInputs or [ ] ++ [ tcl ];

        strictDeps = true;

        # Run tests after install, at which point we've done all TCLLIBPATH setup
        doCheck = false;
        doInstallCheck = args.doCheck or (args.doInstallCheck or false);
        installCheckInputs = args.checkInputs or [ ] ++ args.installCheckInputs or [ ];
        nativeInstallCheckInputs = args.nativeCheckInputs or [ ] ++ args.nativeInstallCheckInputs or [ ];

        # Add typical values expected by TEA for configureFlags
        configureFlags =
          if (!dontConfigure && addTclConfigureFlags) then
            (configureFlags ++ defaultTclPkgConfigureFlags)
          else
            configureFlags;

        env = {
          TCLSH = "${getExe' tcl "tclsh"}";
        }
        // args.env or { };

        __structuredAttrs = true;

        meta = {
          platforms = tcl.meta.platforms;
        }
        // args.meta or { };

      }
      // optionalAttrs (args ? checkPhase) {
        installCheckPhase = args.checkPhase;
      }
    );
}