2013-03-24 11:45:00 +00:00
|
|
|
{ stdenv, fetchurl, perl, bison, mktemp, linuxHeaders, linuxHeadersCross, kernelDev ? null }:
|
2005-08-27 21:48:05 +01:00
|
|
|
|
2006-11-25 00:28:15 +00:00
|
|
|
assert stdenv.isLinux;
|
2005-08-27 21:48:05 +01:00
|
|
|
|
2010-04-04 19:10:42 +01:00
|
|
|
let
|
2011-10-25 09:20:03 +01:00
|
|
|
version = "1.5.24";
|
2010-04-04 19:10:42 +01:00
|
|
|
baseMakeFlags = ["V=1" "prefix=$out" "SHLIBDIR=$out/lib"];
|
|
|
|
in
|
2009-01-29 15:44:37 +00:00
|
|
|
|
2005-08-27 21:48:05 +01:00
|
|
|
stdenv.mkDerivation {
|
2013-03-24 11:45:00 +00:00
|
|
|
name = "klibc-${version}${stdenv.lib.optionalString (kernelDev != null) "-${kernelDev.version}"}";
|
2009-01-29 15:44:37 +00:00
|
|
|
|
|
|
|
src = fetchurl {
|
2012-06-22 16:35:00 +01:00
|
|
|
url = "mirror://kernel/linux/libs/klibc/1.5/klibc-${version}.tar.bz2";
|
2011-10-25 09:20:03 +01:00
|
|
|
sha256 = "18lm32dlj9k2ky9wwk274zmc3jndgrb41b6qm82g3lza6wlw3yki";
|
2009-01-29 15:44:37 +00:00
|
|
|
};
|
2010-09-05 07:00:14 +01:00
|
|
|
|
2010-09-09 18:48:11 +01:00
|
|
|
# Trick to make this build on nix. It expects to have the kernel sources
|
|
|
|
# instead of only the linux kernel headers.
|
|
|
|
# So it cannot run the 'make headers_install' it wants to run.
|
|
|
|
# We don't install the headers, so klibc will not be useful as libc, but
|
|
|
|
# usually in nixpkgs we only use the userspace tools comming with klibc.
|
2013-03-24 11:45:00 +00:00
|
|
|
prePatch = stdenv.lib.optionalString (kernelDev == null) ''
|
2010-09-09 18:48:11 +01:00
|
|
|
sed -i -e /headers_install/d scripts/Kbuild.install
|
|
|
|
'';
|
2009-01-29 15:44:37 +00:00
|
|
|
|
2010-04-04 19:10:42 +01:00
|
|
|
makeFlags = baseMakeFlags;
|
|
|
|
|
|
|
|
inherit linuxHeaders;
|
|
|
|
|
|
|
|
crossAttrs = {
|
|
|
|
makeFlags = baseMakeFlags ++ [ "CROSS_COMPILE=${stdenv.cross.config}-"
|
|
|
|
"KLIBCARCH=${stdenv.cross.arch}" ];
|
|
|
|
|
|
|
|
patchPhase = ''
|
2010-08-01 22:21:26 +01:00
|
|
|
sed -i 's/-fno-pic -mno-abicalls/& -mabi=32/' usr/klibc/arch/mips/MCONFIG
|
2010-04-04 19:10:42 +01:00
|
|
|
sed -i /KLIBCKERNELSRC/d scripts/Kbuild.install
|
2010-08-01 22:21:26 +01:00
|
|
|
# Wrong check for __mips64 in klibc
|
|
|
|
sed -i s/__mips64__/__mips64/ usr/include/fcntl.h
|
2010-04-04 19:10:42 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
linuxHeaders = linuxHeadersCross;
|
|
|
|
};
|
2009-01-29 15:44:37 +00:00
|
|
|
|
2010-04-04 19:10:42 +01:00
|
|
|
# The AEABI option concerns only arm systems, and does not affect the build for
|
|
|
|
# other systems.
|
2008-11-02 15:53:55 +00:00
|
|
|
preBuild = ''
|
2009-11-08 00:32:12 +00:00
|
|
|
sed -i /CONFIG_AEABI/d defconfig
|
|
|
|
echo "CONFIG_AEABI=y" >> defconfig
|
2008-11-02 15:53:55 +00:00
|
|
|
makeFlags=$(eval "echo $makeFlags")
|
|
|
|
|
2013-03-24 11:45:00 +00:00
|
|
|
'' + (if kernelDev == null then ''
|
2009-01-29 15:44:37 +00:00
|
|
|
mkdir linux
|
2010-04-04 19:10:42 +01:00
|
|
|
cp -prsd $linuxHeaders/include linux/
|
2008-11-02 15:53:55 +00:00
|
|
|
chmod -R u+w linux/include/
|
2011-10-25 09:59:39 +01:00
|
|
|
'' else ''
|
2013-03-24 11:45:00 +00:00
|
|
|
tar xvf ${kernelDev.src}
|
2011-10-25 09:59:39 +01:00
|
|
|
mv linux* linux
|
|
|
|
cd linux
|
2013-03-24 11:45:00 +00:00
|
|
|
ln -sv ${kernelDev}/config .config
|
2011-10-25 09:59:39 +01:00
|
|
|
make prepare
|
|
|
|
cd ..
|
|
|
|
'');
|
2009-01-29 15:44:37 +00:00
|
|
|
|
|
|
|
# Install static binaries as well.
|
|
|
|
postInstall = ''
|
|
|
|
dir=$out/lib/klibc/bin.static
|
|
|
|
mkdir $dir
|
|
|
|
cp $(find $(find . -name static) -type f ! -name "*.g" -a ! -name ".*") $dir/
|
|
|
|
cp usr/dash/sh $dir/
|
|
|
|
'';
|
|
|
|
|
2012-12-28 18:20:09 +00:00
|
|
|
nativeBuildInputs = [ perl bison mktemp ];
|
2005-08-27 21:48:05 +01:00
|
|
|
}
|