summary refs log tree commit diff
path: root/pkgs/stdenv/mingw/default.nix
blob: 947db5f10a89500a417d2a5a44b6bf438cf37fce (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
{system} :

let {
  body =
    stdenvFinal;

  /**
   * Initial standard environment based on native Cygwin tools.
   * GCC is not required.
   * Required (approx): bash, mkdir, gnu tar, curl.
   */
  stdenvInit1 =
    import ./simple-stdenv {
      inherit system;
      name = "stdenv-init1-mingw";
      shell = "/bin/bash.exe";
      path = ["/usr/bin" "/bin" "/usr/local/bin"];
    };

  /**
   * Initial standard environment based on MSYS tools.
   */
  stdenvInit2 =
    import ./simple-stdenv {
      inherit system;
      name = "stdenv-init2-mingw";
      shell = msysShell;
      path = [(msys + "/bin")];
    };

  /**
   * Initial standard environment with the most basic MinGW packages.
   */
  stdenvInit3 =
    (import ./simple-stdenv) {
      inherit system;
      name = "stdenv-init3-mingw";
      shell = msysShell;
      path = [
        (make + "/bin")
        (tar + "/bin")
        (binutils + "/bin")
        (gccFull + "/bin")
        (mingwRuntimeBin + "/bin")
        (w32apiBin + "/bin")
        (msys + "/bin")
      ];

      extraEnv = {
        C_INCLUDE_PATH = mingwRuntimeBin + "/include" + ":" + w32apiBin + "/include";
        LIBRARY_PATH = mingwRuntimeBin + "/lib" + ":" + w32apiBin + "/lib";
      };
    };

  /**
   * Final standard environment, based on generic stdenv.
   * It would be better to make the generic stdenv usable on
   * MINGW (i.e. make all environment variables CAPS).
   */
  stdenvFinal =
    let {
      body =
        stdenv // mkDerivationFun // {
          inherit fetchurl;
          overrides.pkgconfig = pkgconfigBin;
        };

      shell =
        msys + "/bin/sh.exe";

      stdenv =
        stdenvInit2.mkDerivation {
          name = "stdenv-mingw";
          builder = ./builder.sh;
          setup = ./setup.sh;

          /**
           * binutils is on the path because it contains dlltool, which
           * is invoked on the PATH by some packages.
           */
          initialPath = [make tar binutils gccFull mingwRuntimeSrc w32apiSrc msys];
          gcc = gccFull;
          shell = msysShell;
          inherit curl;
          isDarwin = false;
          isMinGW = true;
        };

      mkDerivationFun = {
        mkDerivation = attrs:
          (derivation (
            (removeAttrs attrs ["meta"])
            //
            {
              builder =
                if attrs ? realBuilder then attrs.realBuilder else shell;
              args =
                if attrs ? args then
                  attrs.args
                 else
                  ["-e"] ++ (
                    if attrs ? builder then
                      [./fix-builder.sh attrs.builder]
                    else
                      [./fix-builder.sh ./default-builder.sh]
                    );
              inherit stdenv system;
              C_INCLUDE_PATH = mingwRuntimeSrc + "/include" + ":" + w32apiSrc + "/include";
              CPLUS_INCLUDE_PATH = mingwRuntimeSrc + "/include" + ":" + w32apiSrc + "/include";
              LIBRARY_PATH = mingwRuntimeSrc + "/lib" + ":" + w32apiSrc + "/lib";
            })
          )
          // { meta = if attrs ? meta then attrs.meta else {}; };
       };
     };

  /**
   * fetchurl
   */
  fetchurlInit1 =
    import ../../build-support/fetchurl {
      stdenv = stdenvInit1;
      curl =
        (import ./pkgs).curl {
          stdenv = stdenvInit1;
        };
    };

  cygpath =
    import ./cygpath {
      stdenv = stdenvInit1;
    };

  /**
   * Hack: we need the cygpath of the Cygwin chmod.
   */
  fetchurl =
    import ./fetchurl {
      stdenv = stdenvInit2;
      curl = curl + "/bin/curl.exe";
      chmod = cygpath "/usr/bin/chmod";
    };

  /**
   * MSYS, installed using stdenvInit1
   *
   * @todo Maybe remove the make of msys?
   */
  msys =
    stdenvInit1.mkDerivation {
      name = "msys-1.0.11";
      builder = ./msys-builder.sh;
      src =
        fetchurlInit1 {
          url = ftp://ftp.strategoxt.org/pub/mingw/msys-1.0.11.tar.gz;
          sha256 = "08qp4jk279i66q6ngksg58fx3cfv1r6p5n394h2kfrs56qs9zvz4";
        };
    };

  msysShell = 
    msys + "/bin/sh.exe";

  /**
   * Binary packages, based on stdenvInit2
   */
  curl =
    (import ./pkgs).curl {
      stdenv = stdenvInit2;
    };

  gccFull =
    (import ./pkgs).gccFull {
      stdenv = stdenvInit2;
      inherit fetchurl;
    };

  make =
   (import ./pkgs).make {
     stdenv = stdenvInit2;
     inherit fetchurl;
   };

  tar =
   (import ./pkgs).tar {
     stdenv = stdenvInit2;
     inherit fetchurl;
   };

  binutils =
   (import ./pkgs).binutils {
     stdenv = stdenvInit2;
     inherit fetchurl;
    };

  mingwRuntimeBin =
    (import ./pkgs).mingwRuntimeBin {
      stdenv = stdenvInit2;
      inherit fetchurl;
    };

  w32apiBin =
    (import ./pkgs).w32apiBin {
      stdenv = stdenvInit2;
      inherit fetchurl;
    };

  pkgconfigBin =
    (import ./pkgs).pkgconfigBin {
      stdenv = stdenvInit3;
      inherit fetchurl;
    };

  /**
   * Source packages, based on stdenvInit3
   */
  mingwRuntimeSrc =
    (import ./pkgs).mingwRuntimeSrc {
      stdenv = stdenvInit3;
      inherit fetchurl;
    };

  w32apiSrc =
    (import ./pkgs).w32apiSrc {
      stdenv = stdenvInit3;
      inherit fetchurl;
    };

  replace =
    (import ./pkgs).replace {
      stdenv = stdenvInit3;
      inherit fetchurl;
    };
}