2022-06-16 20:29:09 +00:00
|
|
|
{ lib
|
Clean up cross bootstrapping
For a long time, we've had `crossLibcStdenv`, `*Cross` libc attributes,
and `*bsdCross` pre-libc package sets. This was always bad because
having "cross" things is "not declarative": the naming doesn't reflect
what packages *need* but rather how we *provide* something. This is
ugly, and creates needless friction between cross and native building.
Now, almost all of these `*Cross` attributes are gone: just these are
kept:
- Glibc's and Musl's are kept, because those packages are widely used
and I didn't want to risk changing the native builds of those at this
time.
- generic `libcCross`, `theadsCross`, and friends, because these relate
to the convolulted GCC bootstrap which still needs to be redone.
The BSD and obscure Linux or freestnanding libcs have conversely all
been made to use a new `stdenvNoLibc`, which is like the old
`crossLibcStdenv` except:
1. It usable for native and cross alike
2. It named according to what it *is* ("a standard environment without
libc but with a C compiler"), rather than some non-compositional
jargon ("the stdenv used for building libc when cross compiling",
yuck).
I should have done this change long ago, but I was stymied because of
"infinite recursions". The problem was that in too many cases we are
overriding `stdenv` to *remove* things we don't need, and this risks
cyles since those more minimal stdenvs are used to build things in the
more maximal stdenvs.
The solution is to pass `stage.nix` `stdenvNoCC`, so we can override to
*build up* rather than *tear down*. For now, the full `stdenv` is also
passed, so I don't need to change the native bootstraps, but I can see
this changing as we make things more uniform and clean those up.
(adapted from commit 51f1ecaa59a3b7c182b24e71a3176c83d6cd601e)
(adapted from commit 1743662e55669081056743f22f6e616588061cba)
2024-06-18 16:38:21 +00:00
|
|
|
, stdenvNoLibc
|
2022-06-16 20:29:09 +00:00
|
|
|
, buildPackages
|
|
|
|
, fetchurl
|
2024-04-06 04:20:00 +00:00
|
|
|
, gitUpdater
|
2022-06-16 20:29:09 +00:00
|
|
|
, linuxHeaders
|
|
|
|
, libiconvReal
|
2018-05-10 00:49:12 +00:00
|
|
|
, extraConfig ? ""
|
|
|
|
}:
|
2009-11-08 00:32:12 +00:00
|
|
|
|
2009-12-04 13:35:58 +00:00
|
|
|
let
|
Clean up cross bootstrapping
For a long time, we've had `crossLibcStdenv`, `*Cross` libc attributes,
and `*bsdCross` pre-libc package sets. This was always bad because
having "cross" things is "not declarative": the naming doesn't reflect
what packages *need* but rather how we *provide* something. This is
ugly, and creates needless friction between cross and native building.
Now, almost all of these `*Cross` attributes are gone: just these are
kept:
- Glibc's and Musl's are kept, because those packages are widely used
and I didn't want to risk changing the native builds of those at this
time.
- generic `libcCross`, `theadsCross`, and friends, because these relate
to the convolulted GCC bootstrap which still needs to be redone.
The BSD and obscure Linux or freestnanding libcs have conversely all
been made to use a new `stdenvNoLibc`, which is like the old
`crossLibcStdenv` except:
1. It usable for native and cross alike
2. It named according to what it *is* ("a standard environment without
libc but with a C compiler"), rather than some non-compositional
jargon ("the stdenv used for building libc when cross compiling",
yuck).
I should have done this change long ago, but I was stymied because of
"infinite recursions". The problem was that in too many cases we are
overriding `stdenv` to *remove* things we don't need, and this risks
cyles since those more minimal stdenvs are used to build things in the
more maximal stdenvs.
The solution is to pass `stage.nix` `stdenvNoCC`, so we can override to
*build up* rather than *tear down*. For now, the full `stdenv` is also
passed, so I don't need to change the native bootstraps, but I can see
this changing as we make things more uniform and clean those up.
(adapted from commit 51f1ecaa59a3b7c182b24e71a3176c83d6cd601e)
(adapted from commit 1743662e55669081056743f22f6e616588061cba)
2024-06-18 16:38:21 +00:00
|
|
|
stdenv = stdenvNoLibc;
|
2022-06-16 20:29:09 +00:00
|
|
|
isCross = (stdenv.buildPlatform != stdenv.hostPlatform);
|
2010-08-21 16:46:23 +00:00
|
|
|
configParser = ''
|
|
|
|
function parseconfig {
|
|
|
|
set -x
|
|
|
|
while read LINE; do
|
|
|
|
NAME=`echo "$LINE" | cut -d \ -f 1`
|
|
|
|
OPTION=`echo "$LINE" | cut -d \ -f 2`
|
|
|
|
|
|
|
|
if test -z "$NAME"; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "parseconfig: removing $NAME"
|
|
|
|
sed -i /^$NAME=/d .config
|
|
|
|
|
2015-02-02 00:03:18 +00:00
|
|
|
#if test "$OPTION" != n; then
|
2010-08-21 16:46:23 +00:00
|
|
|
echo "parseconfig: setting $NAME=$OPTION"
|
|
|
|
echo "$NAME=$OPTION" >> .config
|
2015-02-02 00:03:18 +00:00
|
|
|
#fi
|
2010-08-21 16:46:23 +00:00
|
|
|
done
|
|
|
|
set +x
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
2012-05-24 19:12:36 +00:00
|
|
|
# UCLIBC_SUSV4_LEGACY defines 'tmpnam', needed for gcc libstdc++ builds.
|
2010-08-21 16:46:23 +00:00
|
|
|
nixConfig = ''
|
|
|
|
RUNTIME_PREFIX "/"
|
|
|
|
DEVEL_PREFIX "/"
|
|
|
|
UCLIBC_HAS_WCHAR y
|
|
|
|
UCLIBC_HAS_FTW y
|
|
|
|
UCLIBC_HAS_RPC y
|
|
|
|
DO_C99_MATH y
|
|
|
|
UCLIBC_HAS_PROGRAM_INVOCATION_NAME y
|
2022-06-16 20:29:09 +00:00
|
|
|
UCLIBC_HAS_RESOLVER_SUPPORT y
|
2012-05-24 19:12:36 +00:00
|
|
|
UCLIBC_SUSV4_LEGACY y
|
2012-05-24 19:16:00 +00:00
|
|
|
UCLIBC_HAS_THREADS_NATIVE y
|
2010-08-21 16:46:23 +00:00
|
|
|
KERNEL_HEADERS "${linuxHeaders}/include"
|
2021-12-10 01:12:42 +00:00
|
|
|
'' + lib.optionalString (stdenv.hostPlatform.gcc.float or "" == "soft") ''
|
|
|
|
UCLIBC_HAS_FPU n
|
2022-06-16 20:29:09 +00:00
|
|
|
'' + lib.optionalString (stdenv.hostPlatform.isAarch32 && isCross) ''
|
2015-02-02 00:03:18 +00:00
|
|
|
CONFIG_ARM_EABI y
|
|
|
|
ARCH_WANTS_BIG_ENDIAN n
|
|
|
|
ARCH_BIG_ENDIAN n
|
|
|
|
ARCH_WANTS_LITTLE_ENDIAN y
|
|
|
|
ARCH_LITTLE_ENDIAN y
|
|
|
|
UCLIBC_HAS_FPU n
|
2010-08-21 16:46:23 +00:00
|
|
|
'';
|
2009-12-04 13:35:58 +00:00
|
|
|
in
|
2023-10-08 21:07:11 +00:00
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
2022-01-10 22:30:11 +00:00
|
|
|
pname = "uclibc-ng";
|
2024-08-20 00:09:08 +00:00
|
|
|
version = "1.0.50";
|
2009-12-04 13:35:58 +00:00
|
|
|
|
2018-05-10 03:20:29 +00:00
|
|
|
src = fetchurl {
|
2023-10-08 21:07:11 +00:00
|
|
|
url = "https://downloads.uclibc-ng.org/releases/${finalAttrs.version}/uClibc-ng-${finalAttrs.version}.tar.xz";
|
2024-08-20 00:09:08 +00:00
|
|
|
hash = "sha256-rthnJR9II6dOpeOjmT06fBIygKvhXjjcIGdww5aPIc8=";
|
2009-11-08 00:32:12 +00:00
|
|
|
};
|
|
|
|
|
2010-03-09 20:36:56 +00:00
|
|
|
# 'ftw' needed to build acl, a coreutils dependency
|
2009-11-08 00:32:12 +00:00
|
|
|
configurePhase = ''
|
2018-05-10 00:49:12 +00:00
|
|
|
make defconfig
|
2010-08-21 16:46:23 +00:00
|
|
|
${configParser}
|
|
|
|
cat << EOF | parseconfig
|
|
|
|
${nixConfig}
|
|
|
|
${extraConfig}
|
2021-01-23 01:33:55 +00:00
|
|
|
${stdenv.hostPlatform.uclibc.extraConfig or ""}
|
2010-08-21 16:46:23 +00:00
|
|
|
EOF
|
2017-12-10 22:28:25 +00:00
|
|
|
( set +o pipefail; yes "" | make oldconfig )
|
2009-11-08 00:32:12 +00:00
|
|
|
'';
|
|
|
|
|
2016-08-05 18:15:27 +00:00
|
|
|
hardeningDisable = [ "stackprotector" ];
|
|
|
|
|
2009-12-04 13:35:58 +00:00
|
|
|
# Cross stripping hurts.
|
2022-06-16 20:29:09 +00:00
|
|
|
dontStrip = isCross;
|
2009-12-04 13:35:58 +00:00
|
|
|
|
2018-05-10 00:49:12 +00:00
|
|
|
depsBuildBuild = [ buildPackages.stdenv.cc ];
|
2009-12-04 13:35:58 +00:00
|
|
|
|
2018-05-10 00:49:12 +00:00
|
|
|
makeFlags = [
|
2021-12-10 01:12:42 +00:00
|
|
|
"ARCH=${stdenv.hostPlatform.linuxArch}"
|
|
|
|
"TARGET_ARCH=${stdenv.hostPlatform.linuxArch}"
|
2018-05-10 00:49:12 +00:00
|
|
|
"VERBOSE=1"
|
2022-06-16 20:29:09 +00:00
|
|
|
] ++ lib.optionals (isCross) [
|
2018-05-10 00:49:12 +00:00
|
|
|
"CROSS=${stdenv.cc.targetPrefix}"
|
|
|
|
];
|
2009-12-04 13:35:58 +00:00
|
|
|
|
2017-12-06 11:57:10 +00:00
|
|
|
# `make libpthread/nptl/sysdeps/unix/sysv/linux/lowlevelrwlock.h`:
|
|
|
|
# error: bits/sysnum.h: No such file or directory
|
|
|
|
enableParallelBuilding = false;
|
2014-10-29 13:18:00 +00:00
|
|
|
|
2009-11-08 00:32:12 +00:00
|
|
|
installPhase = ''
|
2022-06-16 20:29:09 +00:00
|
|
|
runHook preInstall
|
|
|
|
|
2009-11-08 00:32:12 +00:00
|
|
|
mkdir -p $out
|
2021-12-10 01:12:42 +00:00
|
|
|
make $makeFlags PREFIX=$out VERBOSE=1 install
|
2010-03-09 15:48:25 +00:00
|
|
|
(cd $out/include && ln -s $(ls -d ${linuxHeaders}/include/* | grep -v "scsi$") .)
|
2012-05-24 21:44:34 +00:00
|
|
|
# libpthread.so may not exist, so I do || true
|
|
|
|
sed -i s@/lib/@$out/lib/@g $out/lib/libc.so $out/lib/libpthread.so || true
|
2010-03-09 18:05:38 +00:00
|
|
|
|
2022-06-16 20:29:09 +00:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
2014-10-29 13:18:00 +00:00
|
|
|
|
2023-10-08 21:07:11 +00:00
|
|
|
passthru = {
|
|
|
|
# Derivations may check for the existance of this attribute, to know what to
|
|
|
|
# link to.
|
|
|
|
libiconv = libiconvReal;
|
2024-04-06 04:20:00 +00:00
|
|
|
|
|
|
|
updateScript = gitUpdater {
|
|
|
|
url = "https://git.uclibc-ng.org/git/uclibc-ng.git";
|
|
|
|
rev-prefix = "v";
|
|
|
|
};
|
2023-10-08 21:07:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
meta = {
|
2018-05-10 03:20:29 +00:00
|
|
|
homepage = "https://uclibc-ng.org";
|
2022-06-16 20:29:09 +00:00
|
|
|
description = "Embedded C library";
|
|
|
|
longDescription = ''
|
|
|
|
uClibc-ng is a small C library for developing embedded Linux systems. It
|
|
|
|
is much smaller than the GNU C Library, but nearly all applications
|
|
|
|
supported by glibc also work perfectly with uClibc-ng.
|
|
|
|
|
|
|
|
Porting applications from glibc to uClibc-ng typically involves just
|
|
|
|
recompiling the source code. uClibc-ng supports shared libraries and
|
|
|
|
threading. It currently runs on standard Linux and MMU-less (also known as
|
|
|
|
uClinux) systems with support for Aarch64, Alpha, ARC, ARM, AVR32,
|
|
|
|
Blackfin, CRIS, C-Sky, C6X, FR-V, H8/300, HPPA, i386, IA64, KVX, LM32,
|
|
|
|
M68K/Coldfire, Metag, Microblaze, MIPS, MIPS64, NDS32, NIOS2, OpenRISC,
|
|
|
|
PowerPC, RISCV64, Sparc, Sparc64, SuperH, Tile, X86_64 and XTENSA
|
|
|
|
processors. Alpha, FR-V, HPPA, IA64, LM32, NIOS2, Tile and Sparc64 are
|
|
|
|
experimental and need more testing.
|
|
|
|
'';
|
2023-10-08 21:07:11 +00:00
|
|
|
license = lib.licenses.lgpl2Plus;
|
|
|
|
maintainers = with lib.maintainers; [ rasendubi AndersonTorres ];
|
|
|
|
platforms = lib.platforms.linux;
|
|
|
|
badPlatforms = lib.platforms.aarch64;
|
2022-06-16 20:29:09 +00:00
|
|
|
};
|
2023-10-08 21:07:11 +00:00
|
|
|
})
|