about summary refs log tree commit diff
path: root/pkgs/os-specific/bsd/freebsd/pkgs/makeMinimal.nix
blob: e6a8e38a4acec3c03689b5418cbe11ea6dcd1b18 (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
{ lib, stdenv, mkDerivation
, make
, bsdSetupHook, freebsdSetupHook
}:

mkDerivation rec {
  inherit (make) path;

  buildInputs = [];
  nativeBuildInputs = [
    bsdSetupHook freebsdSetupHook
  ];

  skipIncludesPhase = true;

  makeFlags = [];

  postPatch = ''
    patchShebangs configure
    ${make.postPatch}
  '';

  buildPhase = ''
    runHook preBuild

    sh ./make-bootstrap.sh

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    install -D bmake "$out/bin/bmake"
    ln -s "$out/bin/bmake" "$out/bin/make"
    mkdir -p "$out/share"
    cp -r "$BSDSRCDIR/share/mk" "$out/share/mk"
    find "$out/share/mk" -type f -print0 |
      while IFS= read -r -d "" f; do
        substituteInPlace "$f" --replace 'usr/' ""
      done
    substituteInPlace "$out/share/mk/bsd.symver.mk" \
      --replace '/share/mk' "$out/share/mk"

    runHook postInstall
  '';

  postInstall = lib.optionalString (!stdenv.targetPlatform.isFreeBSD) ''
    boot_mk="$BSDSRCDIR/tools/build/mk"
    cp "$boot_mk"/Makefile.boot* "$out/share/mk"
    replaced_mk="$out/share/mk.orig"
    mkdir "$replaced_mk"
    mv "$out"/share/mk/bsd.{lib,prog}.mk "$replaced_mk"
    for m in bsd.{lib,prog}.mk; do
      cp "$boot_mk/$m" "$out/share/mk"
      substituteInPlace "$out/share/mk/$m" --replace '../../../share/mk' '../mk.orig'
    done
  '';

  extraPaths = make.extraPaths;
}