1{ stdenv, fetchurl, linuxHeaders, perl
2, buildPlatform, hostPlatform
3}:
4
5let
6 commonMakeFlags = [
7 "prefix=$(out)"
8 "SHLIBDIR=$(out)/lib"
9 ];
10in
11
12stdenv.mkDerivation rec {
13 name = "klibc-${version}";
14 version = "2.0.4";
15
16 src = fetchurl {
17 url = "mirror://kernel/linux/libs/klibc/2.0/klibc-${version}.tar.xz";
18 sha256 = "7f9a0850586def7cf4faeeb75e5d0f66e613674c524f6e77b0f4d93a26c801cb";
19 };
20
21 patches = [ ./no-reinstall-kernel-headers.patch ];
22
23 nativeBuildInputs = [ perl ];
24
25 hardeningDisable = [ "format" "stackprotector" ];
26
27 makeFlags = commonMakeFlags ++ [
28 "KLIBCARCH=${hostPlatform.platform.kernelArch}"
29 "KLIBCKERNELSRC=${linuxHeaders}"
30 ] # TODO(@Ericson2314): We now can get the ABI from
31 # `hostPlatform.parsed.abi`, is this still a good idea?
32 ++ stdenv.lib.optional (hostPlatform.platform.kernelArch == "arm") "CONFIG_AEABI=y"
33 ++ stdenv.lib.optional (hostPlatform != buildPlatform) "CROSS_COMPILE=${stdenv.cc.targetPrefix}";
34
35 # Install static binaries as well.
36 postInstall = ''
37 dir=$out/lib/klibc/bin.static
38 mkdir $dir
39 cp $(find $(find . -name static) -type f ! -name "*.g" -a ! -name ".*") $dir/
40 cp usr/dash/sh $dir/
41
42 for file in ${linuxHeaders}/include/*; do
43 ln -sv $file $out/lib/klibc/include
44 done
45 '';
46
47 meta = {
48 platforms = [ "x86_64-linux" ];
49 };
50}