about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/interpreters/octave/build-octave-package.nix
blob: 73a67769d6a6e1110b1e7a3d55cfbe85f76ace14 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Generic builder for GNU Octave libraries.
# This is a file that contains nested functions. The first, outer, function
# is the library- and package-wide details, such as the nixpkgs library, any
# additional configuration provided, and the namePrefix to use (based on the
# pname and version of Octave), the octave package, etc.

{ lib
, stdenv
, config
, octave
, texinfo
, computeRequiredOctavePackages
, writeRequiredOctavePackagesHook
}:

# The inner function contains information required to build the individual
# libraries.
{ fullLibName ? "${attrs.pname}-${attrs.version}"

, src

, dontPatch ? false
, patches ? []
, patchPhase ? ""

, enableParallelBuilding ? true
# Build-time dependencies for the package, which were compiled for the system compiling this.
, nativeBuildInputs ? []

# Build-time dependencies for the package, which may not have been compiled for the system compiling this.
, buildInputs ? []

# Propagate build dependencies so in case we have A -> B -> C,
# C can import package A propagated by B
# Run-time dependencies for the package.
, propagatedBuildInputs ? []

# Octave packages that are required at runtime for this one.
# These behave similarly to propagatedBuildInputs, where if
# package A is needed by B, and C needs B, then C also requires A.
# The main difference between these and propagatedBuildInputs is
# during the package's installation into octave, where all
# requiredOctavePackages are ALSO installed into octave.
, requiredOctavePackages ? []

, preBuild ? ""

, meta ? {}

, passthru ? {}

, ... } @ attrs:

let
  requiredOctavePackages' = computeRequiredOctavePackages requiredOctavePackages;

in stdenv.mkDerivation {
  packageName = "${fullLibName}";
  # The name of the octave package ends up being
  # "octave-version-package-version"
  name = "${octave.pname}-${octave.version}-${fullLibName}";

  # This states that any package built with the function that this returns
  # will be an octave package. This is used for ensuring other octave
  # packages are installed into octave during the environment building phase.
  isOctavePackage = true;

  OCTAVE_HISTFILE = "/dev/null";

  inherit src;

  inherit dontPatch patches patchPhase;

  dontConfigure = true;

  enableParallelBuilding = enableParallelBuilding;

  requiredOctavePackages = requiredOctavePackages';

  nativeBuildInputs = [
    octave
    writeRequiredOctavePackagesHook
  ]
  ++ nativeBuildInputs;

  buildInputs = buildInputs ++ requiredOctavePackages';

  propagatedBuildInputs = propagatedBuildInputs ++ [ texinfo ];

  preBuild = if preBuild == "" then
    ''
      # This trickery is needed because Octave expects a single directory inside
      # at the top-most level of the tarball.
      tar --transform 's,^,${fullLibName}/,' -cz * -f ${fullLibName}.tar.gz
    ''
             else
               preBuild;

  buildPhase = ''
    runHook preBuild

    mkdir -p $out
    octave-cli --eval "pkg build $out ${fullLibName}.tar.gz"

    runHook postBuild
  '';

  # We don't install here, because that's handled when we build the environment
  # together with Octave.
  dontInstall = true;

  inherit meta;
}