summaryrefslogtreecommitdiffstats
path: root/pkgs/stdenv/cygwin/make-bootstrap-tools.nix
blob: 2252288d1f2331f8a0ba36488d53a560b508f5c6 (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
{
  pkgs ? import ../../.. { },
}:
let
  inherit (pkgs) runCommand;
  # splicing doesn't seem to work right here
  inherit (pkgs.buildPackages) dumpnar rsync nukeReferences;

  unpacked =
    let
      inherit (pkgs)
        bashNonInteractive
        binutils-unwrapped
        bzip2
        coreutils
        curl
        diffutils
        file
        findutils
        gawk
        gcc-unwrapped
        gitMinimal # for fetchgit (newlib-cygwin)
        gnugrep
        gnumake
        gnused
        gnutar
        gzip
        patch
        xz
        ;

      inherit (pkgs.cygwin)
        newlib-cygwin
        w32api
        ;

    in
    runCommand "unpacked"
      {
        nativeBuildInputs = [ nukeReferences ];
        # The result should not contain any references (store paths) so
        # that we can safely copy them out of the store and to other
        # locations in the store.
        allowedReferences = [ ];
        strictDeps = true;
      }
      ''
        mkdir -p "$out"/{bin,include,lib,libexec}
        cp -d "${bashNonInteractive}"/bin/* "$out"/bin/
        cp -d "${binutils-unwrapped}"/bin/* "$out"/bin/
        cp -d "${bzip2}"/bin/* "$out"/bin/
        cp -d "${coreutils}"/bin/* "$out"/bin/
        cp -d "${curl}"/bin/* "$out"/bin/
        cp -d "${diffutils}"/bin/* "$out"/bin/
        cp -d "${file}"/bin/* "$out"/bin/
        cp -d "${findutils}"/bin/* "$out"/bin/
        cp -d "${gawk}"/bin/* "$out"/bin/
        cp -d "${gcc-unwrapped}"/bin/* "$out"/bin/
        cp -rd ${gcc-unwrapped}/include/* $out/include/
        cp -rd ${gcc-unwrapped}/lib/* $out/lib/
        cp -rd ${gcc-unwrapped}/libexec/* $out/libexec/
        cp -frd ${gcc-unwrapped.lib}/bin/* $out/bin/
        cp -rd ${gcc-unwrapped.lib}/lib/* $out/lib/
        cp -d "${gitMinimal}"/bin/* "$out"/bin/
        cp -d "${gnugrep}"/bin/* "$out"/bin/
        cp -d "${gnumake}"/bin/* "$out"/bin/
        cp -d "${gnused}"/bin/* "$out"/bin/
        cp -d "${gnutar}"/bin/* "$out"/bin/
        (shopt -s dotglob; cp -d "${gzip}"/bin/* "$out"/bin/)
        cp -rd ${newlib-cygwin.dev}/include/* $out/include/
        cp -rd ${newlib-cygwin}/lib/* "$out"/lib/
        cp -d "${patch}"/bin/* "$out"/bin/
        cp -d "${w32api}"/lib/w32api/lib{advapi,shell,user,kernel}32.a "$out"/lib/
        cp -d "${xz}"/bin/* "$out"/bin/

        chmod -R +w "$out"

        find "$out" -type l -print0 | while read -d $'\0' link; do
          [[ -L "$link" && -e "$link" ]] || continue
          [[ $(realpath "$link") != "$out"* ]] || continue
          cp "$link" "$link"~
          mv "$link"~ "$link"
        done

        find "$out" -print0 | xargs -0 nuke-refs -e "$out"
      '';
in
{
  unpack = runCommand "unpack.nar.xz" {
    nativeBuildInputs = [ dumpnar ];
  } "dumpnar ${unpacked} | xz -9 -e -T $NIX_BUILD_CORES >$out";
}