blob: 90f89cc0c78444d207fe4fc21de1534ad55a0367 (
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
{system ? builtins.currentSystem}:
let
pkgsFun = import ../../top-level/all-packages.nix;
pkgsNoParams = pkgsFun {};
raspberrypiCrossSystem = {
crossSystem = {
config = "armv6l-unknown-linux-gnueabi";
bigEndian = false;
arch = "arm";
float = "hard";
fpu = "vfp";
withTLS = true;
libc = "glibc";
platform = pkgsNoParams.platforms.raspberrypi;
openssl.system = "linux-generic32";
gcc = {
arch = "armv6";
fpu = "vfp";
float = "hard";
};
};
};
raspberrypiCrossSystemUclibc = {
crossSystem = {
config = "armv6l-unknown-linux-gnueabi";
bigEndian = false;
arch = "arm";
float = "hard";
fpu = "vfp";
withTLS = true;
libc = "uclibc";
platform = pkgsNoParams.platforms.raspberrypi;
openssl.system = "linux-generic32";
gcc = {
arch = "armv6";
fpu = "vfp";
float = "hard";
};
uclibc.extraConfig = ''
ARCH_WANTS_BIG_ENDIAN n
ARCH_BIG_ENDIAN n
ARCH_WANTS_LITTLE_ENDIAN y
ARCH_LITTLE_ENDIAN y
'';
};
};
pkgsuclibc = pkgsFun ({inherit system;} // raspberrypiCrossSystemUclibc);
pkgs = pkgsFun ({inherit system;} // raspberrypiCrossSystem);
inherit (pkgs) stdenv nukeReferences cpio binutilsCross;
# We want coreutils without ACL support.
coreutils_base = pkgs.coreutils.override (args: {
aclSupport = false;
});
coreutils_ = coreutils_base.crossDrv;
glibc = pkgs.libcCross;
bash = pkgs.bash.crossDrv;
findutils = pkgs.findutils.crossDrv;
diffutils = pkgs.diffutils.crossDrv;
gnused = pkgs.gnused.crossDrv;
gnugrep = pkgs.gnugrep.crossDrv;
gawk = pkgs.gawk.crossDrv;
gnutar = pkgs.gnutar.crossDrv;
gzip = pkgs.gzip.crossDrv;
bzip2 = pkgs.bzip2.crossDrv;
gnumake = pkgs.gnumake.crossDrv;
patch = pkgs.patch.crossDrv;
patchelf = pkgs.patchelf.crossDrv;
replace = pkgs.replace.crossDrv;
gcc = pkgs.gcc;
gmp = pkgs.gmp.crossDrv;
mpfr = pkgs.mpfr.crossDrv;
ppl = pkgs.ppl.crossDrv;
cloogppl = pkgs.cloogppl.crossDrv;
cloog = pkgs.cloog.crossDrv;
zlib = pkgs.zlib.crossDrv;
isl = pkgs.isl.crossDrv;
mpc = pkgs.mpc.crossDrv;
binutils = pkgs.binutils.crossDrv;
klibc = pkgs.linuxPackages.klibc.crossDrv;
in
rec {
curlStatic = import <nixpkgs/pkgs/tools/networking/curl> {
stdenv = pkgsuclibc.stdenv;
inherit (pkgsuclibc) fetchurl;
zlibSupport = false;
sslSupport = false;
linkStatic = true;
};
bzip2Static = import <nixpkgs/pkgs/tools/compression/bzip2> {
stdenv = pkgsuclibc.stdenv;
inherit (pkgsuclibc) fetchurl;
linkStatic = true;
};
inherit pkgs;
build =
stdenv.mkDerivation {
name = "build";
buildInputs = [nukeReferences cpio binutilsCross];
crossConfig = stdenv.cross.config;
buildCommand = ''
set -x
mkdir -p $out/bin $out/lib $out/libexec
# Copy what we need of Glibc.
cp -d ${glibc}/lib/ld-*.so* $out/lib
cp -d ${glibc}/lib/libc*.so* $out/lib
cp -d ${glibc}/lib/libc_nonshared.a $out/lib
cp -d ${glibc}/lib/libm*.so* $out/lib
cp -d ${glibc}/lib/libdl*.so* $out/lib
cp -d ${glibc}/lib/librt*.so* $out/lib
cp -d ${glibc}/lib/libpthread*.so* $out/lib
cp -d ${glibc}/lib/libnsl*.so* $out/lib
cp -d ${glibc}/lib/libutil*.so* $out/lib
cp -d ${glibc}/lib/crt?.o $out/lib
cp -rL ${glibc}/include $out
chmod -R u+w $out/include
# Hopefully we won't need these.
rm -rf $out/include/mtd $out/include/rdma $out/include/sound $out/include/video
find $out/include -name .install -exec rm {} \;
find $out/include -name ..install.cmd -exec rm {} \;
mv $out/include $out/include-glibc
# Copy coreutils, bash, etc.
cp ${coreutils_}/bin/* $out/bin
(cd $out/bin && rm vdir dir sha*sum pinky factor pathchk runcon shuf who whoami shred users)
cp ${bash}/bin/bash $out/bin
cp ${findutils}/bin/find $out/bin
cp ${findutils}/bin/xargs $out/bin
cp -d ${diffutils}/bin/* $out/bin
cp -d ${gnused}/bin/* $out/bin
cp -d ${gnugrep}/bin/* $out/bin
cp ${gawk}/bin/gawk $out/bin
cp -d ${gawk}/bin/awk $out/bin
cp ${gnutar}/bin/tar $out/bin
cp ${gzip}/bin/gzip $out/bin
cp ${bzip2}/bin/bzip2 $out/bin
cp -d ${gnumake}/bin/* $out/bin
cp -d ${patch}/bin/* $out/bin
cp ${patchelf}/bin/* $out/bin
cp ${replace}/bin/* $out/bin
cp -d ${gnugrep.pcre.crossDrv}/lib/libpcre*.so* $out/lib # needed by grep
# Copy what we need of GCC.
cp -d ${gcc.cc.crossDrv}/bin/gcc $out/bin
cp -d ${gcc.cc.crossDrv}/bin/cpp $out/bin
cp -d ${gcc.cc.crossDrv}/bin/g++ $out/bin
cp -d ${gcc.cc.crossDrv}/lib*/libgcc_s.so* $out/lib
cp -d ${gcc.cc.crossDrv}/lib*/libstdc++.so* $out/lib
cp -rd ${gcc.cc.crossDrv}/lib/gcc $out/lib
chmod -R u+w $out/lib
rm -f $out/lib/gcc/*/*/include*/linux
rm -f $out/lib/gcc/*/*/include*/sound
rm -rf $out/lib/gcc/*/*/include*/root
rm -f $out/lib/gcc/*/*/include-fixed/asm
rm -rf $out/lib/gcc/*/*/plugin
#rm -f $out/lib/gcc/*/*/*.a
cp -rd ${gcc.cc.crossDrv}/libexec/* $out/libexec
mkdir $out/include
cp -rd ${gcc.cc.crossDrv}/include/c++ $out/include
chmod -R u+w $out/include
rm -rf $out/include/c++/*/ext/pb_ds
rm -rf $out/include/c++/*/ext/parallel
cp -d ${gmp}/lib/libgmp*.so* $out/lib
cp -d ${mpfr}/lib/libmpfr*.so* $out/lib
cp -d ${cloogppl}/lib/libcloog*.so* $out/lib
cp -d ${cloog}/lib/libcloog*.so* $out/lib
cp -d ${ppl}/lib/libppl*.so* $out/lib
cp -d ${isl}/lib/libisl*.so* $out/lib
cp -d ${mpc}/lib/libmpc*.so* $out/lib
cp -d ${zlib}/lib/libz.so* $out/lib
# Copy binutils.
for i in as ld ar ranlib nm strip readelf objdump; do
cp ${binutils}/bin/$i $out/bin
done
chmod -R u+w $out
# Strip executables even further.
for i in $out/bin/* $out/libexec/gcc/*/*/*; do
if test -x $i -a ! -L $i; then
chmod +w $i
$crossConfig-strip -s $i || true
fi
done
nuke-refs $out/bin/*
nuke-refs $out/lib/*
nuke-refs $out/libexec/gcc/*/*/*
nuke-refs $out/libexec/gcc/*/*/*/*
mkdir $out/.pack
mv $out/* $out/.pack
mv $out/.pack $out/pack
mkdir $out/on-server
(cd $out/pack && (find | cpio -o -H newc)) | bzip2 > $out/on-server/bootstrap-tools.cpio.bz2
mkdir $out/in-nixpkgs
cp ${klibc}/lib/klibc/bin.static/sh $out/in-nixpkgs
cp ${klibc}/lib/klibc/bin.static/cpio $out/in-nixpkgs
cp ${klibc}/lib/klibc/bin.static/mkdir $out/in-nixpkgs
cp ${klibc}/lib/klibc/bin.static/ln $out/in-nixpkgs
cp ${curlStatic.crossDrv}/bin/curl $out/in-nixpkgs
cp ${bzip2Static.crossDrv}/bin/bzip2 $out/in-nixpkgs
chmod u+w $out/in-nixpkgs/*
$crossConfig-strip $out/in-nixpkgs/*
nuke-refs $out/in-nixpkgs/*
bzip2 $out/in-nixpkgs/curl
''; # */
# 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 = [];
};
unpack =
stdenv.mkDerivation {
name = "unpack";
buildCommand = ''
${build}/in-nixpkgs/mkdir $out
${build}/in-nixpkgs/bzip2 -d < ${build}/on-server/bootstrap-tools.cpio.bz2 | (cd $out && ${build}/in-nixpkgs/cpio -V -i)
for i in $out/bin/* $out/libexec/gcc/*/*/*; do
echo patching $i
if ! test -L $i; then
LD_LIBRARY_PATH=$out/lib $out/lib/ld-linux*.so.2 \
$out/bin/patchelf --set-interpreter $out/lib/ld-linux*.so.2 --set-rpath $out/lib --force-rpath $i
fi
done
# Fix the libc linker script.
for i in $out/lib/libc.so; do
cat $i | sed "s|/nix/store/e*-[^/]*/|$out/|g" > $i.tmp
mv $i.tmp $i
done
''; # " */
allowedReferences = ["out"];
};
}
|