push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,168 @@
{
lib,
derivationWithMeta,
fetchurl,
kaem,
tinycc,
gnumake,
gnupatch,
coreutils,
mescc-tools-extra,
bash_2_05,
}:
let
pname = "bash";
version = "2.05b";
src = fetchurl {
url = "mirror://gnu/bash/bash-${version}.tar.gz";
sha256 = "1r1z2qdw3rz668nxrzwa14vk2zcn00hw7mpjn384picck49d80xs";
};
# Thanks to the live-bootstrap project!
# See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/bash-2.05b/bash-2.05b.kaem
liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/bash-2.05b";
main_mk = fetchurl {
url = "${liveBootstrap}/mk/main.mk";
sha256 = "0hj29q3pq3370p18sxkpvv9flb7yvx2fs96xxlxqlwa8lkimd0j4";
};
common_mk = fetchurl {
url = "${liveBootstrap}/mk/common.mk";
sha256 = "09rigxxf85p2ybnq248sai1gdx95yykc8jmwi4yjx389zh09mcr8";
};
builtins_mk = fetchurl {
url = "${liveBootstrap}/mk/builtins.mk";
sha256 = "0939dy5by1xhfmsjj6w63nlgk509fjrhpb2crics3dpcv7prl8lj";
};
patches = [
# mes libc does not have locale support
(fetchurl {
url = "${liveBootstrap}/patches/mes-libc.patch";
sha256 = "0zksdjf6zbb3p4hqg6plq631y76hhhgab7kdvf7cnpk8bcykn12z";
})
# int name, namelen; is wrong for mes libc, it is char* name, so we modify tinycc
# to reflect this.
(fetchurl {
url = "${liveBootstrap}/patches/tinycc.patch";
sha256 = "042d2kr4a8klazk1hlvphxr6frn4mr53k957aq3apf6lbvrjgcj2";
})
# add ifdef's for features we don't want
(fetchurl {
url = "${liveBootstrap}/patches/missing-defines.patch";
sha256 = "1q0k1kj5mrvjkqqly7ki5575a5b3hy1ywnmvhrln318yh67qnkj4";
})
# mes libc + setting locale = not worky
(fetchurl {
url = "${liveBootstrap}/patches/locale.patch";
sha256 = "1p1q1slhafsgj8x4k0dpn9h6ryq5fwfx7dicbbxhldbw7zvnnbx9";
})
# We do not have /dev at this stage of the bootstrap, including /dev/tty
(fetchurl {
url = "${liveBootstrap}/patches/dev-tty.patch";
sha256 = "1315slv5f7ziajqyxg4jlyanf1xwd06xw14y6pq7xpm3jzjk55j9";
})
];
in
kaem.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnupatch
coreutils
];
passthru.runCommand =
name: env: buildCommand:
derivationWithMeta (
{
inherit name buildCommand;
builder = "${bash_2_05}/bin/bash";
args = [
"-e"
(builtins.toFile "bash-builder.sh" ''
export CONFIG_SHELL=$SHELL
# Normalize the NIX_BUILD_CORES variable. The value might be 0, which
# means that we're supposed to try and auto-detect the number of
# available CPU cores at run-time. We don't have nproc to detect the
# number of available CPU cores so default to 1 if not set.
NIX_BUILD_CORES="''${NIX_BUILD_CORES:-1}"
if [ $NIX_BUILD_CORES -le 0 ]; then
NIX_BUILD_CORES=1
fi
export NIX_BUILD_CORES
bash -eux $buildCommandPath
'')
];
passAsFile = [ "buildCommand" ];
SHELL = "${bash_2_05}/bin/bash";
PATH = lib.makeBinPath (
(env.nativeBuildInputs or [ ])
++ [
bash_2_05
coreutils
# provides untar, ungz, and unbz2
mescc-tools-extra
]
);
}
// (removeAttrs env [ "nativeBuildInputs" ])
);
passthru.tests.get-version =
result:
kaem.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/bash --version
mkdir ''${out}
'';
meta = with lib; {
description = "GNU Bourne-Again Shell, the de facto standard shell on Linux";
homepage = "https://www.gnu.org/software/bash";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
};
}
''
# Unpack
ungz --file ${src} --output bash.tar
untar --file bash.tar
rm bash.tar
cd bash-${version}
# Patch
${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches}
# Configure
cp ${main_mk} Makefile
cp ${builtins_mk} builtins/Makefile
cp ${common_mk} common.mk
touch config.h
touch include/version.h
touch include/pipesize.h
# Build
make \
CC="tcc -B ${tinycc.libs}/lib" \
mkbuiltins
cd builtins
make \
CC="tcc -B ${tinycc.libs}/lib" \
libbuiltins.a
cd ..
make CC="tcc -B ${tinycc.libs}/lib"
# Install
install -D bash ''${out}/bin/bash
ln -s bash ''${out}/bin/sh
''

View File

@@ -0,0 +1,128 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bootBash,
gnumake,
gnupatch,
gnused,
gnugrep,
gnutar,
gawk,
gzip,
diffutils,
tinycc,
derivationWithMeta,
bash,
coreutils,
}:
let
pname = "bash";
version = "5.2.15";
src = fetchurl {
url = "mirror://gnu/bash/bash-${version}.tar.gz";
sha256 = "132qng0jy600mv1fs95ylnlisx2wavkkgpb19c6kmz7lnmjhjwhk";
};
patches = [
# flush output for generated code
./mksignames-flush.patch
];
in
bootBash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
coreutils
tinycc.compiler
gnumake
gnupatch
gnused
gnugrep
gnutar
gawk
gzip
diffutils
];
passthru.runCommand =
name: env: buildCommand:
derivationWithMeta (
{
inherit name buildCommand;
builder = "${bash}/bin/bash";
args = [
"-e"
(builtins.toFile "bash-builder.sh" ''
export CONFIG_SHELL=$SHELL
# Normalize the NIX_BUILD_CORES variable. The value might be 0, which
# means that we're supposed to try and auto-detect the number of
# available CPU cores at run-time.
NIX_BUILD_CORES="''${NIX_BUILD_CORES:-1}"
if ((NIX_BUILD_CORES <= 0)); then
guess=$(nproc 2>/dev/null || true)
((NIX_BUILD_CORES = guess <= 0 ? 1 : guess))
fi
export NIX_BUILD_CORES
bash -eux $buildCommandPath
'')
];
passAsFile = [ "buildCommand" ];
SHELL = "${bash}/bin/bash";
PATH = lib.makeBinPath (
(env.nativeBuildInputs or [ ])
++ [
bash
coreutils
]
);
}
// (removeAttrs env [ "nativeBuildInputs" ])
);
passthru.tests.get-version =
result:
bootBash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/bash --version
mkdir $out
'';
meta = with lib; {
description = "GNU Bourne-Again Shell, the de facto standard shell on Linux";
homepage = "https://www.gnu.org/software/bash";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
};
}
''
# Unpack
tar xzf ${src}
cd bash-${version}
# Patch
${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches}
# Configure
export CC="tcc -B ${tinycc.libs}/lib"
export AR="tcc -ar"
export LD=tcc
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config} \
--without-bash-malloc
# Build
make -j $NIX_BUILD_CORES SHELL=bash
# Install
make -j $NIX_BUILD_CORES install
ln -s bash $out/bin/sh
''

View File

@@ -0,0 +1,10 @@
--- a/support/mksignames.c
+++ b/support/mksignames.c
@@ -68,6 +68,7 @@ write_signames (stream)
fprintf (stream, "};\n\n");
fprintf (stream, "#define initialize_signames()\n\n");
#endif
+ fflush(stream);
}
int

View File

@@ -0,0 +1,118 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
coreutils,
gnumake,
gnupatch,
gnused,
gnugrep,
gawk,
diffutils,
gnutar,
xz,
tinycc,
}:
let
# Based on https://github.com/ZilchOS/bootstrap-from-tcc/blob/2e0c68c36b3437386f786d619bc9a16177f2e149/using-nix/2a1-static-binutils.nix
pname = "binutils";
version = "2.41";
src = fetchurl {
url = "mirror://gnu/binutils/binutils-${version}.tar.xz";
hash = "sha256-rppXieI0WeWWBuZxRyPy0//DHAMXQZHvDQFb3wYAdFA=";
};
patches = [
# Make binutils output deterministic by default.
./deterministic.patch
];
configureFlags = [
"--prefix=${placeholder "out"}"
"--build=${buildPlatform.config}"
"--host=${hostPlatform.config}"
"--with-sysroot=/"
"--enable-deterministic-archives"
# depends on bison
"--disable-gprofng"
# Turn on --enable-new-dtags by default to make the linker set
# RUNPATH instead of RPATH on binaries. This is important because
# RUNPATH can be overridden using LD_LIBRARY_PATH at runtime.
"--enable-new-dtags"
# By default binutils searches $libdir for libraries. This brings in
# libbfd and libopcodes into a default visibility. Drop default lib
# path to force users to declare their use of these libraries.
"--with-lib-path=:"
];
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnupatch
gnused
gnugrep
gawk
diffutils
gnutar
xz
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/ld --version
mkdir $out
'';
meta = with lib; {
description = "Tools for manipulating binaries (linker, assembler, etc.)";
homepage = "https://www.gnu.org/software/binutils";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
};
}
''
# Unpack
cp ${src} binutils.tar.xz
unxz binutils.tar.xz
tar xf binutils.tar
rm binutils.tar
cd binutils-${version}
# Patch
${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches}
sed -i 's|/bin/sh|${bash}/bin/bash|' \
missing install-sh mkinstalldirs
# see libtool's 74c8993c178a1386ea5e2363a01d919738402f30
sed -i 's/| \$NL2SP/| sort | $NL2SP/' ltmain.sh
# alias makeinfo to true
mkdir aliases
ln -s ${coreutils}/bin/true aliases/makeinfo
export PATH="$(pwd)/aliases/:$PATH"
# Configure
export CC="tcc -B ${tinycc.libs}/lib"
export AR="tcc -ar"
export lt_cv_sys_max_cmd_len=32768
export CFLAGS="-D__LITTLE_ENDIAN__=1"
bash ./configure ${lib.concatStringsSep " " configureFlags}
# Build
make -j $NIX_BUILD_CORES all-libiberty all-gas all-bfd all-libctf all-zlib all-gprof
make all-ld # race condition on ld/.deps/ldwrite.Po, serialize
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
''

View File

@@ -0,0 +1,12 @@
diff -ur orig/binutils-2.23.1/ld/ldlang.c binutils-2.23.1/ld/ldlang.c
--- orig/ld/ldlang.c
+++ new/ld/ldlang.c
@@ -3095,6 +3095,8 @@
ldfile_output_machine))
einfo (_("%P%F:%s: can not set architecture: %E\n"), name);
+ link_info.output_bfd->flags |= BFD_DETERMINISTIC_OUTPUT;
+
link_info.hash = bfd_link_hash_table_create (link_info.output_bfd);
if (link_info.hash == NULL)
einfo (_("%P%F: can not create hash table: %E\n"));

View File

@@ -0,0 +1,59 @@
{
lib,
fetchurl,
bash,
tinycc,
gnumake,
gnutar,
gzip,
}:
let
pname = "bzip2";
version = "1.0.8";
src = fetchurl {
url = "https://sourceware.org/pub/bzip2/bzip2-${version}.tar.gz";
sha256 = "0s92986cv0p692icqlw1j42y9nld8zd83qwhzbqd61p1dqbh6nmb";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnutar
gzip
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/bzip2 --help
mkdir $out
'';
meta = with lib; {
description = "High-quality data compression program";
homepage = "https://www.sourceware.org/bzip2";
license = licenses.bsdOriginal;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
};
}
''
# Unpack
tar xzf ${src}
cd bzip2-${version}
# Build
make \
-j $NIX_BUILD_CORES \
CC="tcc -B ${tinycc.libs}/lib" \
AR="tcc -ar" \
bzip2 bzip2recover
# Install
make install -j $NIX_BUILD_CORES PREFIX=$out
''

View File

@@ -0,0 +1,120 @@
{
lib,
fetchurl,
kaem,
tinycc,
gnumake,
gnupatch,
}:
let
pname = "bootstrap-coreutils";
version = "5.0";
src = fetchurl {
url = "mirror://gnu/coreutils/coreutils-${version}.tar.gz";
sha256 = "10wq6k66i8adr4k08p0xmg87ff4ypiazvwzlmi7myib27xgffz62";
};
# Thanks to the live-bootstrap project!
# See https://github.com/fosslinux/live-bootstrap/blob/a8752029f60217a5c41c548b16f5cdd2a1a0e0db/sysa/coreutils-5.0/coreutils-5.0.kaem
liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/a8752029f60217a5c41c548b16f5cdd2a1a0e0db/sysa/coreutils-5.0";
makefile = fetchurl {
url = "${liveBootstrap}/mk/main.mk";
sha256 = "0njg4xccxfqrslrmlb8ls7h6hlnfmdx42nvxwmca8flvczwrplfd";
};
patches = [
# modechange.h uses functions defined in sys/stat.h, so we need to move it to
# after sys/stat.h include.
(fetchurl {
url = "${liveBootstrap}/patches/modechange.patch";
sha256 = "04xa4a5w2syjs3xs6qhh8kdzqavxnrxpxwyhc3qqykpk699p3ms5";
})
# mbstate_t is a struct that is required. However, it is not defined by mes libc.
(fetchurl {
url = "${liveBootstrap}/patches/mbstate.patch";
sha256 = "0rz3c0sflgxjv445xs87b83i7gmjpl2l78jzp6nm3khdbpcc53vy";
})
# strcoll() does not exist in mes libc, change it to strcmp.
(fetchurl {
url = "${liveBootstrap}/patches/ls-strcmp.patch";
sha256 = "0lx8rz4sxq3bvncbbr6jf0kyn5bqwlfv9gxyafp0541dld6l55p6";
})
# getdate.c is pre-compiled from getdate.y
# At this point we don't have bison yet and in any case getdate.y does not
# compile when generated with modern bison.
(fetchurl {
url = "${liveBootstrap}/patches/touch-getdate.patch";
sha256 = "1xd3z57lvkj7r8vs5n0hb9cxzlyp58pji7d335snajbxzwy144ma";
})
# touch: add -h to change symlink timestamps, where supported
(fetchurl {
url = "${liveBootstrap}/patches/touch-dereference.patch";
sha256 = "0wky5r3k028xwyf6g6ycwqxzc7cscgmbymncjg948vv4qxsxlfda";
})
# strcoll() does not exist in mes libc, change it to strcmp.
(fetchurl {
url = "${liveBootstrap}/patches/expr-strcmp.patch";
sha256 = "19f31lfsm1iwqzvp2fyv97lmqg4730prfygz9zip58651jf739a9";
})
# strcoll() does not exist in mes libc, change it to strcmp.
# hard_LC_COLLATE is used but not declared when HAVE_SETLOCALE is unset.
(fetchurl {
url = "${liveBootstrap}/patches/sort-locale.patch";
sha256 = "0bdch18mpyyxyl6gyqfs0wb4pap9flr11izqdyxccx1hhz0a2i6c";
})
# don't assume fopen cannot return stdin or stdout.
(fetchurl {
url = "${liveBootstrap}/patches/uniq-fopen.patch";
sha256 = "0qs6shyxl9j4h34v5j5sgpxrr4gjfljd2hxzw416ghwc3xzv63fp";
})
];
in
kaem.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnupatch
];
meta = with lib; {
description = "GNU Core Utilities";
homepage = "https://www.gnu.org/software/coreutils";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
};
}
''
# Unpack
ungz --file ${src} --output coreutils.tar
untar --file coreutils.tar
rm coreutils.tar
cd coreutils-${version}
# Patch
${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches}
# Configure
catm config.h
cp lib/fnmatch_.h lib/fnmatch.h
cp lib/ftw_.h lib/ftw.h
cp lib/search_.h lib/search.h
rm src/dircolors.h
# Build
make -f ${makefile} \
CC="tcc -B ${tinycc.libs}/lib" \
PREFIX=''${out}
# Check
./src/echo "Hello coreutils!"
# Install
./src/mkdir -p ''${out}/bin
make -f ${makefile} install PREFIX=''${out}
''

View File

@@ -0,0 +1,78 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
tinycc,
gnumake,
gnugrep,
gnused,
gawk,
gnutar,
gzip,
}:
let
pname = "bootstrap-coreutils-musl";
version = "9.4";
src = fetchurl {
url = "mirror://gnu/coreutils/coreutils-${version}.tar.gz";
hash = "sha256-X2ANkJOXOwr+JTk9m8GMRPIjJlf0yg2V6jHHAutmtzk=";
};
configureFlags = [
"--prefix=${placeholder "out"}"
"--build=${buildPlatform.config}"
"--host=${hostPlatform.config}"
# musl 1.1.x doesn't use 64bit time_t
"--disable-year2038"
# libstdbuf.so fails in static builds
"--enable-no-install-program=stdbuf"
];
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnused
gnugrep
gawk
gnutar
gzip
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/cat --version
mkdir $out
'';
meta = with lib; {
description = "GNU Core Utilities";
homepage = "https://www.gnu.org/software/coreutils";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
};
}
''
# Unpack
tar xzf ${src}
cd coreutils-${version}
# Configure
export CC="tcc -B ${tinycc.libs}/lib"
export LD=tcc
bash ./configure ${lib.concatStringsSep " " configureFlags}
# Build
make -j $NIX_BUILD_CORES AR="tcc -ar" MAKEINFO="true"
# Install
make -j $NIX_BUILD_CORES install MAKEINFO="true"
''

View File

@@ -0,0 +1,254 @@
{
lib,
config,
buildPlatform,
hostPlatform,
fetchurl,
checkMeta,
}:
lib.makeScope
# Prevent using top-level attrs to protect against introducing dependency on
# non-bootstrap packages by mistake. Any top-level inputs must be explicitly
# declared here.
(
extra:
lib.callPackageWith (
{
inherit
lib
config
buildPlatform
hostPlatform
fetchurl
checkMeta
;
}
// extra
)
)
(
self: with self; {
bash_2_05 = callPackage ./bash/2.nix { tinycc = tinycc-mes; };
bash = callPackage ./bash {
bootBash = bash_2_05;
tinycc = tinycc-musl;
coreutils = coreutils-musl;
gnumake = gnumake-musl;
gnutar = gnutar-musl;
};
binutils = callPackage ./binutils {
tinycc = tinycc-musl;
gnumake = gnumake-musl;
gnutar = gnutar-musl;
};
bzip2 = callPackage ./bzip2 {
tinycc = tinycc-musl;
gnumake = gnumake-musl;
gnutar = gnutar-musl;
};
coreutils = callPackage ./coreutils { tinycc = tinycc-mes; };
coreutils-musl = callPackage ./coreutils/musl.nix {
bash = bash_2_05;
tinycc = tinycc-musl;
gnumake = gnumake-musl;
gnutar = gnutar-musl;
};
diffutils = callPackage ./diffutils {
bash = bash_2_05;
tinycc = tinycc-musl;
gnumake = gnumake-musl;
gnutar = gnutar-musl;
};
findutils = callPackage ./findutils {
tinycc = tinycc-musl;
gnumake = gnumake-musl;
gnutar = gnutar-musl;
};
gawk-mes = callPackage ./gawk/mes.nix {
bash = bash_2_05;
tinycc = tinycc-mes;
gnused = gnused-mes;
};
gawk = callPackage ./gawk {
bash = bash_2_05;
tinycc = tinycc-musl;
gnumake = gnumake-musl;
gnutar = gnutar-musl;
bootGawk = gawk-mes;
};
gcc46 = callPackage ./gcc/4.6.nix {
tinycc = tinycc-musl;
gnumake = gnumake-musl;
gnutar = gnutar-musl;
# FIXME: not sure why new gawk doesn't work
gawk = gawk-mes;
};
gcc46-cxx = callPackage ./gcc/4.6.cxx.nix {
gcc = gcc46;
gnumake = gnumake-musl;
gnutar = gnutar-musl;
# FIXME: not sure why new gawk doesn't work
gawk = gawk-mes;
};
gcc8 = callPackage ./gcc/8.nix {
gcc = gcc46-cxx;
gnumake = gnumake-musl;
gnutar = gnutar-latest;
# FIXME: not sure why new gawk doesn't work
gawk = gawk-mes;
};
gcc-latest = callPackage ./gcc/latest.nix {
gcc = gcc8;
gnumake = gnumake-musl;
gnutar = gnutar-latest;
# FIXME: not sure why new gawk doesn't work
gawk = gawk-mes;
};
gnugrep = callPackage ./gnugrep {
bash = bash_2_05;
tinycc = tinycc-mes;
};
gnumake = callPackage ./gnumake { tinycc = tinycc-mes; };
gnumake-musl = callPackage ./gnumake/musl.nix {
bash = bash_2_05;
tinycc = tinycc-musl;
gawk = gawk-mes;
gnumakeBoot = gnumake;
};
gnupatch = callPackage ./gnupatch { tinycc = tinycc-mes; };
gnused = callPackage ./gnused {
bash = bash_2_05;
tinycc = tinycc-musl;
gnused = gnused-mes;
};
gnused-mes = callPackage ./gnused/mes.nix {
bash = bash_2_05;
tinycc = tinycc-mes;
};
gnutar = callPackage ./gnutar/mes.nix {
bash = bash_2_05;
tinycc = tinycc-mes;
gnused = gnused-mes;
};
gnutar-musl = callPackage ./gnutar/musl.nix {
bash = bash_2_05;
tinycc = tinycc-musl;
gnused = gnused-mes;
};
# FIXME: better package naming scheme
gnutar-latest = callPackage ./gnutar/latest.nix {
gcc = gcc46;
gnumake = gnumake-musl;
gnutarBoot = gnutar-musl;
};
gzip = callPackage ./gzip {
bash = bash_2_05;
tinycc = tinycc-mes;
gnused = gnused-mes;
};
heirloom = callPackage ./heirloom {
bash = bash_2_05;
tinycc = tinycc-mes;
};
heirloom-devtools = callPackage ./heirloom-devtools { tinycc = tinycc-mes; };
linux-headers = callPackage ./linux-headers { bash = bash_2_05; };
ln-boot = callPackage ./ln-boot { };
mes = callPackage ./mes { };
mes-libc = callPackage ./mes/libc.nix { };
musl11 = callPackage ./musl/1.1.nix {
bash = bash_2_05;
tinycc = tinycc-mes;
gnused = gnused-mes;
};
musl = callPackage ./musl {
gcc = gcc46;
gnumake = gnumake-musl;
};
stage0-posix = callPackage ./stage0-posix { };
inherit (self.stage0-posix)
kaem
m2libc
mescc-tools
mescc-tools-extra
;
tinycc-bootstrappable = lib.recurseIntoAttrs (callPackage ./tinycc/bootstrappable.nix { });
tinycc-mes = lib.recurseIntoAttrs (callPackage ./tinycc/mes.nix { });
tinycc-musl = lib.recurseIntoAttrs (
callPackage ./tinycc/musl.nix {
bash = bash_2_05;
musl = musl11;
}
);
xz = callPackage ./xz {
bash = bash_2_05;
tinycc = tinycc-musl;
gnumake = gnumake-musl;
gnutar = gnutar-musl;
};
inherit (callPackage ./utils.nix { }) derivationWithMeta writeTextFile writeText;
test = kaem.runCommand "minimal-bootstrap-test" { } ''
echo ${bash.tests.get-version}
echo ${bash_2_05.tests.get-version}
echo ${binutils.tests.get-version}
echo ${bzip2.tests.get-version}
echo ${coreutils-musl.tests.get-version}
echo ${diffutils.tests.get-version}
echo ${findutils.tests.get-version}
echo ${gawk-mes.tests.get-version}
echo ${gawk.tests.get-version}
echo ${gcc46.tests.get-version}
echo ${gcc46-cxx.tests.hello-world}
echo ${gcc8.tests.hello-world}
echo ${gcc-latest.tests.hello-world}
echo ${gnugrep.tests.get-version}
echo ${gnused.tests.get-version}
echo ${gnused-mes.tests.get-version}
echo ${gnutar.tests.get-version}
echo ${gnutar-musl.tests.get-version}
echo ${gnutar-latest.tests.get-version}
echo ${gzip.tests.get-version}
echo ${heirloom.tests.get-version}
echo ${mes.compiler.tests.get-version}
echo ${musl.tests.hello-world}
echo ${tinycc-mes.compiler.tests.chain}
echo ${tinycc-musl.compiler.tests.hello-world}
echo ${xz.tests.get-version}
mkdir ''${out}
'';
}
)

View File

@@ -0,0 +1,75 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
tinycc,
gnumake,
gnugrep,
gnused,
gawk,
gnutar,
xz,
}:
let
pname = "diffutils";
# last version that can be built by tinycc-musl 0.9.27
version = "3.8";
src = fetchurl {
url = "mirror://gnu/diffutils/diffutils-${version}.tar.xz";
hash = "sha256-pr3X0bMSZtEcT03mwbdI1GB6sCMa9RiPwlM9CuJDj+w=";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnused
gnugrep
gawk
gnutar
xz
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/diff --version
mkdir $out
'';
meta = with lib; {
description = "Commands for showing the differences between files (diff, cmp, etc.)";
homepage = "https://www.gnu.org/software/diffutils/diffutils.html";
license = licenses.gpl3Only;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
};
}
''
# Unpack
cp ${src} diffutils.tar.xz
unxz diffutils.tar.xz
tar xf diffutils.tar
rm diffutils.tar
cd diffutils-${version}
# Configure
export CC="tcc -B ${tinycc.libs}/lib"
export LD=tcc
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config}
# Build
make -j $NIX_BUILD_CORES AR="tcc -ar"
# Install
make -j $NIX_BUILD_CORES install
''

View File

@@ -0,0 +1,79 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
tinycc,
gnumake,
gnugrep,
gnused,
gawk,
gnutar,
xz,
}:
let
pname = "findutils";
version = "4.9.0";
src = fetchurl {
url = "mirror://gnu/findutils/findutils-${version}.tar.xz";
hash = "sha256-or+4wJ1DZ3DtxZ9Q+kg+eFsWGjt7nVR1c8sIBl/UYv4=";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnused
gnugrep
gawk
gnutar
xz
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/find --version
mkdir $out
'';
meta = with lib; {
description = "GNU Find Utilities, the basic directory searching utilities of the GNU operating system";
homepage = "https://www.gnu.org/software/findutils";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
};
}
''
# Unpack
cp ${src} findutils.tar.xz
unxz findutils.tar.xz
tar xf findutils.tar
rm findutils.tar
cd findutils-${version}
# Patch
# configure fails to accurately detect PATH_MAX support
sed -i 's/chdir_long/chdir/' gl/lib/save-cwd.c
# Configure
export CC="tcc -B ${tinycc.libs}/lib"
export AR="tcc -ar"
export LD=tcc
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config}
# Build
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
''

View File

@@ -0,0 +1,11 @@
{ lib }:
{
meta = with lib; {
description = "GNU implementation of the Awk programming language";
homepage = "https://www.gnu.org/software/gawk";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
};
}

View File

@@ -0,0 +1,65 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
tinycc,
gnumake,
gnugrep,
gnused,
gnutar,
gzip,
bootGawk,
}:
let
inherit (import ./common.nix { inherit lib; }) meta;
pname = "gawk";
version = "5.2.2";
src = fetchurl {
url = "mirror://gnu/gawk/gawk-${version}.tar.gz";
hash = "sha256-lFrvfM/xAfILIqEIArwAXplKsrjqPnJMwaGXxi9B9lA=";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version meta;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnused
gnugrep
gnutar
gzip
bootGawk
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/awk --version
mkdir $out
'';
}
''
# Unpack
tar xzf ${src}
cd gawk-${version}
# Configure
export CC="tcc -B ${tinycc.libs}/lib"
export AR="tcc -ar"
export LD=tcc
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config}
# Build
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
''

View File

@@ -0,0 +1,74 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
tinycc,
gnumake,
gnupatch,
gnused,
gnugrep,
}:
let
inherit (import ./common.nix { inherit lib; }) meta;
pname = "gawk-mes";
# >=3.1.x is incompatible with mes-libc
version = "3.0.6";
src = fetchurl {
url = "mirror://gnu/gawk/gawk-${version}.tar.gz";
sha256 = "1z4bibjm7ldvjwq3hmyifyb429rs2d9bdwkvs0r171vv1khpdwmb";
};
patches = [
# for reproducibility don't generate date stamp
./no-stamp.patch
];
in
bash.runCommand "${pname}-${version}"
{
inherit pname version meta;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnupatch
gnused
gnugrep
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/awk --version
mkdir $out
'';
}
''
# Unpack
ungz --file ${src} --output gawk.tar
untar --file gawk.tar
rm gawk.tar
cd gawk-${version}
# Patch
${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches}
# Configure
export CC="tcc -B ${tinycc.libs}/lib"
export ac_cv_func_getpgrp_void=yes
export ac_cv_func_tzset=yes
bash ./configure \
--build=${buildPlatform.config} \
--host=${hostPlatform.config} \
--disable-nls \
--prefix=$out
# Build
make gawk
# Install
install -D gawk $out/bin/gawk
ln -s gawk $out/bin/awk
''

View File

@@ -0,0 +1,10 @@
--- configure
+++ configure
@@ -3676,7 +3676,6 @@ cat >> $CONFIG_STATUS <<EOF
EOF
cat >> $CONFIG_STATUS <<\EOF
-date > stamp-h
exit 0
EOF
chmod +x $CONFIG_STATUS

View File

@@ -0,0 +1,151 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
coreutils,
gcc,
musl,
binutils,
gnumake,
gnupatch,
gnused,
gnugrep,
gawk,
diffutils,
findutils,
gnutar,
gzip,
}:
let
pname = "gcc-cxx";
version = "4.6.4";
src = fetchurl {
url = "mirror://gnu/gcc/gcc-${version}/gcc-core-${version}.tar.gz";
sha256 = "173kdb188qg79pcz073cj9967rs2vzanyjdjyxy9v0xb0p5sad75";
};
ccSrc = fetchurl {
url = "mirror://gnu/gcc/gcc-${version}/gcc-g++-${version}.tar.gz";
sha256 = "1fqqk5zkmdg4vmqzdmip9i42q6b82i3f6yc0n86n9021cr7ms2k9";
};
gmpVersion = "4.3.2";
gmp = fetchurl {
url = "mirror://gnu/gmp/gmp-${gmpVersion}.tar.gz";
sha256 = "15rwq54fi3s11izas6g985y9jklm3xprfsmym3v1g6xr84bavqvv";
};
mpfrVersion = "2.4.2";
mpfr = fetchurl {
url = "mirror://gnu/mpfr/mpfr-${mpfrVersion}.tar.gz";
sha256 = "0dxn4904dra50xa22hi047lj8kkpr41d6vb9sd4grca880c7wv94";
};
mpcVersion = "1.0.3";
mpc = fetchurl {
url = "mirror://gnu/mpc/mpc-${mpcVersion}.tar.gz";
sha256 = "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1";
};
patches = [
# Remove hardcoded NATIVE_SYSTEM_HEADER_DIR
./no-system-headers.patch
];
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
gcc
binutils
gnumake
gnupatch
gnused
gnugrep
gawk
diffutils
findutils
gnutar
gzip
];
passthru.tests.hello-world =
result:
bash.runCommand "${pname}-simple-program-${version}"
{
nativeBuildInputs = [
binutils
musl
result
];
}
''
cat <<EOF >> test.c
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
EOF
musl-gcc -o test test.c
./test
mkdir $out
'';
meta = with lib; {
description = "GNU Compiler Collection, version ${version}";
homepage = "https://gcc.gnu.org";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
mainProgram = "gcc";
};
}
''
# Unpack
tar xzf ${src}
tar xzf ${ccSrc}
tar xzf ${gmp}
tar xzf ${mpfr}
tar xzf ${mpc}
cd gcc-${version}
ln -s ../gmp-${gmpVersion} gmp
ln -s ../mpfr-${mpfrVersion} mpfr
ln -s ../mpc-${mpcVersion} mpc
# Patch
${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches}
# doesn't recognise musl
sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host
# Configure
export CC="gcc -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
export C_INCLUDE_PATH="${musl}/include"
export CPLUS_INCLUDE_PATH="$C_INCLUDE_PATH"
export LIBRARY_PATH="${musl}/lib"
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config} \
--with-native-system-header-dir=${musl}/include \
--with-build-sysroot=${musl} \
--enable-languages=c,c++ \
--disable-bootstrap \
--disable-libmudflap \
--disable-libstdcxx-pch \
--disable-lto \
--disable-multilib
# Build
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
''

View File

@@ -0,0 +1,150 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
tinycc,
binutils,
gnumake,
gnupatch,
gnused,
gnugrep,
gawk,
diffutils,
findutils,
gnutar,
gzip,
}:
let
pname = "gcc";
version = "4.6.4";
src = fetchurl {
url = "mirror://gnu/gcc/gcc-${version}/gcc-core-${version}.tar.gz";
sha256 = "173kdb188qg79pcz073cj9967rs2vzanyjdjyxy9v0xb0p5sad75";
};
ccSrc = fetchurl {
url = "mirror://gnu/gcc/gcc-${version}/gcc-g++-${version}.tar.gz";
sha256 = "1fqqk5zkmdg4vmqzdmip9i42q6b82i3f6yc0n86n9021cr7ms2k9";
};
gmpVersion = "4.3.2";
gmp = fetchurl {
url = "mirror://gnu/gmp/gmp-${gmpVersion}.tar.gz";
sha256 = "15rwq54fi3s11izas6g985y9jklm3xprfsmym3v1g6xr84bavqvv";
};
mpfrVersion = "2.4.2";
mpfr = fetchurl {
url = "mirror://gnu/mpfr/mpfr-${mpfrVersion}.tar.gz";
sha256 = "0dxn4904dra50xa22hi047lj8kkpr41d6vb9sd4grca880c7wv94";
};
mpcVersion = "1.0.3";
mpc = fetchurl {
url = "mirror://gnu/mpc/mpc-${mpcVersion}.tar.gz";
sha256 = "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1";
};
patches = [
# Remove hardcoded NATIVE_SYSTEM_HEADER_DIR
./no-system-headers.patch
];
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
binutils
gnumake
gnupatch
gnused
gnugrep
gawk
diffutils
findutils
gnutar
gzip
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/gcc --version
mkdir $out
'';
meta = with lib; {
description = "GNU Compiler Collection, version ${version}";
homepage = "https://gcc.gnu.org";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
mainProgram = "gcc";
};
}
''
# Unpack
tar xzf ${src}
tar xzf ${ccSrc}
tar xzf ${gmp}
tar xzf ${mpfr}
tar xzf ${mpc}
cd gcc-${version}
ln -s ../gmp-${gmpVersion} gmp
ln -s ../mpfr-${mpfrVersion} mpfr
ln -s ../mpc-${mpcVersion} mpc
# Patch
${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches}
# Configure
export CC="tcc -B ${tinycc.libs}/lib"
export C_INCLUDE_PATH="${tinycc.libs}/include:$(pwd)/mpfr/src"
export CPLUS_INCLUDE_PATH="$C_INCLUDE_PATH"
# Avoid "Link tests are not allowed after GCC_NO_EXECUTABLES"
export lt_cv_shlibpath_overrides_runpath=yes
export ac_cv_func_memcpy=yes
export ac_cv_func_strerror=yes
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config} \
--with-native-system-header-dir=${tinycc.libs}/include \
--with-build-sysroot=${tinycc.libs}/include \
--disable-bootstrap \
--disable-decimal-float \
--disable-libatomic \
--disable-libcilkrts \
--disable-libgomp \
--disable-libitm \
--disable-libmudflap \
--disable-libquadmath \
--disable-libsanitizer \
--disable-libssp \
--disable-libvtv \
--disable-lto \
--disable-lto-plugin \
--disable-multilib \
--disable-plugin \
--disable-threads \
--enable-languages=c \
--enable-static \
--disable-shared \
--enable-threads=single \
--disable-libstdcxx-pch \
--disable-build-with-cxx
# Build
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
''

View File

@@ -0,0 +1,152 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
coreutils,
gcc,
musl,
binutils,
gnumake,
gnused,
gnugrep,
gawk,
diffutils,
findutils,
gnutar,
gzip,
bzip2,
xz,
}:
let
pname = "gcc";
version = "8.5.0";
src = fetchurl {
url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz";
hash = "sha256-0wiEGlEbuDCmEAOXsAQtskzhH2Qtq26m7kSELlMl7VA=";
};
# last version to compile with gcc 4.6
gmpVersion = "6.2.1";
gmp = fetchurl {
url = "mirror://gnu/gmp/gmp-${gmpVersion}.tar.xz";
hash = "sha256-/UgpkSzd0S+EGBw0Ucx1K+IkZD6H+sSXtp7d2txJtPI=";
};
mpfrVersion = "4.2.1";
mpfr = fetchurl {
url = "mirror://gnu/mpfr/mpfr-${mpfrVersion}.tar.xz";
hash = "sha256-J3gHNTpnJpeJlpRa8T5Sgp46vXqaW3+yeTiU4Y8fy7I=";
};
mpcVersion = "1.3.1";
mpc = fetchurl {
url = "mirror://gnu/mpc/mpc-${mpcVersion}.tar.gz";
hash = "sha256-q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg=";
};
islVersion = "0.24";
isl = fetchurl {
url = "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${islVersion}.tar.bz2";
hash = "sha256-/PeN2WVsEOuM+fvV9ZoLawE4YgX+GTSzsoegoYmBRcA=";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
gcc
binutils
gnumake
gnused
gnugrep
gawk
diffutils
findutils
gnutar
gzip
bzip2
xz
];
passthru.tests.hello-world =
result:
bash.runCommand "${pname}-simple-program-${version}"
{
nativeBuildInputs = [
binutils
musl
result
];
}
''
cat <<EOF >> test.c
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
EOF
musl-gcc -o test test.c
./test
mkdir $out
'';
meta = with lib; {
description = "GNU Compiler Collection, version ${version}";
homepage = "https://gcc.gnu.org";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
mainProgram = "gcc";
};
}
''
# Unpack
tar xf ${src}
tar xf ${gmp}
tar xf ${mpfr}
tar xf ${mpc}
tar xf ${isl}
cd gcc-${version}
ln -s ../gmp-${gmpVersion} gmp
ln -s ../mpfr-${mpfrVersion} mpfr
ln -s ../mpc-${mpcVersion} mpc
ln -s ../isl-${islVersion} isl
# Patch
# doesn't recognise musl
sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host
# Configure
export CC="gcc -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
export CXX="g++ -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
export C_INCLUDE_PATH="${musl}/include"
export CPLUS_INCLUDE_PATH="$C_INCLUDE_PATH"
export LIBRARY_PATH="${musl}/lib"
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config} \
--with-native-system-header-dir=/include \
--with-sysroot=${musl} \
--enable-languages=c,c++ \
--disable-bootstrap \
--disable-libmpx \
--disable-libsanitizer \
--disable-lto \
--disable-multilib \
--disable-plugin
# Build
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install-strip
''

View File

@@ -0,0 +1,148 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
coreutils,
gcc,
musl,
binutils,
gnumake,
gnused,
gnugrep,
gawk,
diffutils,
findutils,
gnutar,
gzip,
bzip2,
xz,
}:
let
pname = "gcc";
version = "13.2.0";
src = fetchurl {
url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz";
hash = "sha256-4nXnZEKmBnNBon8Exca4PYYTFEAEwEE1KIY9xrXHQ9o=";
};
gmpVersion = "6.3.0";
gmp = fetchurl {
url = "mirror://gnu/gmp/gmp-${gmpVersion}.tar.xz";
hash = "sha256-o8K4AgG4nmhhb0rTC8Zq7kknw85Q4zkpyoGdXENTiJg=";
};
mpfrVersion = "4.2.1";
mpfr = fetchurl {
url = "mirror://gnu/mpfr/mpfr-${mpfrVersion}.tar.xz";
hash = "sha256-J3gHNTpnJpeJlpRa8T5Sgp46vXqaW3+yeTiU4Y8fy7I=";
};
mpcVersion = "1.3.1";
mpc = fetchurl {
url = "mirror://gnu/mpc/mpc-${mpcVersion}.tar.gz";
hash = "sha256-q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg=";
};
islVersion = "0.24";
isl = fetchurl {
url = "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${islVersion}.tar.bz2";
hash = "sha256-/PeN2WVsEOuM+fvV9ZoLawE4YgX+GTSzsoegoYmBRcA=";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
gcc
binutils
gnumake
gnused
gnugrep
gawk
diffutils
findutils
gnutar
gzip
bzip2
xz
];
passthru.tests.hello-world =
result:
bash.runCommand "${pname}-simple-program-${version}"
{
nativeBuildInputs = [
binutils
musl
result
];
}
''
cat <<EOF >> test.c
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
EOF
musl-gcc -o test test.c
./test
mkdir $out
'';
meta = with lib; {
description = "GNU Compiler Collection, version ${version}";
homepage = "https://gcc.gnu.org";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
mainProgram = "gcc";
};
}
''
# Unpack
tar xf ${src}
tar xf ${gmp}
tar xf ${mpfr}
tar xf ${mpc}
tar xf ${isl}
cd gcc-${version}
ln -s ../gmp-${gmpVersion} gmp
ln -s ../mpfr-${mpfrVersion} mpfr
ln -s ../mpc-${mpcVersion} mpc
ln -s ../isl-${islVersion} isl
# Patch
# force musl even if host triple is gnu
sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host
# Configure
export CC="gcc -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
export CXX="g++ -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
export LIBRARY_PATH="${musl}/lib"
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config} \
--with-native-system-header-dir=/include \
--with-sysroot=${musl} \
--enable-languages=c,c++ \
--disable-bootstrap \
--disable-libsanitizer \
--disable-lto \
--disable-multilib \
--disable-plugin
# Build
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install-strip
''

View File

@@ -0,0 +1,11 @@
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -440,7 +440,7 @@ LINKER_PLUGIN_API_H = $(srcdir)/../include/plugin-api.h
LTO_SYMTAB_H = $(srcdir)/../include/lto-symtab.h
# Default native SYSTEM_HEADER_DIR, to be overridden by targets.
-NATIVE_SYSTEM_HEADER_DIR = /usr/include
+# NATIVE_SYSTEM_HEADER_DIR = /usr/include
# Default cross SYSTEM_HEADER_DIR, to be overridden by targets.
CROSS_SYSTEM_HEADER_DIR = @CROSS_SYSTEM_HEADER_DIR@

View File

@@ -0,0 +1,64 @@
{
lib,
fetchurl,
bash,
tinycc,
gnumake,
}:
let
pname = "gnugrep";
version = "2.4";
src = fetchurl {
url = "mirror://gnu/grep/grep-${version}.tar.gz";
sha256 = "05iayw5sfclc476vpviz67hdy03na0pz2kb5csa50232nfx34853";
};
# Thanks to the live-bootstrap project!
# See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/grep-2.4
makefile = fetchurl {
url = "https://github.com/fosslinux/live-bootstrap/raw/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/grep-2.4/mk/main.mk";
sha256 = "08an9ljlqry3p15w28hahm6swnd3jxizsd2188przvvsj093j91k";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumake
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/grep --version
mkdir ''${out}
'';
meta = with lib; {
description = "GNU implementation of the Unix grep command";
homepage = "https://www.gnu.org/software/grep";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
mainProgram = "grep";
platforms = platforms.unix;
};
}
''
# Unpack
ungz --file ${src} --output grep.tar
untar --file grep.tar
rm grep.tar
cd grep-${version}
# Configure
cp ${makefile} Makefile
# Build
make CC="tcc -B ${tinycc.libs}/lib"
# Install
make install PREFIX=$out
''

View File

@@ -0,0 +1,35 @@
From e00a5257a6ca5fedbf68b09eee7df3502971a057 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
Date: Sat, 24 Apr 2021 10:11:40 +0200
Subject: [PATCH 1/2] No impure bin sh
default_shell is used to populuate default shell used to execute jobs.
Unless SHELL is set to a different value this would be /bin/sh.
Our stdenv provides sh in form of bash anyway. Having this value not
hard-coded has some advantages:
- It would ensure that on all systems it uses sh from its PATH rather
than /bin/sh, which helps as different systems might have different
shells there (bash vs. dash)
- In the past I had issues with LD_PRELOAD with BEAR, where /bin/sh
used a different glibc than BEAR which came from my development shell.
---
src/job.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/job.c b/src/job.c
index ae1f18b..6b4ddb3 100644
--- a/src/job.c
+++ b/src/job.c
@@ -77,7 +77,7 @@ char * vms_strsignal (int status);
#else
-const char *default_shell = "/bin/sh";
+const char *default_shell = "sh";
int batch_mode_shell = 0;
#endif
--
2.31.1

View File

@@ -0,0 +1,40 @@
From 795d63d3c8b5c0dbb7e544954f75507b371b7228 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
Date: Sat, 24 Apr 2021 10:20:16 +0200
Subject: [PATCH 2/2] remove impure dirs
---
src/read.c | 3 ---
src/remake.c | 2 --
2 files changed, 5 deletions(-)
diff --git a/src/read.c b/src/read.c
index fa197fb..defacfb 100644
--- a/src/read.c
+++ b/src/read.c
@@ -109,9 +109,6 @@ static const char *default_include_directories[] =
#endif
INCLUDEDIR,
#ifndef _AMIGA
- "/usr/gnu/include",
- "/usr/local/include",
- "/usr/include",
#endif
0
};
diff --git a/src/remake.c b/src/remake.c
index fb237c5..94bff7d 100644
--- a/src/remake.c
+++ b/src/remake.c
@@ -1601,8 +1601,6 @@ library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
static const char *dirs[] =
{
#ifndef _AMIGA
- "/lib",
- "/usr/lib",
#endif
#if defined(WINDOWS32) && !defined(LIBDIR)
/*
--
2.31.1

View File

@@ -0,0 +1,58 @@
diff --git a/src/dir.c b/src/dir.c
index 3e94b98..cfaa6a2 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -1331,10 +1331,9 @@ local_stat (const char *path, struct stat *buf)
/* Similarly for lstat. */
#if !defined(lstat) && !defined(WINDOWS32) || defined(VMS)
-# ifndef VMS
-# ifndef HAVE_SYS_STAT_H
+// mes-libc implements but does not declare lstat
+# if (!defined(VMS) && !defined(HAVE_SYS_STAT_H)) || defined(__TINYC__)
int lstat (const char *path, struct stat *sbuf);
-# endif
# else
/* We are done with the fake lstat. Go back to the real lstat */
# ifdef lstat
diff --git a/src/job.c b/src/job.c
index ea88561..8388a82 100644
--- a/src/job.c
+++ b/src/job.c
@@ -2052,7 +2052,8 @@ job_next_command (struct child *child)
static int
load_too_high (void)
{
-#if defined(__MSDOS__) || defined(VMS) || defined(_AMIGA) || defined(__riscos__)
+// mes-libc does not support getloadavg
+#if defined(__MSDOS__) || defined(VMS) || defined(_AMIGA) || defined(__riscos__) || defined (__TINYC__)
return 1;
#else
static double last_sec;
diff --git a/src/main.c b/src/main.c
index a9d3a64..664d40f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2770,7 +2770,7 @@ main (int argc, char **argv, char **envp)
char *b = alloca (40);
sprintf (b, "MAKE_RESTARTS=%s%u",
OUTPUT_IS_TRACED () ? "-" : "", restarts);
- putenv (b);
+ // mes-libc does not support putenv
}
fflush (stdout);
diff --git a/src/misc.c b/src/misc.c
index eb14f40..bffca82 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -653,7 +653,8 @@ get_tmppath ()
# ifdef HAVE_MKTEMP
path = get_tmptemplate ();
- if (*mktemp (path) == '\0')
+ // tinycc: "src/misc.c:656: error: pointer expected"
+ if (!strcmp(mktemp (path), ""))
{
OSS (error, NILF,
_("cannot generate temp path from %s: %s"), path, strerror (errno));

View File

@@ -0,0 +1,204 @@
{
lib,
fetchurl,
kaem,
tinycc,
gnupatch,
}:
let
pname = "gnumake";
version = "4.4.1";
src = fetchurl {
url = "mirror://gnu/make/make-${version}.tar.gz";
sha256 = "1cwgcmwdn7gqn5da2ia91gkyiqs9birr10sy5ykpkaxzcwfzn5nx";
};
patches = [
# Replaces /bin/sh with sh, see patch file for reasoning
./0001-No-impure-bin-sh.patch
# Purity: don't look for library dependencies (of the form `-lfoo') in /lib
# and /usr/lib. It's a stupid feature anyway. Likewise, when searching for
# included Makefiles, don't look in /usr/include and friends.
./0002-remove-impure-dirs.patch
# Fixes for tinycc. See comments in patch file for reasoning
./0003-tinycc-support.patch
];
CFLAGS = [
"-I./src"
"-I./lib"
"-DHAVE_CONFIG_H"
"-DMAKE_MAINTAINER_MODE"
"-DLIBDIR=\\\"${placeholder "out"}/lib\\\""
"-DLOCALEDIR=\\\"/fake-locale\\\""
"-DPOSIX=1"
# mes-libc doesn't implement osync_* methods
"-DNO_OUTPUT_SYNC=1"
# mes-libc doesn't define O_TMPFILE
"-DO_TMPFILE=020000000"
]
++ config;
/*
Maintenance notes:
Generated by
./configure \
--build i686-pc-linux-gnu \
--host i686-pc-linux-gnu \
CC="${tinycc.compiler}/bin/tcc -B ${tinycc.libs}/lib" \
ac_cv_func_dup=no
- `ac_cv_func_dup` disabled as mes-libc doesn't implement tmpfile()
The output src/config.h was then manually filtered, removing definitions that
didn't have uses in the source code
*/
config = [
"-DFILE_TIMESTAMP_HI_RES=0"
"-DHAVE_ALLOCA"
"-DHAVE_ALLOCA_H"
"-DHAVE_ATEXIT"
"-DHAVE_DECL_BSD_SIGNAL=0"
"-DHAVE_DECL_GETLOADAVG=0"
"-DHAVE_DECL_SYS_SIGLIST=0"
"-DHAVE_DECL__SYS_SIGLIST=0"
"-DHAVE_DECL___SYS_SIGLIST=0"
"-DHAVE_DIRENT_H"
"-DHAVE_DUP2"
"-DHAVE_FCNTL_H"
"-DHAVE_FDOPEN"
"-DHAVE_GETCWD"
"-DHAVE_GETTIMEOFDAY"
"-DHAVE_INTTYPES_H"
"-DHAVE_ISATTY"
"-DHAVE_LIMITS_H"
"-DHAVE_LOCALE_H"
"-DHAVE_MEMORY_H"
"-DHAVE_MKTEMP"
"-DHAVE_SA_RESTART"
"-DHAVE_SETVBUF"
"-DHAVE_SIGACTION"
"-DHAVE_SIGSETMASK"
"-DHAVE_STDINT_H"
"-DHAVE_STDLIB_H"
"-DHAVE_STRDUP"
"-DHAVE_STRERROR"
"-DHAVE_STRINGS_H"
"-DHAVE_STRING_H"
"-DHAVE_STRTOLL"
"-DHAVE_SYS_FILE_H"
"-DHAVE_SYS_PARAM_H"
"-DHAVE_SYS_RESOURCE_H"
"-DHAVE_SYS_SELECT_H"
"-DHAVE_SYS_STAT_H"
"-DHAVE_SYS_TIMEB_H"
"-DHAVE_SYS_TIME_H"
"-DHAVE_SYS_WAIT_H"
"-DHAVE_TTYNAME"
"-DHAVE_UMASK"
"-DHAVE_UNISTD_H"
"-DHAVE_WAITPID"
"-DMAKE_JOBSERVER"
"-DMAKE_SYMLINKS"
"-DPATH_SEPARATOR_CHAR=':'"
"-DSCCS_GET=\\\"get\\\""
"-DSTDC_HEADERS"
"-Dsig_atomic_t=int"
"-Dvfork=fork"
];
# Maintenance note: list of source files derived from Basic.mk
make_SOURCES = [
"src/ar.c"
"src/arscan.c"
"src/commands.c"
"src/default.c"
"src/dir.c"
"src/expand.c"
"src/file.c"
"src/function.c"
"src/getopt.c"
"src/getopt1.c"
"src/guile.c"
"src/hash.c"
"src/implicit.c"
"src/job.c"
"src/load.c"
"src/loadapi.c"
"src/main.c"
"src/misc.c"
"src/output.c"
"src/read.c"
"src/remake.c"
"src/rule.c"
"src/shuffle.c"
"src/signame.c"
"src/strcache.c"
"src/variable.c"
"src/version.c"
"src/vpath.c"
];
glob_SOURCES = [
"lib/fnmatch.c"
"lib/glob.c"
];
remote_SOURCES = [ "src/remote-stub.c" ];
sources =
make_SOURCES
++ glob_SOURCES
++ remote_SOURCES
++ [
"src/posixos.c"
];
objects = map (x: lib.replaceStrings [ ".c" ] [ ".o" ] (baseNameOf x)) sources;
in
kaem.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnupatch
];
meta = with lib; {
description = "Tool to control the generation of non-source files from sources";
homepage = "https://www.gnu.org/software/make";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
mainProgram = "make";
platforms = platforms.unix;
};
}
''
# Unpack
ungz --file ${src} --output make.tar
untar --file make.tar
rm make.tar
cd make-${version}
# Patch
${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches}
# Configure
catm src/config.h src/mkconfig.h src/mkcustom.h
cp lib/glob.in.h lib/glob.h
cp lib/fnmatch.in.h lib/fnmatch.h
# Compile
alias CC="tcc -B ${tinycc.libs}/lib ${lib.concatStringsSep " " CFLAGS}"
${lib.concatMapStringsSep "\n" (f: "CC -c ${f}") sources}
# Link
CC -o make ${lib.concatStringsSep " " objects}
# Check
./make --version
# Install
mkdir -p ''${out}/bin
cp ./make ''${out}/bin
chmod 555 ''${out}/bin/make
''

View File

@@ -0,0 +1,86 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
tinycc,
gnumakeBoot,
gnupatch,
gnused,
gnugrep,
gawk,
gnutar,
gzip,
}:
let
pname = "gnumake-musl";
version = "4.4.1";
src = fetchurl {
url = "mirror://gnu/make/make-${version}.tar.gz";
hash = "sha256-3Rb7HWe/q3mnL16DkHNcSePo5wtJRaFasfgd23hlj7M=";
};
patches = [
# Replaces /bin/sh with sh, see patch file for reasoning
./0001-No-impure-bin-sh.patch
# Purity: don't look for library dependencies (of the form `-lfoo') in /lib
# and /usr/lib. It's a stupid feature anyway. Likewise, when searching for
# included Makefiles, don't look in /usr/include and friends.
./0002-remove-impure-dirs.patch
];
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumakeBoot
gnupatch
gnused
gnugrep
gawk
gnutar
gzip
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/make --version
mkdir $out
'';
meta = with lib; {
description = "Tool to control the generation of non-source files from sources";
homepage = "https://www.gnu.org/software/make";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
mainProgram = "make";
platforms = platforms.unix;
};
}
''
# Unpack
tar xzf ${src}
cd make-${version}
# Patch
${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches}
# Configure
export CC="tcc -B ${tinycc.libs}/lib"
export LD=tcc
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config}
# Build
make AR="tcc -ar"
# Install
make install
''

View File

@@ -0,0 +1,110 @@
{
lib,
fetchurl,
kaem,
tinycc,
}:
let
pname = "gnupatch";
# 2.6.x and later use features not implemented in mes-libc (eg. quotearg.h)
version = "2.5.9";
src = fetchurl {
url = "mirror://gnu/patch/patch-${version}.tar.gz";
sha256 = "12nv7jx3gxfp50y11nxzlnmqqrpicjggw6pcsq0wyavkkm3cddgc";
};
# Thanks to the live-bootstrap project!
# https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/patch-2.5.9/mk/main.mk
CFLAGS = [
"-I."
"-DHAVE_DECL_GETENV"
"-DHAVE_DECL_MALLOC"
"-DHAVE_DIRENT_H"
"-DHAVE_LIMITS_H"
"-DHAVE_GETEUID"
"-DHAVE_MKTEMP"
"-DPACKAGE_BUGREPORT="
"-Ded_PROGRAM=\\\"/nullop\\\""
"-Dmbstate_t=int" # When HAVE_MBRTOWC is not enabled uses of mbstate_t are always a no-op
"-DRETSIGTYPE=int"
"-DHAVE_MKDIR"
"-DHAVE_RMDIR"
"-DHAVE_FCNTL_H"
"-DPACKAGE_NAME=\\\"patch\\\""
"-DPACKAGE_VERSION=\\\"${version}\\\""
"-DHAVE_MALLOC"
"-DHAVE_REALLOC"
"-DSTDC_HEADERS"
"-DHAVE_STRING_H"
"-DHAVE_STDLIB_H"
];
# Maintenance note: List of sources from Makefile.in
SRCS = [
"addext.c"
"argmatch.c"
"backupfile.c"
"basename.c"
"dirname.c"
"getopt.c"
"getopt1.c"
"inp.c"
"maketime.c"
"partime.c"
"patch.c"
"pch.c"
"quote.c"
"quotearg.c"
"quotesys.c"
"util.c"
"version.c"
"xmalloc.c"
];
sources = SRCS ++ [
# mes-libc doesn't implement `error()`
"error.c"
];
objects = map (x: lib.replaceStrings [ ".c" ] [ ".o" ] (baseNameOf x)) sources;
in
kaem.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [ tinycc.compiler ];
meta = with lib; {
description = "GNU Patch, a program to apply differences to files";
homepage = "https://www.gnu.org/software/patch";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
mainProgram = "patch";
platforms = platforms.unix;
};
}
''
# Unpack
ungz --file ${src} --output patch.tar
untar --file patch.tar
rm patch.tar
cd patch-${version}
# Configure
catm config.h
# Build
alias CC="tcc -B ${tinycc.libs}/lib ${lib.concatStringsSep " " CFLAGS}"
${lib.concatMapStringsSep "\n" (f: "CC -c ${f}") sources}
# Link
CC -o patch ${lib.concatStringsSep " " objects}
# Check
./patch --version
# Install
mkdir -p ''${out}/bin
cp ./patch ''${out}/bin
chmod 555 ''${out}/bin/patch
''

View File

@@ -0,0 +1,12 @@
{ lib }:
{
meta = with lib; {
description = "GNU sed, a batch stream editor";
homepage = "https://www.gnu.org/software/sed";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
mainProgram = "sed";
platforms = platforms.unix;
};
}

View File

@@ -0,0 +1,67 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
gnumake,
tinycc,
gnused,
gnugrep,
gnutar,
gzip,
}:
let
inherit (import ./common.nix { inherit lib; }) meta;
pname = "gnused";
# last version that can be bootstrapped with our slightly buggy gnused-mes
version = "4.2";
src = fetchurl {
url = "mirror://gnu/sed/sed-${version}.tar.gz";
hash = "sha256-20XNY/0BDmUFN9ZdXfznaJplJ0UjZgbl5ceCk3Jn2YM=";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version meta;
nativeBuildInputs = [
gnumake
tinycc.compiler
gnused
gnugrep
gnutar
gzip
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/sed --version
mkdir ''${out}
'';
}
''
# Unpack
tar xzf ${src}
cd sed-${version}
# Configure
export CC="tcc -B ${tinycc.libs}/lib"
export LD=tcc
./configure \
--build=${buildPlatform.config} \
--host=${hostPlatform.config} \
--disable-shared \
--disable-nls \
--disable-dependency-tracking \
--prefix=$out
# Build
make AR="tcc -ar"
# Install
make install
''

View File

@@ -0,0 +1,63 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
gnumake,
tinycc,
}:
let
inherit (import ./common.nix { inherit lib; }) meta;
pname = "gnused-mes";
# last version that can be compiled with mes-libc
version = "4.0.9";
src = fetchurl {
url = "mirror://gnu/sed/sed-${version}.tar.gz";
sha256 = "0006gk1dw2582xsvgx6y6rzs9zw8b36rhafjwm288zqqji3qfrf3";
};
# Thanks to the live-bootstrap project!
# See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/sed-4.0.9/sed-4.0.9.kaem
makefile = fetchurl {
url = "https://github.com/fosslinux/live-bootstrap/raw/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/sed-4.0.9/mk/main.mk";
sha256 = "0w1f5ri0g5zla31m6l6xyzbqwdvandqfnzrsw90dd6ak126w3mya";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version meta;
nativeBuildInputs = [
gnumake
tinycc.compiler
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/sed --version
mkdir ''${out}
'';
}
''
# Unpack
ungz --file ${src} --output sed.tar
untar --file sed.tar
rm sed.tar
cd sed-${version}
# Configure
cp ${makefile} Makefile
catm config.h
# Build
make \
CC="tcc -B ${tinycc.libs}/lib" \
LIBC=mes
# Install
make install PREFIX=$out
''

View File

@@ -0,0 +1,75 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
gcc,
musl,
binutils,
gnumake,
gnused,
gnugrep,
gawk,
gzip,
gnutarBoot,
}:
let
pname = "gnutar";
version = "1.35";
src = fetchurl {
url = "mirror://gnu/tar/tar-${version}.tar.gz";
hash = "sha256-FNVeMgY+qVJuBX+/Nfyr1TN452l4fv95GcN1WwLStX4=";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
gcc
musl
binutils
gnumake
gnused
gnugrep
gawk
gzip
gnutarBoot
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/tar --version
mkdir $out
'';
meta = with lib; {
description = "GNU implementation of the `tar' archiver";
homepage = "https://www.gnu.org/software/tar";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
mainProgram = "tar";
platforms = platforms.unix;
};
}
''
# Unpack
tar xzf ${src}
cd tar-${version}
# Configure
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config} \
CC=musl-gcc
# Build
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
''

View File

@@ -0,0 +1,69 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
tinycc,
gnumake,
gnused,
gnugrep,
}:
let
pname = "gnutar";
# >= 1.13 is incompatible with mes-libc
version = "1.12";
src = fetchurl {
url = "mirror://gnu/tar/tar-${version}.tar.gz";
sha256 = "02m6gajm647n8l9a5bnld6fnbgdpyi4i3i83p7xcwv0kif47xhy6";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnused
gnugrep
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/tar --version
mkdir $out
'';
meta = with lib; {
description = "GNU implementation of the `tar' archiver";
homepage = "https://www.gnu.org/software/tar";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
mainProgram = "tar";
platforms = platforms.unix;
};
}
''
# Unpack
ungz --file ${src} --output tar.tar
untar --file tar.tar
rm tar.tar
cd tar-${version}
# Configure
export CC="tcc -B ${tinycc.libs}/lib"
bash ./configure \
--build=${buildPlatform.config} \
--host=${hostPlatform.config} \
--disable-nls \
--prefix=$out
# Build
make AR="tcc -ar"
# Install
make install
''

View File

@@ -0,0 +1,74 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
tinycc,
gnumake,
gnugrep,
gnused,
}:
let
# gnutar with musl preserves modify times, allowing make to not try
# rebuilding pregenerated files
pname = "gnutar-musl";
version = "1.12";
src = fetchurl {
url = "mirror://gnu/tar/tar-${version}.tar.gz";
hash = "sha256-xsN+iIsTbM76uQPFEUn0t71lnWnUrqISRfYQU6V6pgo=";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnused
gnugrep
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/tar --version
mkdir $out
'';
meta = with lib; {
description = "GNU implementation of the `tar' archiver";
homepage = "https://www.gnu.org/software/tar";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
mainProgram = "tar";
platforms = platforms.unix;
};
}
''
# Unpack
ungz --file ${src} --output tar.tar
untar --file tar.tar
rm tar.tar
cd tar-${version}
# Configure
export CC="tcc -B ${tinycc.libs}/lib"
export LD=tcc
export ac_cv_sizeof_unsigned_long=4
export ac_cv_sizeof_long_long=8
export ac_cv_header_netdb_h=no
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config} \
--disable-nls
# Build
make AR="tcc -ar"
# Install
make install
''

View File

@@ -0,0 +1,62 @@
{
lib,
fetchurl,
bash,
tinycc,
gnumake,
gnused,
gnugrep,
}:
let
pname = "gzip";
version = "1.2.4";
src = fetchurl {
url = "mirror://gnu/gzip/gzip-${version}.tar.gz";
sha256 = "0ryr5b00qz3xcdcv03qwjdfji8pasp0007ay3ppmk71wl8c1i90w";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnused
gnugrep
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/gzip --version
mkdir $out
'';
meta = with lib; {
description = "GNU zip compression program";
homepage = "https://www.gnu.org/software/gzip";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
};
}
''
# Unpack
ungz --file ${src} --output gzip.tar
untar --file gzip.tar
rm gzip.tar
cd gzip-${version}
# Configure
export CC="tcc -B ${tinycc.libs}/lib -Dstrlwr=unused"
bash ./configure --prefix=$out
# Build
make
# Install
mkdir $out
make install
''

View File

@@ -0,0 +1,104 @@
{
lib,
fetchurl,
kaem,
tinycc,
gnumake,
gnupatch,
coreutils,
}:
let
pname = "heirloom-devtools";
version = "070527";
src = fetchurl {
url = "mirror://sourceforge/heirloom/heirloom-devtools/heirloom-devtools-${version}.tar.bz2";
sha256 = "9f233d8b78e4351fe9dd2d50d83958a0e5af36f54e9818521458a08e058691ba";
};
# Thanks to the live-bootstrap project!
# See https://github.com/fosslinux/live-bootstrap/blob/d918b984ad6fe4fc7680f3be060fd82f8c9fddd9/sysa/heirloom-devtools-070527/heirloom-devtools-070527.kaem
liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/d918b984ad6fe4fc7680f3be060fd82f8c9fddd9/sysa/heirloom-devtools-070527";
patches = [
# Remove all kinds of wchar support. Mes Libc does not support wchar in any form
(fetchurl {
url = "${liveBootstrap}/patches/yacc_remove_wchar.patch";
sha256 = "0wgiz02bb7xzjy2gnbjp8y31qy6rc4b29v01zi32zh9lw54j68hc";
})
# Similarly to yacc, remove wchar. See yacc patch for further information
(fetchurl {
url = "${liveBootstrap}/patches/lex_remove_wchar.patch";
sha256 = "168dfngi51ljjqgd55wbvmffaq61gk48gak50ymnl1br92qkp4zh";
})
];
in
kaem.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnupatch
coreutils
];
meta = with lib; {
description = "Portable yacc and lex derived from OpenSolaris";
homepage = "https://heirloom.sourceforge.net/devtools.html";
license = with licenses; [
cddl
bsdOriginalUC
caldera
];
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
};
}
''
# Unpack
unbz2 --file ${src} --output heirloom-devtools.tar
untar --file heirloom-devtools.tar
rm heirloom-devtools.tar
build=''${NIX_BUILD_TOP}/heirloom-devtools-${version}
cd ''${build}
# Patch
${lib.concatLines (map (f: "patch -Np0 -i ${f}") patches)}
# Build yacc
cd yacc
make -f Makefile.mk \
CC="tcc -B ${tinycc.libs}/lib" \
AR="tcc -ar" \
CFLAGS="-DMAXPATHLEN=4096 -DEILSEQ=84 -DMB_LEN_MAX=100" \
LDFLAGS="-lgetopt" \
RANLIB=true \
LIBDIR=''${out}/lib
# Install yacc
install -D yacc ''${out}/bin/yacc
install -Dm 444 liby.a ''${out}/lib/liby.a
install -Dm 444 yaccpar ''${out}/lib/yaccpar
# Make yacc available to lex
PATH="''${out}/bin:''${PATH}"
# Build lex
cd ../lex
make -f Makefile.mk \
CC="tcc -B ${tinycc.libs}/lib" \
AR="tcc -ar" \
CFLAGS="-DEILSEQ=84 -DMB_LEN_MAX=100" \
LDFLAGS="-lgetopt" \
RANLIB=true \
LIBDIR=''${out}/lib
# Install lex
install -D lex ''${out}/bin/lex
install -Dm 444 ncform ''${out}/lib/lex/ncform
install -Dm 444 nceucform ''${out}/lib/lex/nceucform
install -Dm 444 nrform ''${out}/lib/lex/nrform
install -Dm 444 libl.a ''${out}/lib/libl.a
''

View File

@@ -0,0 +1,84 @@
--- cp/cp.c
+++ cp/cp.c
@@ -42,8 +42,6 @@ static const char sccsid[] USED = "@(#)cp.sl 1.84 (gritter) 3/4/06";
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/un.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <fcntl.h>
@@ -427,6 +425,7 @@ fdcopy(const char *src, const struct stat *ssp, const int sfd,
#endif
#ifdef __linux__
+#ifdef O_DIRECT
if (!bflag && !Dflag && ssp->st_size > 0) {
long long sent;
@@ -436,6 +435,7 @@ fdcopy(const char *src, const struct stat *ssp, const int sfd,
if (sent < 0)
goto err;
}
+#endif
#endif /* __linux__ */
if (pagesize == 0)
if ((pagesize = 4096) < 0)
@@ -702,37 +702,6 @@ symlinkcopy(const char *src, const struct stat *ssp,
}
}
-static void
-socketcopy(const char *src, const struct stat *ssp,
- const char *tgt, const struct stat *dsp)
-{
- int fd, addrsz;
- struct sockaddr_un addr;
- size_t len;
-
- if (do_unlink(tgt, dsp) != OKAY)
- return;
- len = strlen(tgt);
- memset(&addr, 0, sizeof addr);
- addr.sun_family = AF_UNIX;
- addrsz = sizeof addr - sizeof addr.sun_path + len;
- if ((len >= sizeof addr.sun_path ? errno = ENAMETOOLONG, fd = -1, 1 :
- (strncpy(addr.sun_path,tgt,sizeof addr.sun_path), 0)) ||
- (fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0 ||
- bind(fd, (struct sockaddr *)&addr, addrsz) < 0) {
- fprintf(stderr, "%s: cannot create socket %s\n%s: %s\n",
- progname, tgt,
- progname, strerror(errno));
- if (fd >= 0)
- close(fd);
- errcnt |= 01;
- return;
- }
- close(fd);
- if (pflag)
- permissions(tgt, ssp);
-}
-
static void
specialcopy(const char *src, const struct stat *ssp,
const char *tgt, const struct stat *dsp)
@@ -748,9 +717,6 @@ specialcopy(const char *src, const struct stat *ssp,
case S_IFLNK:
symlinkcopy(src, ssp, tgt, dsp);
break;
- case S_IFSOCK:
- socketcopy(src, ssp, tgt, dsp);
- break;
case S_IFDOOR:
ignoring("door", src);
break;
@@ -1043,7 +1009,7 @@ ln(const char *src, const char *tgt, struct stat *dsp, int level,
errcnt |= 01;
return;
}
-#if (defined (SUS) || defined (S42)) && (defined (__linux__) || defined (__sun))
+#if (defined (SUS) || defined (S42)) && (defined (__linux__) || defined (__sun)) && !defined (__TINYC__)
if (sflag == 0) {
char *rpbuf = alloca(PATH_MAX+1);
if (realpath(src, rpbuf) == NULL) {

View File

@@ -0,0 +1,133 @@
{
lib,
fetchurl,
bash,
tinycc,
gnumake,
gnupatch,
heirloom-devtools,
heirloom,
}:
let
pname = "heirloom";
version = "070715";
src = fetchurl {
url = "mirror://sourceforge/heirloom/heirloom/${version}/heirloom-${version}.tar.bz2";
sha256 = "sha256-6zP3C8wBmx0OCkHx11UtRcV6FicuThxIY07D5ESWow8=";
};
patches = [
# we pre-generate nawk's proctab.c as meslibc is not capable of running maketab
# during build time (insufficient sscanf support)
./proctab.patch
# disable utilities that don't build successfully
./disable-programs.patch
# "tcc -ar" doesn't support creating empty archives
./tcc-empty-ar.patch
# meslibc doesn't have separate libm
./dont-link-lm.patch
# meslibc's vprintf doesn't support %ll
./vprintf.patch
# meslibc doesn't support sysconf()
./sysconf.patch
# meslibc doesn't support locale
./strcoll.patch
# meslibc doesn't support termios.h
./termios.patch
# meslibc doesn't support utime.h
./utime.patch
# meslibc doesn't support langinfo.h
./langinfo.patch
# support building with meslibc
./meslibc-support.patch
# remove socket functionality as unsupported by meslibc
./cp-no-socket.patch
];
makeFlags = [
# mk.config build options
"CC='tcc -B ${tinycc.libs}/lib -include ${./stubs.h} -include ${./musl.h}'"
"AR='tcc -ar'"
"RANLIB=true"
"STRIP=true"
"SHELL=${bash}/bin/sh"
"POSIX_SHELL=${bash}/bin/sh"
"DEFBIN=/bin"
"SV3BIN=/5bin"
"S42BIN=/5bin/s42"
"SUSBIN=/bin"
"SU3BIN=/5bin/posix2001"
"UCBBIN=/ucb"
"CCSBIN=/ccs/bin"
"DEFLIB=/lib"
"DEFSBIN=/bin"
"MANDIR=/share/man"
"LCURS=" # disable ncurses
"USE_ZLIB=0" # disable zlib
"IWCHAR='-I../libwchar'"
"LWCHAR='-L../libwchar -lwchar'"
];
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnupatch
heirloom-devtools
];
passthru.sed = bash.runCommand "${pname}-sed-${version}" { } ''
install -D ${heirloom}/bin/sed $out/bin/sed
'';
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/banner Hello Heirloom
mkdir $out
'';
meta = with lib; {
description = "Heirloom Toolchest is a collection of standard Unix utilities";
homepage = "https://heirloom.sourceforge.net/tools.html";
license = with licenses; [
# All licenses according to LICENSE/
zlib
caldera
bsdOriginalUC
cddl
bsd3
gpl2Plus
lgpl21Plus
lpl-102
info-zip
];
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
};
}
''
# Unpack
unbz2 --file ${src} --output heirloom.tar
untar --file heirloom.tar
rm heirloom.tar
cd heirloom-${version}
# Patch
${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches}
cp ${./proctab.c} nawk/proctab.c
# Build
# These tools are required during later build steps
export PATH="$PATH:$PWD/ed:$PWD/nawk:$PWD/sed"
make ${lib.concatStringsSep " " makeFlags}
# Install
make install ROOT=$out ${lib.concatStringsSep " " makeFlags}
''

View File

@@ -0,0 +1,43 @@
--- makefile
+++ makefile
@@ -1,21 +1,24 @@
-SHELL = /bin/sh
+SHELL = sh
-SUBDIRS = build libwchar libcommon libuxre _install \
- banner basename bc bdiff bfs \
- cal calendar cat chmod chown \
- cksum cmp col comm copy cp cpio csplit cut \
- date dc dd deroff diff diff3 dircmp dirname df du \
+SUBDIRS = libwchar libcommon libuxre _install \
+ banner basename bdiff bfs \
+ cat chmod chown \
+ cksum cmp col comm copy cp csplit cut \
+ dc dirname \
echo ed env expand expr \
- factor file find fmt fmtmsg fold \
- getconf getopt grep groups hd head hostname id join \
- kill line listusers ln logins logname ls \
- mail man mesg mkdir mkfifo mknod more mvdir \
- nawk news nice nl nohup oawk od \
- paste pathchk pg pgrep pr printenv printf priocntl ps psrinfo pwd \
- random renice rm rmdir \
- sdiff sed setpgrp shl sleep sort spell split stty su sum sync \
- tabs tail tapecntl tar tcopy tee test time touch tr true tsort tty \
- ul uname uniq units users wc what who whoami whodo xargs yes
+ file fmt fold \
+ getopt grep hd head join \
+ kill line ln logname ls \
+ mesg mkdir mknod \
+ nl nohup od \
+ paste pathchk pgrep pr printenv printf pwd \
+ random rm rmdir \
+ sed sleep sort split sum \
+ tee test touch tr true tsort tty \
+ uniq units wc what whoami xargs yes
+
+# These depend on some coreutils that we need to build first
+SUBDIRS += bc nawk build
dummy: makefiles all

View File

@@ -0,0 +1,44 @@
--- csplit/Makefile.mk
+++ csplit/Makefile.mk
@@ -1,19 +1,19 @@
all: csplit csplit_sus csplit_su3
csplit: csplit.o
- $(LD) $(LDFLAGS) csplit.o $(LCOMMON) $(LWCHAR) $(LIBS) -lm -o csplit
+ $(LD) $(LDFLAGS) csplit.o $(LCOMMON) $(LWCHAR) $(LIBS) -o csplit
csplit.o: csplit.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(XO6FL) $(LARGEF) $(IWCHAR) $(ICOMMON) -c csplit.c
csplit_sus: csplit_sus.o
- $(LD) $(LDFLAGS) csplit_sus.o $(LUXRE) $(LCOMMON) $(LWCHAR) $(LIBS) -lm -o csplit_sus
+ $(LD) $(LDFLAGS) csplit_sus.o $(LUXRE) $(LCOMMON) $(LWCHAR) $(LIBS) -o csplit_sus
csplit_sus.o: csplit.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(XO6FL) $(LARGEF) $(IUXRE) $(IWCHAR) $(ICOMMON) -DSUS -c csplit.c -o csplit_sus.o
csplit_su3: csplit_su3.o
- $(LD) $(LDFLAGS) csplit_su3.o $(LUXRE) $(LCOMMON) $(LWCHAR) $(LIBS) -lm -o csplit_su3
+ $(LD) $(LDFLAGS) csplit_su3.o $(LUXRE) $(LCOMMON) $(LWCHAR) $(LIBS) -o csplit_su3
csplit_su3.o: csplit.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(XO6FL) $(LARGEF) $(IUXRE) $(IWCHAR) $(ICOMMON) -DSU3 -c csplit.c -o csplit_su3.o
--- nawk/Makefile.mk
+++ nawk/Makefile.mk
@@ -3,13 +3,13 @@ all: awk awk_sus awk_su3
OBJ = awk.lx.o b.o lib.o main.o parse.o proctab.o run.o tran.o
awk: awk.g.o $(OBJ) version.o
- $(LD) $(LDFLAGS) awk.g.o $(OBJ) version.o $(LUXRE) -lm $(LCOMMON) $(LWCHAR) $(LIBS) -o awk
+ $(LD) $(LDFLAGS) awk.g.o $(OBJ) version.o $(LUXRE) $(LCOMMON) $(LWCHAR) $(LIBS) -o awk
awk_sus: awk.g.o $(OBJ) version_sus.o
- $(LD) $(LDFLAGS) awk.g.o $(OBJ) version_sus.o $(LUXRE) -lm $(LCOMMON) $(LWCHAR) $(LIBS) -o awk_sus
+ $(LD) $(LDFLAGS) awk.g.o $(OBJ) version_sus.o $(LUXRE) $(LCOMMON) $(LWCHAR) $(LIBS) -o awk_sus
awk_su3: awk.g.2001.o $(OBJ) version_su3.o
- $(LD) $(LDFLAGS) awk.g.2001.o $(OBJ) version_su3.o $(LUXRE) -lm $(LCOMMON) $(LWCHAR) $(LIBS) -o awk_su3
+ $(LD) $(LDFLAGS) awk.g.2001.o $(OBJ) version_su3.o $(LUXRE) $(LCOMMON) $(LWCHAR) $(LIBS) -o awk_su3
awk.g.c: awk.g.y
$(YACC) -d awk.g.y

View File

@@ -0,0 +1,99 @@
--- nawk/main.c
+++ nawk/main.c
@@ -35,7 +35,6 @@
#include <errno.h>
#include <string.h>
#include <locale.h>
-#include <langinfo.h>
#include <libgen.h>
#define CMDCLASS ""/*"UX:"*/ /* Command classification */
--- sort/sort.c
+++ sort/sort.c
@@ -63,7 +63,6 @@ static const char sccsid[] USED = "@(#)sort.sl 1.37 (gritter) 5/29/05";
#include <locale.h>
#include <wchar.h>
#include <wctype.h>
-#include <langinfo.h>
#include <inttypes.h>
#include <errno.h>
@@ -287,18 +286,6 @@ main(int argc, char **argv)
else
chkblank();
compare = cmpf = ccoll ? mb_cur_max > 1 ? cmpm : cmpa : cmpl;
- setlocale(LC_NUMERIC, "");
- arg = nl_langinfo(RADIXCHAR);
- if (mb_cur_max > 1)
- next(radixchar, arg, i);
- else
- radixchar = *arg & 0377;
- arg = nl_langinfo(THOUSEP);
- if (mb_cur_max > 1)
- next(thousep, arg, i);
- else
- thousep = *arg & 0377;
- setlocale(LC_TIME, "");
fields = smalloc(NF * sizeof *fields);
copyproto();
eargv = argv;
@@ -1088,8 +1075,7 @@ cmp(const char *i, const char *j)
} else {
sa = elicpy(collba, pa, la, '\n', ignore, code);
sb = elicpy(collbb, pb, lb, '\n', ignore, code);
- n = fp->Mflg ? monthcmp(collba, collbb) :
- strcoll(collba, collbb);
+ n = strcmp(collba, collbb);
if (n)
return n > 0 ? -fp->rflg : fp->rflg;
pa = &pa[sa];
@@ -1570,49 +1556,6 @@ upcdup(const char *s)
return r;
}
-static const char *months[12];
-
-#define COPY_ABMON(m) months[m-1] = upcdup(nl_langinfo(ABMON_##m))
-
-static void
-fillmonths(void)
-{
- COPY_ABMON(1);
- COPY_ABMON(2);
- COPY_ABMON(3);
- COPY_ABMON(4);
- COPY_ABMON(5);
- COPY_ABMON(6);
- COPY_ABMON(7);
- COPY_ABMON(8);
- COPY_ABMON(9);
- COPY_ABMON(10);
- COPY_ABMON(11);
- COPY_ABMON(12);
-}
-
-static int
-monthcoll(const char *s)
-{
- int i;
- char u[MB_LEN_MAX*3+1];
-
- cpcu3(u, s);
- for (i = 0; i < 12; i++)
- if (strcmp(u, months[i]) == 0)
- return i;
- return 0;
-}
-
-
-static int
-monthcmp(const char *pa, const char *pb)
-{
- if (months[0] == NULL)
- fillmonths();
- return monthcoll(pa) - monthcoll(pb);
-}
-
/*
* isblank() consumes half of execution time (in skip()) with
* glibc 2.3.1. Check if it contains only space and tab, and

View File

@@ -0,0 +1,322 @@
--- _install/install_ucb.c
+++ _install/install_ucb.c
@@ -267,7 +267,7 @@ cp(const char *src, const char *tgt, struct stat *dsp)
if (check(src, tgt, dsp, &sst) != OKAY)
return;
unlink(tgt);
- if ((dfd = creat(tgt, 0700)) < 0 || fchmod(dfd, 0700) < 0 ||
+ if ((dfd = creat(tgt, 0700)) < 0 || chmod(tgt, 0700) < 0 ||
fstat(dfd, &nst) < 0) {
fprintf(stderr, "%s: %s: %s\n", progname, src,
strerror(errno));
--- libcommon/Makefile.mk
+++ libcommon/Makefile.mk
@@ -15,7 +15,7 @@ CHECK: CHECK.c
headers: CHECK
one() { \
rm -f "$$1.h"; \
- if grep "$$1_h[ ]*=[ ]*[^0][ ]*;" CHECK >/dev/null; \
+ if true; \
then \
ln -s "_$$1.h" "$$1.h"; \
fi; \
--- libcommon/atoll.h
+++ libcommon/atoll.h
@@ -1,8 +1,10 @@
/* Sccsid @(#)atoll.h 1.4 (gritter) 7/18/04 */
#if defined (__hpux) || defined (_AIX) || \
- defined (__FreeBSD__) && (__FreeBSD__) < 5
+ (defined (__FreeBSD__) && (__FreeBSD__) < 5) || defined (__TINYC__)
+#ifndef __TINYC__
extern long long strtoll(const char *nptr, char **endptr, int base);
extern unsigned long long strtoull(const char *nptr, char **endptr, int base);
+#endif
extern long long atoll(const char *nptr);
#endif /* __hpux || _AIX || __FreeBSD__ < 5 */
--- libcommon/blank.h
+++ libcommon/blank.h
@@ -5,7 +5,7 @@
*/
/* Sccsid @(#)blank.h 1.3 (gritter) 5/1/04 */
-#ifndef __dietlibc__
+#if !defined(__dietlibc__) && !defined(__TINYC__)
#ifndef LIBCOMMON_BLANK_H
#define LIBCOMMON_BLANK_H 1
--- libcommon/getdir.c
+++ libcommon/getdir.c
@@ -52,7 +52,7 @@ extern int getdents(int, struct dirent *, size_t);
#undef d_ino
#endif /* __FreeBSD__ || __NetBSD__ || __OpenBSD__ || __DragonFly__
|| __APPLE__ */
-#elif defined (__dietlibc__)
+#elif defined (__dietlibc__) || defined(__TINYC__)
#include <dirent.h>
#include <unistd.h>
#else /* !__GLIBC__, !__dietlibc__ */
--- libcommon/memalign.c
+++ libcommon/memalign.c
@@ -23,7 +23,7 @@
#if defined (__FreeBSD__) || defined (__dietlibc__) || defined (_AIX) || \
defined (__NetBSD__) || defined (__OpenBSD__) || \
- defined (__DragonFly__) || defined (__APPLE__)
+ defined (__DragonFly__) || defined (__APPLE__) || defined(__TINYC__)
/*
* FreeBSD malloc(3) promises to page-align the return of malloc() calls
* if size is at least a page. This serves for a poor man's memalign()
--- libcommon/memalign.h
+++ libcommon/memalign.h
@@ -26,7 +26,7 @@
#if defined (__FreeBSD__) || defined (__dietlibc__) || defined (_AIX) || \
defined (__NetBSD__) || defined (__OpenBSD__) || \
- defined (__DragonFly__) || defined (__APPLE__)
+ defined (__DragonFly__) || defined (__APPLE__) || defined(__TINYC__)
#include <stdlib.h>
extern void *memalign(size_t, size_t);
--- libcommon/pathconf.c
+++ libcommon/pathconf.c
@@ -21,7 +21,7 @@
*/
/* Sccsid @(#)pathconf.c 1.2 (gritter) 5/1/04 */
-#ifdef __dietlibc__
+#if defined(__dietlibc__) || defined(__TINYC__)
#include <unistd.h>
#include "pathconf.h"
--- libcommon/pathconf.h
+++ libcommon/pathconf.h
@@ -21,7 +21,7 @@
*/
/* Sccsid @(#)pathconf.h 1.2 (gritter) 5/1/04 */
-#ifdef __dietlibc__
+#if defined(__dietlibc__) || defined(__TINYC__)
#include <unistd.h>
extern long fpathconf(int, int);
--- libcommon/regexp.h
+++ libcommon/regexp.h
@@ -47,7 +47,7 @@
static const char regexp_h_sccsid[] REGEXP_H_USED =
"@(#)regexp.sl 1.56 (gritter) 5/29/05";
-#if !defined (REGEXP_H_USED_FROM_VI) && !defined (__dietlibc__)
+#if !defined (REGEXP_H_USED_FROM_VI) && !defined (__dietlibc__) && !defined (__TINYC__)
#define REGEXP_H_WCHARS
#endif
--- libcommon/sfile.c
+++ libcommon/sfile.c
@@ -21,7 +21,7 @@
*/
/* Sccsid @(#)sfile.c 1.9 (gritter) 6/7/04 */
-#ifdef __linux__
+#if defined(__linux__) && !defined(__TINYC__)
#undef _FILE_OFFSET_BITS
#include <sys/types.h>
--- libcommon/sighold.c
+++ libcommon/sighold.c
@@ -22,7 +22,7 @@
/* Sccsid @(#)sighold.c 1.7 (gritter) 1/22/06 */
#if defined (__FreeBSD__) || defined (__dietlibc__) || defined (__NetBSD__) || \
- defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__)
+ defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__) || defined (__TINYC__)
#include <signal.h>
#include "sigset.h"
--- libcommon/sigignore.c
+++ libcommon/sigignore.c
@@ -22,7 +22,7 @@
/* Sccsid @(#)sigignore.c 1.6 (gritter) 1/22/06 */
#if defined (__FreeBSD__) || defined (__dietlibc__) || defined (__NetBSD__) || \
- defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__)
+ defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__) || defined (__TINYC__)
#include <signal.h>
#include "sigset.h"
--- libcommon/sigpause.c
+++ libcommon/sigpause.c
@@ -22,7 +22,7 @@
/* Sccsid @(#)sigpause.c 1.6 (gritter) 1/22/06 */
#if defined (__FreeBSD__) || defined (__dietlibc__) || defined (__NetBSD__) || \
- defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__)
+ defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__) || defined (__TINYC__)
#include <signal.h>
#include "sigset.h"
--- libcommon/sigrelse.c
+++ libcommon/sigrelse.c
@@ -22,7 +22,7 @@
/* Sccsid @(#)sigrelse.c 1.8 (gritter) 1/22/06 */
#if defined (__FreeBSD__) || defined (__dietlibc__) || defined (__NetBSD__) || \
- defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__)
+ defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__) || defined (__TINYC__)
#include <signal.h>
#include "sigset.h"
--- libcommon/sigset.c
+++ libcommon/sigset.c
@@ -22,7 +22,7 @@
/* Sccsid @(#)sigset.c 1.7 (gritter) 1/22/06 */
#if defined (__FreeBSD__) || defined (__dietlibc__) || defined (__NetBSD__) || \
- defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__)
+ defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__) || defined (__TINYC__)
#include <signal.h>
#include "sigset.h"
@@ -46,10 +46,7 @@ void (*sigset(int sig, void (*func)(int)))(int)
if (sigaction(sig, func==SIG_HOLD?(struct sigaction *)0:&nact, &oact)
== -1)
return SIG_ERR;
- if (sigismember(&oset, sig))
- return SIG_HOLD;
- else
- return (oact.sa_handler);
+ return (oact.sa_handler);
}
#endif /* __FreeBSD__ || __dietlibc__ || __NetBSD__ || __OpenBSD__ ||
__DragonFly__ || __APPLE__ */
--- libcommon/sigset.h
+++ libcommon/sigset.h
@@ -22,7 +22,7 @@
/* Sccsid @(#)sigset.h 1.9 (gritter) 1/22/06 */
#if defined (__FreeBSD__) || defined (__dietlibc__) || defined (__NetBSD__) || \
- defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__)
+ defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__) || defined (__TINYC__)
#ifndef SIG_HOLD
#define SIG_HOLD ((void (*)(int))2)
--- libcommon/strtol.c
+++ libcommon/strtol.c
@@ -1,7 +1,7 @@
/* Sccsid @(#)strtol.c 1.6 (gritter) 7/18/04 */
#if defined (__hpux) || defined (_AIX) || \
- defined (__FreeBSD__) && (__FreeBSD__) < 5
+ (defined (__FreeBSD__) && (__FreeBSD__) < 5) || defined (__TINYC__)
#include <stdlib.h>
#include <ctype.h>
@@ -97,6 +97,7 @@ out: if (pp <= bptr) {
return v * sign;
}
+#ifndef __TINYC__
long long
strtoll(const char *nptr, char **endptr, int base)
{
@@ -108,6 +109,7 @@ strtoull(const char *nptr, char **endptr, int base)
{
return (unsigned long long)internal(nptr, endptr, base, 3);
}
+#endif
long long
atoll(const char *nptr)
--- nawk/awk.h
+++ nawk/awk.h
@@ -156,7 +156,6 @@ extern Cell *rlengthloc; /* RLENGTH */
#endif
#ifndef IN_MAKETAB
-#include <wchar.h>
/*
* Get next character from string s and store it in wc; n is set to
--- nawk/awk.lx.l
+++ nawk/awk.lx.l
@@ -71,7 +71,6 @@
#include "awk.h"
#include "y.tab.h"
-#include <pfmt.h>
#include <unistd.h>
static void awk_unputstr(const char *s);
--- nawk/run.c
+++ nawk/run.c
@@ -1467,14 +1467,6 @@ Cell *bltin(Node **a, int n)
case FRAND:
u = (Awkfloat) (rand() % 32767) / 32767.0;
break;
- case FSRAND:
- u = saved_srand; /* return previous seed */
- if (x->tval & REC) /* no argument provided */
- saved_srand = time(NULL);
- else
- saved_srand = getfval(x);
- srand((int) saved_srand);
- break;
case FTOUPPER:
case FTOLOWER:
p = getsval(x);
--- pgrep/pgrep.c
+++ pgrep/pgrep.c
@@ -214,7 +214,7 @@ chdir_to_proc(void)
fprintf(stderr, "%s: cannot open %s\n", progname, PROCDIR);
exit(3);
}
- if (fchdir(fd) < 0) {
+ if (chdir(PROCDIR) < 0) {
fprintf(stderr, "%s: cannot chdir to %s\n", progname, PROCDIR);
exit(3);
}
--- rm/rm.c
+++ rm/rm.c
@@ -242,7 +242,7 @@ rm(size_t pend, const char *base, const int olddir, int ssub, int level)
}
return;
}
- if (fchdir(df) < 0) {
+ if (chdir(base) < 0) {
if (rmfile(base, &st) < 0) {
fprintf(stderr,
"%s: cannot chdir to %s\n",
@@ -270,7 +270,7 @@ rm(size_t pend, const char *base, const int olddir, int ssub, int level)
progname, path);
errcnt |= 4;
}
- if (olddir >= 0 && fchdir(olddir) < 0) {
+ if (olddir >= 0) {
fprintf(stderr, "%s: cannot change backwards\n",
progname);
exit(1);
@@ -316,24 +316,6 @@ subproc(size_t pend, const char *base, int level)
int status;
while (waitpid(pid, &status, 0) != pid);
- if (status && WIFSIGNALED(status)) {
- /*
- * If the signal was sent due to a tty keypress,
- * we should be terminated automatically and
- * never reach this point. Otherwise, we terminate
- * with the same signal, but make sure that we do
- * not overwrite a possibly generated core file.
- * This results in nearly the usual behavior except
- * that the shell never prints a 'core dumped'
- * message.
- */
- struct rlimit rl;
-
- rl.rlim_cur = rl.rlim_max = 0;
- setrlimit(RLIMIT_CORE, &rl);
- raise(WTERMSIG(status));
- pause();
- }
return status ? WEXITSTATUS(status) : 0;
}
case -1:

View File

@@ -0,0 +1,53 @@
/*
Copyright © 2005-2019 Rich Felker, et al.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// Additional utilities from musl 1.1.24
// include/stdlib.h
#define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
#define WTERMSIG(s) ((s) & 0x7f)
#define WIFEXITED(s) (!WTERMSIG(s))
#define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu)
// include/sys/sysmacros.h
#define major(x) \
((unsigned)( (((x)>>31>>1) & 0xfffff000) | (((x)>>8) & 0x00000fff) ))
#define minor(x) \
((unsigned)( (((x)>>12) & 0xffffff00) | ((x) & 0x000000ff) ))
#define makedev(x,y) ( \
(((x)&0xfffff000ULL) << 32) | \
(((x)&0x00000fffULL) << 8) | \
(((y)&0xffffff00ULL) << 12) | \
(((y)&0x000000ffULL)) )
// src/misc/basename.c
#include <string.h>
char *basename(char *s)
{
size_t i;
if (!s || !*s) return ".";
i = strlen(s)-1;
for (; i&&s[i]=='/'; i--) s[i] = 0;
for (; i&&s[i-1]!='/'; i--);
return s+i;
}

View File

@@ -0,0 +1,205 @@
#include <stdio.h>
#include "awk.h"
#include "y.tab.h"
static unsigned char *printname[92] = {
(unsigned char *) "FIRSTTOKEN", /* 258 */
(unsigned char *) "PROGRAM", /* 259 */
(unsigned char *) "PASTAT", /* 260 */
(unsigned char *) "PASTAT2", /* 261 */
(unsigned char *) "XBEGIN", /* 262 */
(unsigned char *) "XEND", /* 263 */
(unsigned char *) "NL", /* 264 */
(unsigned char *) "ARRAY", /* 265 */
(unsigned char *) "MATCH", /* 266 */
(unsigned char *) "NOTMATCH", /* 267 */
(unsigned char *) "MATCHOP", /* 268 */
(unsigned char *) "FINAL", /* 269 */
(unsigned char *) "DOT", /* 270 */
(unsigned char *) "ALL", /* 271 */
(unsigned char *) "CCL", /* 272 */
(unsigned char *) "NCCL", /* 273 */
(unsigned char *) "CHAR", /* 274 */
(unsigned char *) "MCHAR", /* 275 */
(unsigned char *) "OR", /* 276 */
(unsigned char *) "STAR", /* 277 */
(unsigned char *) "QUEST", /* 278 */
(unsigned char *) "PLUS", /* 279 */
(unsigned char *) "AND", /* 280 */
(unsigned char *) "BOR", /* 281 */
(unsigned char *) "APPEND", /* 282 */
(unsigned char *) "EQ", /* 283 */
(unsigned char *) "GE", /* 284 */
(unsigned char *) "GT", /* 285 */
(unsigned char *) "LE", /* 286 */
(unsigned char *) "LT", /* 287 */
(unsigned char *) "NE", /* 288 */
(unsigned char *) "IN", /* 289 */
(unsigned char *) "ARG", /* 290 */
(unsigned char *) "BLTIN", /* 291 */
(unsigned char *) "BREAK", /* 292 */
(unsigned char *) "CONTINUE", /* 293 */
(unsigned char *) "DELETE", /* 294 */
(unsigned char *) "DO", /* 295 */
(unsigned char *) "EXIT", /* 296 */
(unsigned char *) "FOR", /* 297 */
(unsigned char *) "FUNC", /* 298 */
(unsigned char *) "SUB", /* 299 */
(unsigned char *) "GSUB", /* 300 */
(unsigned char *) "IF", /* 301 */
(unsigned char *) "INDEX", /* 302 */
(unsigned char *) "LSUBSTR", /* 303 */
(unsigned char *) "MATCHFCN", /* 304 */
(unsigned char *) "NEXT", /* 305 */
(unsigned char *) "ADD", /* 306 */
(unsigned char *) "MINUS", /* 307 */
(unsigned char *) "MULT", /* 308 */
(unsigned char *) "DIVIDE", /* 309 */
(unsigned char *) "MOD", /* 310 */
(unsigned char *) "ASSIGN", /* 311 */
(unsigned char *) "ASGNOP", /* 312 */
(unsigned char *) "ADDEQ", /* 313 */
(unsigned char *) "SUBEQ", /* 314 */
(unsigned char *) "MULTEQ", /* 315 */
(unsigned char *) "DIVEQ", /* 316 */
(unsigned char *) "MODEQ", /* 317 */
(unsigned char *) "POWEQ", /* 318 */
(unsigned char *) "PRINT", /* 319 */
(unsigned char *) "PRINTF", /* 320 */
(unsigned char *) "SPRINTF", /* 321 */
(unsigned char *) "ELSE", /* 322 */
(unsigned char *) "INTEST", /* 323 */
(unsigned char *) "CONDEXPR", /* 324 */
(unsigned char *) "POSTINCR", /* 325 */
(unsigned char *) "PREINCR", /* 326 */
(unsigned char *) "POSTDECR", /* 327 */
(unsigned char *) "PREDECR", /* 328 */
(unsigned char *) "VAR", /* 329 */
(unsigned char *) "IVAR", /* 330 */
(unsigned char *) "VARNF", /* 331 */
(unsigned char *) "CALL", /* 332 */
(unsigned char *) "NUMBER", /* 333 */
(unsigned char *) "STRING", /* 334 */
(unsigned char *) "FIELD", /* 335 */
(unsigned char *) "REGEXPR", /* 336 */
(unsigned char *) "GETLINE", /* 337 */
(unsigned char *) "RETURN", /* 338 */
(unsigned char *) "SPLIT", /* 339 */
(unsigned char *) "SUBSTR", /* 340 */
(unsigned char *) "WHILE", /* 341 */
(unsigned char *) "CAT", /* 342 */
(unsigned char *) "NOT", /* 343 */
(unsigned char *) "UMINUS", /* 344 */
(unsigned char *) "POWER", /* 345 */
(unsigned char *) "DECR", /* 346 */
(unsigned char *) "INCR", /* 347 */
(unsigned char *) "INDIRECT", /* 348 */
(unsigned char *) "LASTTOKEN", /* 349 */
};
Cell *(*proctab[92])(Node **, int) = {
nullproc, /* FIRSTTOKEN */
program, /* PROGRAM */
pastat, /* PASTAT */
dopa2, /* PASTAT2 */
nullproc, /* XBEGIN */
nullproc, /* XEND */
nullproc, /* NL */
array, /* ARRAY */
matchop, /* MATCH */
matchop, /* NOTMATCH */
nullproc, /* MATCHOP */
nullproc, /* FINAL */
nullproc, /* DOT */
nullproc, /* ALL */
nullproc, /* CCL */
nullproc, /* NCCL */
nullproc, /* CHAR */
nullproc, /* MCHAR */
nullproc, /* OR */
nullproc, /* STAR */
nullproc, /* QUEST */
nullproc, /* PLUS */
boolop, /* AND */
boolop, /* BOR */
nullproc, /* APPEND */
relop, /* EQ */
relop, /* GE */
relop, /* GT */
relop, /* LE */
relop, /* LT */
relop, /* NE */
instat, /* IN */
arg, /* ARG */
bltin, /* BLTIN */
jump, /* BREAK */
jump, /* CONTINUE */
delete, /* DELETE */
dostat, /* DO */
jump, /* EXIT */
forstat, /* FOR */
nullproc, /* FUNC */
sub, /* SUB */
gsub, /* GSUB */
ifstat, /* IF */
sindex, /* INDEX */
nullproc, /* LSUBSTR */
matchop, /* MATCHFCN */
jump, /* NEXT */
arith, /* ADD */
arith, /* MINUS */
arith, /* MULT */
arith, /* DIVIDE */
arith, /* MOD */
assign, /* ASSIGN */
nullproc, /* ASGNOP */
assign, /* ADDEQ */
assign, /* SUBEQ */
assign, /* MULTEQ */
assign, /* DIVEQ */
assign, /* MODEQ */
assign, /* POWEQ */
print, /* PRINT */
aprintf, /* PRINTF */
awsprintf, /* SPRINTF */
nullproc, /* ELSE */
intest, /* INTEST */
condexpr, /* CONDEXPR */
incrdecr, /* POSTINCR */
incrdecr, /* PREINCR */
incrdecr, /* POSTDECR */
incrdecr, /* PREDECR */
nullproc, /* VAR */
nullproc, /* IVAR */
getnf, /* VARNF */
call, /* CALL */
nullproc, /* NUMBER */
nullproc, /* STRING */
nullproc, /* FIELD */
nullproc, /* REGEXPR */
getline, /* GETLINE */
jump, /* RETURN */
split, /* SPLIT */
substr, /* SUBSTR */
whilestat, /* WHILE */
cat, /* CAT */
boolop, /* NOT */
arith, /* UMINUS */
arith, /* POWER */
nullproc, /* DECR */
nullproc, /* INCR */
indirect, /* INDIRECT */
nullproc, /* LASTTOKEN */
};
unsigned char *tokname(int n)
{
static unsigned char buf[100];
if (n < FIRSTTOKEN || n > LASTTOKEN) {
snprintf((char *)buf, sizeof buf, "token %d", n);
return buf;
}
return printname[n-257];
}

View File

@@ -0,0 +1,11 @@
--- nawk/Makefile.mk
+++ nawk/Makefile.mk
@@ -28,8 +28,6 @@ maketab: maketab.o
$(HOSTCC) maketab.o -o maketab
./maketab > proctab.c
-proctab.c: maketab
-
awk.g.o: awk.g.c
$(CC) $(CFLAGSS) $(CPPFLAGS) $(XO5FL) $(LARGEF) $(IWCHAR) $(ICOMMON) $(IUXRE) -c awk.g.c

View File

@@ -0,0 +1,73 @@
--- comm/comm.c
+++ comm/comm.c
@@ -242,7 +242,7 @@ compare(const char *a, const char *b)
return(2);
}
} else {
- n = strcoll(a, b);
+ n = strcmp(a, b);
return n ? n > 0 ? 2 : 1 : 0;
}
}
--- expr/expr.y
+++ expr/expr.y
@@ -234,7 +234,7 @@ _rel(int op, register char *r1, register char *r2)
if (numeric(r1) && numeric(r2))
i = atoll(r1) - atoll(r2);
else
- i = strcoll(r1, r2);
+ i = strcmp(r1, r2);
switch(op) {
case EQ: i = i==0; break;
case GT: i = i>0; break;
--- join/join.c
+++ join/join.c
@@ -65,7 +65,7 @@ enum {
JF = -1
};
#define ppi(f, j) ((j) >= 0 && (j) < ppisize[f] ? ppibuf[f][j] : null)
-#define comp() strcoll(ppi(F1, j1),ppi(F2, j2))
+#define comp() strcmp(ppi(F1, j1),ppi(F2, j2))
#define next(wc, s, n) (*(s) & 0200 ? ((n) = mbtowi(&(wc), (s), mb_cur_max), \
(n) = ((n) > 0 ? (n) : (n) < 0 ? (wc=WEOF, 1) : 1)) : \
--- ls/ls.c
+++ ls/ls.c
@@ -575,13 +575,13 @@ _mergesort(struct file **al)
static int
namecmp(struct file *f1, struct file *f2)
{
- return strcoll(f1->name, f2->name);
+ return strcmp(f1->name, f2->name);
}
static int
extcmp(struct file *f1, struct file *f2)
{
- return strcoll(extension(f1->name), extension(f2->name));
+ return strcmp(extension(f1->name), extension(f2->name));
}
static int
--- nawk/run.c
+++ nawk/run.c
@@ -608,7 +608,7 @@ Cell *relop(Node **a, int n)
j = x->fval - y->fval;
i = j<0? -1: (j>0? 1: 0);
} else {
- i = strcoll((char*)getsval(x), (char*)getsval(y));
+ i = strcmp((char*)getsval(x), (char*)getsval(y));
}
tempfree(x, "");
tempfree(y, "");
--- sort/sort.c
+++ sort/sort.c
@@ -1148,7 +1148,7 @@ cmpl(const char *pa, const char *pb)
ecpy(collba, pa, '\n');
ecpy(collbb, pb, '\n');
- n = strcoll(collba, collbb);
+ n = strcmp(collba, collbb);
return n ? n > 0 ? -fields[0].rflg : fields[0].rflg : 0;
}

View File

@@ -0,0 +1,64 @@
#include <getopt.h>
extern int optopt;
int ftruncate(int fd, int offset) {
return -1;
}
int getsid (int pid) {
return -1;
}
static int isblank(int c)
{
return c == ' ' || c == '\t';
}
#define lchown chown
// meslibc implements lstat but is missing declaration
#include <sys/stat.h>
int lstat (char const *file_name, struct stat *statbuf);
#include <fcntl.h>
int mkstemp(char *t)
{
mktemp(t);
int fd = open(t, O_CREAT|O_RDWR|O_TRUNC, 0600);
return fd;
}
int putenv(char *string)
{
return 0;
}
char* realpath (char* path, char* resolved) {
return NULL;
}
#define strncasecmp(a,b,n) strncmp(strupr(a),strupr(b),n)
#define nlink_t unsigned long
#include <limits.h>
#define USHRT_MAX UINT16_MAX
#define SSIZE_MAX LONG_MAX
#define MB_LEN_MAX 1
#define EPERM 1
#define ESRCH 3
#define EDOM 33
#define S_IFSOCK 0140000
#define S_ISVTX 01000
#define S_IREAD S_IRUSR
#define S_IWRITE S_IWUSR
#define S_IEXEC S_IXUSR
#define _PC_PATH_MAX PATH_MAX
#define _PC_VDISABLE 8
#define _POSIX_PATH_MAX PATH_MAX
#define LINE_MAX 4096
#define LC_TIME 0

View File

@@ -0,0 +1,77 @@
--- cmp/cmp.c
+++ cmp/cmp.c
@@ -264,7 +264,7 @@ openfile(const char *fn)
struct file *f;
if (pagesize == 0)
- if ((pagesize = sysconf(_SC_PAGESIZE)) < 0)
+ if ((pagesize = 4096) < 0)
pagesize = 4096;
if ((f = memalign(pagesize, sizeof *f)) == NULL) {
write(2, "no memory\n", 10);
--- copy/copy.c
+++ copy/copy.c
@@ -362,7 +362,7 @@ fdcopy(const char *src, const struct stat *sp, int sfd,
goto err;
}
#endif /* __linux__ */
- if (pagesize == 0 && (pagesize = sysconf(_SC_PAGESIZE)) <= 0)
+ if (pagesize == 0 && (pagesize = 4096) <= 0)
pagesize = 4096;
if ((blksize = sp->st_blksize) <= 0)
blksize = 512;
--- cp/cp.c
+++ cp/cp.c
@@ -438,7 +438,7 @@ fdcopy(const char *src, const struct stat *ssp, const int sfd,
}
#endif /* __linux__ */
if (pagesize == 0)
- if ((pagesize = sysconf(_SC_PAGESIZE)) < 0)
+ if ((pagesize = 4096) < 0)
pagesize = 4096;
if (bflag)
blksize = bflag;
--- libcommon/ib_alloc.c
+++ libcommon/ib_alloc.c
@@ -41,7 +41,7 @@ ib_alloc(int fd, unsigned blksize)
struct stat st;
if (pagesize == 0)
- if ((pagesize = sysconf(_SC_PAGESIZE)) < 0)
+ if ((pagesize = 4096) < 0)
pagesize = 4096;
if (blksize == 0) {
if (fstat(fd, &st) < 0)
--- libcommon/memalign.c
+++ libcommon/memalign.c
@@ -40,7 +40,7 @@ memalign(size_t alignment, size_t size)
static long pagesize;
if (pagesize == 0)
- pagesize = sysconf(_SC_PAGESIZE);
+ pagesize = 4096;
if (alignment != pagesize)
return NULL;
if (size < pagesize)
--- libcommon/oblok.c
+++ libcommon/oblok.c
@@ -100,7 +100,7 @@ ob_alloc(int fd, enum ob_mode bf)
struct oblok *op;
if (pagesize == 0)
- if ((pagesize = sysconf(_SC_PAGESIZE)) < 0)
+ if ((pagesize = 4096) < 0)
pagesize = 4096;
if ((op = memalign(pagesize, sizeof *op)) == NULL)
return NULL;
--- xargs/xargs.c
+++ xargs/xargs.c
@@ -404,7 +404,7 @@ static void
endcmd(void)
{
a_agg = a_cnt;
- a_maxsize = sysconf(_SC_ARG_MAX) - envsz() - 2048 - a_asz;
+ a_maxsize = 65536 - envsz() - 2048 - a_asz;
if (nflag || sflag) {
long newsize = sflag ? atol(sflag) :
#ifdef WEIRD_LIMITS

View File

@@ -0,0 +1,11 @@
--- libwchar/Makefile.mk
+++ libwchar/Makefile.mk
@@ -10,7 +10,7 @@ fake:
if test "x$(LWCHAR)" = x; \
then \
touch $(OBJ); \
- ar r libwchar.a $(OBJ); \
+ touch libwchar.a $(OBJ); \
fi
install:

View File

@@ -0,0 +1,141 @@
--- ed/ed.c
+++ ed/ed.c
@@ -68,7 +68,6 @@ static const char sccsid[] USED = "@(#)ed.sl 1.99 (gritter) 7/27/06";
#include <stdlib.h>
#include <signal.h>
#include "sigset.h"
-#include <termios.h>
#include <setjmp.h>
#include <libgen.h>
#include <inttypes.h>
@@ -77,7 +76,6 @@ static const char sccsid[] USED = "@(#)ed.sl 1.99 (gritter) 7/27/06";
#include <ctype.h>
#include <wctype.h>
#include <limits.h>
-#include <termios.h>
static int FNSIZE;
static int LBSIZE;
static int RHSIZE;
@@ -2273,22 +2271,10 @@ sclose(int fd)
static void
fspec(const char *lp)
{
- struct termios ts;
const char *cp;
freetabs();
maxlength = 0;
- if (tcgetattr(1, &ts) < 0
-#ifdef TAB3
- || (ts.c_oflag&TAB3) == 0
-#endif
- )
- return;
- while (lp[0]) {
- if (lp[0] == '<' && lp[1] == ':')
- break;
- lp++;
- }
if (lp[0]) {
lp += 2;
while ((cp = ftok(&lp)) != NULL) {
--- ls/ls.c
+++ ls/ls.c
@@ -102,7 +102,6 @@ static char ifmt_c[] = "-pc-d-b--nl-SD--";
#include <grp.h>
#include <errno.h>
#include <fcntl.h>
-#include <termios.h>
#include <locale.h>
#include <limits.h>
#include <ctype.h>
@@ -110,14 +109,6 @@ static char ifmt_c[] = "-pc-d-b--nl-SD--";
#include <wchar.h>
#include <wctype.h>
#include "config.h"
-#ifndef USE_TERMCAP
-#ifndef sun
-#include <curses.h>
-#include <term.h>
-#endif
-#else /* USE_TERMCAP */
-#include <termcap.h>
-#endif /* USE_TERMCAP */
#ifdef _AIX
#include <sys/sysmacros.h>
@@ -989,13 +980,6 @@ printname(const char *name, struct file *f, int doit)
bold++;
}
if (color) {
-#ifndef USE_TERMCAP
- if (bold)
- vidattr(A_BOLD);
-#else /* USE_TERMCAP */
- if (Bold)
- tputs(Bold, 1, putchar);
-#endif /* USE_TERMCAP */
printf(color);
}
}
@@ -1056,13 +1040,6 @@ printname(const char *name, struct file *f, int doit)
}
}
if (doit && color) {
-#if !defined (USE_TERMCAP)
- if (bold)
- vidattr(A_NORMAL);
-#else /* USE_TERMCAP */
- if (Normal)
- tputs(Normal, 1, putchar);
-#endif /* USE_TERMCAP */
printf(fc_get(FC_NORMAL));
}
if (f)
@@ -1598,16 +1575,12 @@ main(int argc, char **argv)
{
struct file *flist = nil, **aflist = &flist;
enum depth depth;
- struct winsize ws;
int i;
char *cp;
#ifdef __GLIBC__
putenv("POSIXLY_CORRECT=1");
#endif
- setlocale(LC_COLLATE, "");
- setlocale(LC_CTYPE, "");
- setlocale(LC_TIME, "");
#ifndef UCB
if (getenv("SYSV3") != NULL)
sysv3 = 1;
@@ -1624,16 +1597,6 @@ main(int argc, char **argv)
}
if (istty || isatty(1)) {
istty = 1;
-#if !defined (USE_TERMCAP)
- setupterm(NULL, 1, &tinfostat);
-#else /* USE_TERMCAP */
- {
- char buf[2048];
- if ((cp = getenv("TERM")) != NULL)
- if (tgetent(buf, cp) > 0)
- tinfostat = 1;
- }
-#endif /* USE_TERMCAP */
field |= FL_STATUS;
}
while ((i = getopt(argc, argv, personalities[personality].per_opt))
@@ -1753,12 +1716,6 @@ main(int argc, char **argv)
if ((cp = getenv("COLUMNS")) != NULL) {
ncols = atoi(cp);
} else if ((present('C') || present('x') || present('m')) && istty) {
- if (ioctl(1, TIOCGWINSZ, &ws) == 0 && ws.ws_col > 0)
- ncols = ws.ws_col - 1;
-#if !defined (USE_TERMCAP)
- else if (tinfostat == 1 && columns > 0)
- ncols = columns;
-#endif /* !USE_TERMCAP */
}
depth = SURFACE;
if (optind == argc) {

View File

@@ -0,0 +1,90 @@
--- copy/copy.c
+++ copy/copy.c
@@ -46,7 +46,6 @@ static const char sccsid[] USED = "@(#)copy.sl 1.15 (gritter) 5/29/05";
#include <libgen.h>
#include <limits.h>
#include <dirent.h>
-#include <utime.h>
#include <stdarg.h>
#include "sfile.h"
#include "memalign.h"
@@ -441,12 +440,6 @@ attribs(const char *dst, const struct stat *sp)
if (oflag && ((sp->st_mode&S_IFMT) == S_IFLNK ?
lchown:chown)(dst, sp->st_uid, sp->st_gid) < 0)
complain("Unable to chown %s", dst);
- if (mflag && (sp->st_mode&S_IFMT) != S_IFLNK) {
- struct utimbuf ut;
- ut.actime = sp->st_atime;
- ut.modtime = sp->st_mtime;
- utime(dst, &ut);
- }
}
static void
--- cp/cp.c
+++ cp/cp.c
@@ -56,7 +56,6 @@ static const char sccsid[] USED = "@(#)cp.sl 1.84 (gritter) 3/4/06";
#include <libgen.h>
#include <limits.h>
#include <dirent.h>
-#include <utime.h>
#include "sfile.h"
#include "memalign.h"
#include "alloca.h"
@@ -354,18 +353,6 @@ permissions(const char *path, const struct stat *ssp)
mode = ssp->st_mode & 07777;
if (pflag) {
- struct utimbuf ut;
- ut.actime = ssp->st_atime;
- ut.modtime = ssp->st_mtime;
- if (utime(path, &ut) < 0) {
-#if defined (SUS) || defined (S42)
- fprintf(stderr, "%s: cannot set times for %s\n%s: %s\n",
- progname, path,
- progname, strerror(errno));
-#endif /* SUS || S42 */
- if (pers != PERS_MV)
- errcnt |= 010;
- }
if (myuid == 0) {
if (chown(path, ssp->st_uid, ssp->st_gid) < 0) {
#if defined (SUS) || defined (S42)
--- touch/touch.c
+++ touch/touch.c
@@ -47,7 +47,6 @@ static const char sccsid[] USED = "@(#)touch.sl 1.21 (gritter) 5/29/05";
#include <stdlib.h>
#include <errno.h>
#include <libgen.h>
-#include <utime.h>
#include <ctype.h>
#include <time.h>
@@ -80,7 +79,6 @@ static void
touch(const char *fn)
{
struct stat st;
- struct utimbuf ut;
if (stat(fn, &st) < 0) {
if (errno == ENOENT) {
@@ -113,19 +111,6 @@ touch(const char *fn)
return;
}
}
- if (aflag)
- ut.actime = nacc;
- else
- ut.actime = st.st_atime;
- if (mflag)
- ut.modtime = nmod;
- else
- ut.modtime = st.st_mtime;
- if (utime(fn, nulltime ? NULL : &ut) < 0) {
- fprintf(stderr, "%s: cannot change times on %s\n",
- progname, fn);
- errcnt++;
- }
}
static void

View File

@@ -0,0 +1,128 @@
--- cksum/cksum.c
+++ cksum/cksum.c
@@ -147,7 +147,7 @@ cksum(const char *name)
s = (s << 8) ^ crctab[(s >> 24) ^ c];
}
s = ~s;
- printf("%u %llu", (unsigned)s, nbytes);
+ printf("%u %lu", (unsigned)s, nbytes);
if(name)
printf(" %s", name);
printf("\n");
--- cmp/cmp.c
+++ cmp/cmp.c
@@ -246,8 +246,8 @@ different:
errcnt = 1;
} else {
if (sflag == 0)
- printf("%s %s differ: char %lld,"
- " line %lld\n",
+ printf("%s %s differ: char %ld,"
+ " line %ld\n",
f1->f_nam, f2->f_nam,
(long long)offset(f1),
line);
--- csplit/csplit.c
+++ csplit/csplit.c
@@ -284,7 +284,7 @@ csplit(const char *fn)
op = nextfile();
if (op) {
if (!sflag)
- printf("%lld\n", bytes);
+ printf("%ld\n", bytes);
bytes = 0;
fclose(op);
}
--- expr/expr.y
+++ expr/expr.y
@@ -140,7 +140,7 @@ expression: expr NOARG {
if (sus && numeric($1)) {
int64_t n;
n = atoll($1);
- printf("%lld\n", n);
+ printf("%ld\n", n);
exit(n == 0);
} else
puts($1);
@@ -447,10 +447,10 @@ numpr(int64_t val)
int ret;
rv = smalloc(NUMSZ);
- ret = snprintf(rv, NUMSZ, "%lld", (long long)val);
+ ret = snprintf(rv, NUMSZ, "%ld", (long long)val);
if (ret < 0 || ret >= NUMSZ) {
rv = srealloc(rv, ret + 1);
- ret = snprintf(rv, ret, "%lld", (long long)val);
+ ret = snprintf(rv, ret, "%ld", (long long)val);
if (ret < 0)
yyerror("illegal number");
}
--- grep/Makefile.mk
+++ grep/Makefile.mk
@@ -92,7 +92,7 @@ config.h:
-echo 'long long foo;' >___build$$$$.c ; \
$(CC) $(CFLAGS2) $(CPPFLAGS) $(IWCHAR) $(ICOMMON) $(IUXRE) $(LARGEF) -c ___build$$$$.c >/dev/null 2>&1 ; \
if test $$? = 0 && test -f ___build$$$$.o ; \
- then echo '#define LONGLONG' >>config.h ; \
+ then echo '' >>config.h ; \
fi ; \
rm -f ___build$$$$.o ___build$$$$.c
--- ls/Makefile.mk
+++ ls/Makefile.mk
@@ -76,7 +76,7 @@ config.h:
-echo 'long long foo;' >___build$$$$.c ; \
$(CC) $(CFLAGS) $(CPPFLAGS) $(LARGEF) $(IWCHAR) -c ___build$$$$.c >/dev/null 2>&1 ; \
if test $$? = 0 && test -f ___build$$$$.o ; \
- then echo '#define LONGLONG' >>config.h ; \
+ then echo '' >>config.h ; \
fi ; \
rm -f ___build$$$$.o ___build$$$$.c
-echo '#include <sys/types.h>' >___build$$$$.c ; \
--- pr/pr.c
+++ pr/pr.c
@@ -548,7 +548,7 @@ print(const char *fp, const char **argp)
putcs(" ");
putcs(header);
snprintf(linebuf, sizeof linebuf,
- " Page %lld\n\n\n", page);
+ " Page %ld\n\n\n", page);
putcs(linebuf);
}
c = putpage();
--- sed/sed1.c
+++ sed/sed1.c
@@ -489,7 +489,7 @@ command(struct reptr *ipc)
break;
case EQCOM:
- fprintf(stdout, "%lld\n", lnum);
+ fprintf(stdout, "%ld\n", lnum);
break;
case GCOM:
--- sum/sum.c
+++ sum/sum.c
@@ -116,7 +116,7 @@ sum(const char *name)
else {
s = (s & 0xFFFF) + (s >> 16);
s = (s & 0xFFFF) + (s >> 16);
- printf("%u %llu", (unsigned)s,
+ printf("%u %lu", (unsigned)s,
(unsigned long long)(nbytes+UNIT-1)/UNIT);
}
if(name)
--- wc/wc.c
+++ wc/wc.c
@@ -89,9 +89,9 @@ report(unsigned long long count)
#if defined (S42)
if (putspace++)
printf(" ");
- printf("%llu", count);
+ printf("%lu", count);
#else /* !S42 */
- printf("%7llu ", count);
+ printf("%7lu ", count);
#endif /* !S42 */
}

View File

@@ -0,0 +1,52 @@
{
lib,
fetchurl,
bash,
gnutar,
xz,
}:
let
# WARNING: You probably don't want to use this package outside minimal-bootstrap
#
# We need some set of Linux kernel headers to build our bootstrap packages
# (gcc/binutils/glibc etc.) against. As long as it compiles it is "good enough".
# Therefore the requirement for correctness, completeness, platform-specific
# features, and being up-to-date, are very loose.
#
# Rebuilding the Linux headers from source correctly is something we can defer
# till we have access to gcc/binutils/perl. For now we can use Guix's assembled
# kernel header distribution and assume it's good enough.
pname = "linux-headers";
version = "4.14.67";
src = fetchurl {
url = "mirror://gnu/gnu/guix/bootstrap/i686-linux/20190815/linux-libre-headers-stripped-4.14.67-i686-linux.tar.xz";
sha256 = "0sm2z9x4wk45bh6qfs94p0w1d6hsy6dqx9sw38qsqbvxwa1qzk8s";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
gnutar
xz
];
meta = with lib; {
description = "Header files and scripts for Linux kernel";
license = licenses.gpl2Only;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.linux;
};
}
''
# Unpack
cp ${src} linux-headers.tar.xz
unxz linux-headers.tar.xz
tar xf linux-headers.tar
# Install
mkdir $out
cp -r include $out
''

View File

@@ -0,0 +1,31 @@
{
lib,
kaem,
mes,
}:
let
pname = "ln-boot";
version = "unstable-2023-05-22";
src = ./ln.c;
in
kaem.runCommand "${pname}-${version}"
{
inherit pname version;
meta = with lib; {
description = "Basic tool for creating symbolic links";
license = licenses.mit;
teams = [ teams.minimal-bootstrap ];
mainProgram = "ln";
platforms = platforms.unix;
};
}
''
mkdir -p ''${out}/bin
${mes.compiler}/bin/mes --no-auto-compile -e main ${mes.srcPost.bin}/bin/mescc.scm -- \
-L ${mes.libs}/lib \
-lc+tcc \
-o ''${out}/bin/ln \
${src}
''

View File

@@ -0,0 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int main(int argc, char** argv)
{
if (argc != 4 || strcmp(argv[1], "-s")) {
fputs("Usage: ", stdout);
fputs(argv[0], stdout);
fputs(" -s TARGET LINK_NAME\n", stdout);
exit(EXIT_FAILURE);
}
symlink(argv[2], argv[3]);
exit(EXIT_SUCCESS);
}

View File

@@ -0,0 +1,260 @@
{
lib,
fetchurl,
callPackage,
kaem,
mescc-tools,
}:
# Maintenance note:
# Build steps have been adapted from build-aux/bootstrap.sh.in
# as well as the live-bootstrap project
# https://github.com/fosslinux/live-bootstrap/blob/737bf61a26152fb82510a2797f0d712de918aa78/sysa/mes-0.25/mes-0.25.kaem
let
pname = "mes";
version = "0.25";
src = fetchurl {
url = "mirror://gnu/mes/mes-${version}.tar.gz";
hash = "sha256-MlJQs1Z+2SA7pwFhyDWvAQeec+vtl7S1u3fKUAuCiUA=";
};
nyacc = callPackage ./nyacc.nix { inherit nyacc; };
config_h = builtins.toFile "config.h" ''
#undef SYSTEM_LIBC
#define MES_VERSION "${version}"
'';
sources = (import ./sources.nix).x86.linux.mescc;
inherit (sources)
libc_mini_SOURCES
libmescc_SOURCES
libc_SOURCES
mes_SOURCES
;
# add symlink() to libc+tcc so we can use it in ln-boot
libc_tcc_SOURCES = sources.libc_tcc_SOURCES ++ [ "lib/linux/symlink.c" ];
meta = with lib; {
description = "Scheme interpreter and C compiler for bootstrapping";
homepage = "https://www.gnu.org/software/mes";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = [ "i686-linux" ];
};
srcPost =
kaem.runCommand "${pname}-src-${version}"
{
outputs = [
"out"
"bin"
];
inherit meta;
}
''
# Unpack source
ungz --file ${src} --output mes.tar
mkdir ''${out}
cd ''${out}
untar --non-strict --file ''${NIX_BUILD_TOP}/mes.tar # ignore symlinks
MES_PREFIX=''${out}/mes-${version}
cd ''${MES_PREFIX}
cp ${config_h} include/mes/config.h
mkdir include/arch
cp include/linux/x86/syscall.h include/arch/syscall.h
cp include/linux/x86/kernel-stat.h include/arch/kernel-stat.h
# Remove pregenerated files
rm mes/module/mes/psyntax.pp mes/module/mes/psyntax.pp.header
# These files are symlinked in the repo
cp mes/module/srfi/srfi-9-struct.mes mes/module/srfi/srfi-9.mes
cp mes/module/srfi/srfi-9/gnu-struct.mes mes/module/srfi/srfi-9/gnu.mes
# Remove environment impurities
__GUILE_LOAD_PATH="\"''${MES_PREFIX}/mes/module:''${MES_PREFIX}/module:${nyacc.guilePath}\""
boot0_scm=mes/module/mes/boot-0.scm
guile_mes=mes/module/mes/guile.mes
replace --file ''${boot0_scm} --output ''${boot0_scm} --match-on "(getenv \"GUILE_LOAD_PATH\")" --replace-with ''${__GUILE_LOAD_PATH}
replace --file ''${guile_mes} --output ''${guile_mes} --match-on "(getenv \"GUILE_LOAD_PATH\")" --replace-with ''${__GUILE_LOAD_PATH}
module_mescc_scm=module/mescc/mescc.scm
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"M1\")" --replace-with "\"${mescc-tools}/bin/M1\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"HEX2\")" --replace-with "\"${mescc-tools}/bin/hex2\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"BLOOD_ELF\")" --replace-with "\"${mescc-tools}/bin/blood-elf\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"srcdest\")" --replace-with "\"''${MES_PREFIX}\""
mes_c=src/mes.c
replace --file ''${mes_c} --output ''${mes_c} --match-on "getenv (\"MES_PREFIX\")" --replace-with "\"''${MES_PREFIX}\""
replace --file ''${mes_c} --output ''${mes_c} --match-on "getenv (\"srcdest\")" --replace-with "\"''${MES_PREFIX}\""
# Increase runtime resource limits
gc_c=src/gc.c
replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_ARENA\")" --replace-with "\"100000000\""
replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_MAX_ARENA\")" --replace-with "\"100000000\""
replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_STACK\")" --replace-with "\"6000000\""
# Create mescc.scm
mescc_in=scripts/mescc.scm.in
replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"MES_PREFIX\")" --replace-with "\"''${MES_PREFIX}\""
replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"includedir\")" --replace-with "\"''${MES_PREFIX}/include\""
replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"libdir\")" --replace-with "\"''${MES_PREFIX}/lib\""
replace --file ''${mescc_in} --output ''${mescc_in} --match-on @prefix@ --replace-with ''${MES_PREFIX}
replace --file ''${mescc_in} --output ''${mescc_in} --match-on @VERSION@ --replace-with ${version}
replace --file ''${mescc_in} --output ''${mescc_in} --match-on @mes_cpu@ --replace-with x86
replace --file ''${mescc_in} --output ''${mescc_in} --match-on @mes_kernel@ --replace-with linux
mkdir -p ''${bin}/bin
cp ''${mescc_in} ''${bin}/bin/mescc.scm
# Build mes-m2
kaem --verbose --strict --file kaem.x86
cp bin/mes-m2 ''${bin}/bin/mes-m2
chmod 555 ''${bin}/bin/mes-m2
'';
srcPrefix = "${srcPost.out}/mes-${version}";
cc = "${srcPost.bin}/bin/mes-m2";
ccArgs = [
"-e"
"main"
"${srcPost.bin}/bin/mescc.scm"
"--"
"-D"
"HAVE_CONFIG_H=1"
"-I"
"${srcPrefix}/include"
"-I"
"${srcPrefix}/include/linux/x86"
];
CC = toString ([ cc ] ++ ccArgs);
stripExt = source: lib.replaceStrings [ ".c" ] [ "" ] (baseNameOf source);
compile =
source:
kaem.runCommand (stripExt source) { } ''
mkdir ''${out}
cd ''${out}
${CC} -c ${srcPrefix}/${source}
'';
crt1 = compile "/lib/linux/x86-mes-mescc/crt1.c";
getRes = suffix: res: "${res}/${res.name}${suffix}";
archive = out: sources: "catm ${out} ${lib.concatMapStringsSep " " (getRes ".o") sources}";
sourceArchive = out: sources: "catm ${out} ${lib.concatMapStringsSep " " (getRes ".s") sources}";
mkLib =
libname: sources:
let
os = map compile sources;
in
kaem.runCommand "${pname}-${libname}-${version}"
{
inherit meta;
}
''
LIBDIR=''${out}/lib
mkdir -p ''${LIBDIR}
cd ''${LIBDIR}
${archive "${libname}.a" os}
${sourceArchive "${libname}.s" os}
'';
libc-mini = mkLib "libc-mini" libc_mini_SOURCES;
libmescc = mkLib "libmescc" libmescc_SOURCES;
libc = mkLib "libc" libc_SOURCES;
libc_tcc = mkLib "libc+tcc" libc_tcc_SOURCES;
# Recompile Mes and Mes C library using mes-m2 bootstrapped Mes
libs =
kaem.runCommand "${pname}-m2-libs-${version}"
{
inherit pname version;
passthru.tests.get-version =
result:
kaem.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/mes --version
mkdir ''${out}
'';
inherit meta;
}
''
LIBDIR=''${out}/lib
mkdir -p ''${out} ''${LIBDIR}
mkdir -p ''${LIBDIR}/x86-mes
# crt1.o
cp ${crt1}/crt1.o ''${LIBDIR}/x86-mes
cp ${crt1}/crt1.s ''${LIBDIR}/x86-mes
# libc-mini.a
cp ${libc-mini}/lib/libc-mini.a ''${LIBDIR}/x86-mes
cp ${libc-mini}/lib/libc-mini.s ''${LIBDIR}/x86-mes
# libmescc.a
cp ${libmescc}/lib/libmescc.a ''${LIBDIR}/x86-mes
cp ${libmescc}/lib/libmescc.s ''${LIBDIR}/x86-mes
# libc.a
cp ${libc}/lib/libc.a ''${LIBDIR}/x86-mes
cp ${libc}/lib/libc.s ''${LIBDIR}/x86-mes
# libc+tcc.a
cp ${libc_tcc}/lib/libc+tcc.a ''${LIBDIR}/x86-mes
cp ${libc_tcc}/lib/libc+tcc.s ''${LIBDIR}/x86-mes
'';
# Build mes itself
compiler =
kaem.runCommand "${pname}-${version}"
{
inherit pname version;
passthru.tests.get-version =
result:
kaem.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/mes --version
mkdir ''${out}
'';
inherit meta;
}
''
mkdir -p ''${out}/bin
${srcPost.bin}/bin/mes-m2 -e main ${srcPost.bin}/bin/mescc.scm -- \
-L ''${srcPrefix}/lib \
-L ${libs}/lib \
-lc \
-lmescc \
-nostdlib \
-o ''${out}/bin/mes \
${libs}/lib/x86-mes/crt1.o \
${lib.concatMapStringsSep " " (getRes ".o") (map compile mes_SOURCES)}
'';
in
{
inherit
src
srcPost
srcPrefix
nyacc
;
inherit compiler libs;
}

View File

@@ -0,0 +1,94 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash coreutils gnutar
# Generate a sources.nix for a version of GNU mes. Creates lists of source files
# from build-aux/configure-lib.sh.
#
# You may point this tool at a manually downloaded tarball, but more ideal is
# using the source tarball from Nixpkgs. For example:
#
# MES_TARBALL="$(nix-build --no-link -A minimal-bootstrap.mes.src ../../../../..)"
# ./gen-sources.sh "$MES_TARBALL" > ./new-sources.nix
set -eu
# Supported platforms
ARCHS="x86"
KERNELS="linux"
COMPILERS="mescc gcc"
format() {
echo "["
echo $* | xargs printf ' "%s"\n'
echo " ]"
}
gen_sources() {
# Configuration variables used by configure-lib.sh
export mes_libc=mes
export mes_cpu=$1
export mes_kernel=$2
export compiler=$3
# Populate source file lists
source $CONFIGURE_LIB_SH
cat <<EOF
$mes_cpu.$mes_kernel.$compiler = {
libc_mini_SOURCES = $(format $libc_mini_SOURCES);
libmescc_SOURCES = $(format $libmescc_SOURCES);
libtcc1_SOURCES = $(format $libtcc1_SOURCES);
libc_SOURCES = $(format $libc_SOURCES);
libc_tcc_SOURCES = $(format $libc_tcc_SOURCES);
libc_gnu_SOURCES = $(format $libc_gnu_SOURCES);
mes_SOURCES = $(format $mes_SOURCES);
};
EOF
}
MES_TARBALL=$1
if [ ! -f $MES_TARBALL ]; then
echo "Provide path to mes-x.x.x.tar.gz as first argument" >&2
exit 1
fi
echo "Generating sources.nix from $MES_TARBALL" >&2
TMP=$(mktemp -d)
cd $TMP
echo "Workdir: $TMP" >&2
echo "Extracting $MES_TARBALL" >&2
tar --strip-components 1 -xf $MES_TARBALL
CONFIGURE_LIB_SH="$TMP/build-aux/configure-lib.sh"
if [ ! -f $CONFIGURE_LIB_SH ]; then
echo "Could not find mes's configure-lib.sh script at $CONFIGURE_LIB_SH" >&2
exit 1
fi
# Create dummy config expected by configure-lib.sh
touch config.sh
chmod +x config.sh
echo "Configuring with $CONFIGURE_LIB_SH" >&2
cat <<EOF
# This file is generated by ./gen-sources.sh.
# Do not edit!
{
EOF
for arch in $ARCHS; do
for kernel in $KERNELS; do
for compiler in $COMPILERS; do
gen_sources $arch $kernel $compiler
done
done
done
cat <<EOF
}
EOF

View File

@@ -0,0 +1,63 @@
{
lib,
kaem,
ln-boot,
mes,
mes-libc,
}:
let
pname = "mes-libc";
inherit (mes.compiler) version;
sources = (import ./sources.nix).x86.linux.gcc;
inherit (sources) libtcc1_SOURCES libc_gnu_SOURCES;
# Concatenate all source files into a convenient bundle
# "gcc" variants of source files (eg. "lib/linux/x86-mes-gcc") can also be
# compiled by tinycc
#
# Passing this many arguments is too much for kaem so we need to split
# the operation in two
firstLibc = lib.take 100 libc_gnu_SOURCES;
lastLibc = lib.drop 100 libc_gnu_SOURCES;
in
kaem.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [ ln-boot ];
passthru.CFLAGS = "-DHAVE_CONFIG_H=1 -I${mes-libc}/include -I${mes-libc}/include/linux/x86";
meta = with lib; {
description = "Mes C Library";
homepage = "https://www.gnu.org/software/mes";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = [ "i686-linux" ];
};
}
''
cd ${mes.srcPrefix}
# mescc compiled libc.a
mkdir -p ''${out}/lib/x86-mes
# libc.c
catm ''${TMPDIR}/first.c ${lib.concatStringsSep " " firstLibc}
catm ''${out}/lib/libc.c ''${TMPDIR}/first.c ${lib.concatStringsSep " " lastLibc}
# crt{1,n,i}.c
cp lib/linux/x86-mes-gcc/crt1.c ''${out}/lib
cp lib/linux/x86-mes-gcc/crtn.c ''${out}/lib
cp lib/linux/x86-mes-gcc/crti.c ''${out}/lib
# libtcc1.c
catm ''${out}/lib/libtcc1.c ${lib.concatStringsSep " " libtcc1_SOURCES}
# getopt.c
cp lib/posix/getopt.c ''${out}/lib/libgetopt.c
# Install headers
ln -s ${mes.srcPrefix}/include ''${out}/include
''

View File

@@ -0,0 +1,42 @@
{
lib,
fetchurl,
kaem,
nyacc,
}:
let
pname = "nyacc";
# NYACC is a tightly coupled dependency of mes. This version is known to work
# with mes 0.25.
# https://git.savannah.gnu.org/cgit/mes.git/tree/INSTALL?h=v0.25#n31
version = "1.00.2";
src = fetchurl {
url = "mirror://savannah/nyacc/nyacc-${version}.tar.gz";
sha256 = "065ksalfllbdrzl12dz9d9dcxrv97wqxblslngsc6kajvnvlyvpk";
};
in
kaem.runCommand "${pname}-${version}"
{
inherit pname version;
passthru.guilePath = "${nyacc}/share/${pname}-${version}/module";
meta = with lib; {
description = "Modules for generating parsers and lexical analyzers";
longDescription = ''
Not Yet Another Compiler Compiler is a set of guile modules for
generating computer language parsers and lexical analyzers.
'';
homepage = "https://savannah.nongnu.org/projects/nyacc";
license = licenses.lgpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.all;
};
}
''
ungz --file ${src} --output nyacc.tar
mkdir -p ''${out}/share
cd ''${out}/share
untar --file ''${NIX_BUILD_TOP}/nyacc.tar
''

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,119 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
tinycc,
gnumake,
gnupatch,
gnused,
gnugrep,
gnutar,
gzip,
}:
let
inherit (import ./common.nix { inherit lib; }) pname meta;
version = "1.1.24";
src = fetchurl {
url = "https://musl.libc.org/releases/musl-${version}.tar.gz";
hash = "sha256-E3DJqBKyzyp9koAlEMygBYzDfmanvt1wBR8KNAFQIqM=";
};
# Thanks to the live-bootstrap project!
# See https://github.com/fosslinux/live-bootstrap/blob/d98f97e21413efc32c770d0356f1feda66025686/sysa/musl-1.1.24/musl-1.1.24.sh
liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/d98f97e21413efc32c770d0356f1feda66025686/sysa/musl-1.1.24";
patches = [
(fetchurl {
url = "${liveBootstrap}/patches/avoid_set_thread_area.patch";
hash = "sha256-TsbBZXk4/KMZG9EKi7cF+sullVXrxlizLNH0UHGXsPs=";
})
(fetchurl {
url = "${liveBootstrap}/patches/avoid_sys_clone.patch";
hash = "sha256-/ZmH64J57MmbxdfQ4RNjamAiBdkImMTlHsHdgV4gMj4=";
})
(fetchurl {
url = "${liveBootstrap}/patches/fenv.patch";
hash = "sha256-vMVGjoN4deAJW5gsSqA207SJqAbvhrnOsGK49DdEiTI=";
})
(fetchurl {
url = "${liveBootstrap}/patches/makefile.patch";
hash = "sha256-03iYBAUnsrEdLIIhhhq5mM6BGnPn2EfUmIHu51opxbw=";
})
(fetchurl {
url = "${liveBootstrap}/patches/musl_weak_symbols.patch";
hash = "sha256-/d9a2eUkpe9uyi1ye6T4CiYc9MR3FZ9na0Gb90+g4v0=";
})
(fetchurl {
url = "${liveBootstrap}/patches/set_thread_area.patch";
hash = "sha256-RIZYqbbRSx4X/0iFUhriwwBRmoXVR295GNBUjf2UrM0=";
})
(fetchurl {
url = "${liveBootstrap}/patches/sigsetjmp.patch";
hash = "sha256-wd2Aev1zPJXy3q933aiup5p1IMKzVJBquAyl3gbK4PU=";
})
# FIXME: this patch causes the build to fail
# (fetchurl {
# url = "${liveBootstrap}/patches/stdio_flush_on_exit.patch";
# hash = "sha256-/z5ze3h3QTysay8nRvyvwPv3pmTcKptdkBIaMCoeLDg=";
# })
# HACK: always flush stdio immediately
./always-flush.patch
(fetchurl {
url = "${liveBootstrap}/patches/va_list.patch";
hash = "sha256-UmcMIl+YCi3wIeVvjbsCyqFlkyYsM4ECNwTfXP+s7vg=";
})
];
in
bash.runCommand "${pname}-${version}"
{
inherit pname version meta;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnupatch
gnused
gnugrep
gnutar
gzip
];
}
''
# Unpack
tar xzf ${src}
cd musl-${version}
# Patch
${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches}
# tcc does not support complex types
rm -rf src/complex
# Configure fails without this
mkdir -p /dev
# https://github.com/ZilchOS/bootstrap-from-tcc/blob/2e0c68c36b3437386f786d619bc9a16177f2e149/using-nix/2a3-intermediate-musl.nix
sed -i 's|/bin/sh|${bash}/bin/bash|' \
tools/*.sh
chmod 755 tools/*.sh
# patch popen/system to search in PATH instead of hardcoding /bin/sh
sed -i 's|posix_spawn(&pid, "/bin/sh",|posix_spawnp(\&pid, "sh",|' \
src/stdio/popen.c src/process/system.c
sed -i 's|execl("/bin/sh", "sh", "-c",|execlp("sh", "-c",|'\
src/misc/wordexp.c
# Configure
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config} \
--disable-shared \
CC=tcc
# Build
make AR="tcc -ar" RANLIB=true CFLAGS="-DSYSCALL_NO_TLS"
# Install
make install
cp ${tinycc.libs}/lib/libtcc1.a $out/lib
''

View File

@@ -0,0 +1,12 @@
diff --git src/env/__libc_start_main.c src/env/__libc_start_main.c
index 8fbe526..9476c22 100644
--- src/env/__libc_start_main.c
+++ src/env/__libc_start_main.c
@@ -91,6 +91,7 @@ static int libc_start_main_stage2(int (*main)(int,char **,char **), int argc, ch
__libc_start_init();
/* Pass control to the application */
+ setbuf(stdout, NULL);
exit(main(argc, argv, envp));
return 0;
}

View File

@@ -0,0 +1,13 @@
{ lib }:
{
pname = "musl";
meta = with lib; {
description = "Efficient, small, quality libc implementation";
homepage = "https://musl.libc.org";
license = licenses.mit;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
};
}

View File

@@ -0,0 +1,91 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
gcc,
binutils,
gnumake,
gnugrep,
gnused,
gnutar,
gzip,
}:
let
inherit (import ./common.nix { inherit lib; }) pname meta;
version = "1.2.4";
src = fetchurl {
url = "https://musl.libc.org/releases/musl-${version}.tar.gz";
hash = "sha256-ejXq4z1TcqfA2hGI3nmHJvaIJVE7euPr6XqqpSEU8Dk=";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version meta;
nativeBuildInputs = [
gcc
binutils
gnumake
gnused
gnugrep
gnutar
gzip
];
passthru.tests.hello-world =
result:
bash.runCommand "${pname}-simple-program-${version}"
{
nativeBuildInputs = [
gcc
binutils
result
];
}
''
cat <<EOF >> test.c
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
EOF
musl-gcc -o test test.c
./test
mkdir $out
'';
}
''
# Unpack
tar xzf ${src}
cd musl-${version}
# Patch
# https://github.com/ZilchOS/bootstrap-from-tcc/blob/2e0c68c36b3437386f786d619bc9a16177f2e149/using-nix/2a3-intermediate-musl.nix
sed -i 's|/bin/sh|${bash}/bin/bash|' \
tools/*.sh
# patch popen/system to search in PATH instead of hardcoding /bin/sh
sed -i 's|posix_spawn(&pid, "/bin/sh",|posix_spawnp(\&pid, "sh",|' \
src/stdio/popen.c src/process/system.c
sed -i 's|execl("/bin/sh", "sh", "-c",|execlp("sh", "-c",|'\
src/misc/wordexp.c
# Configure
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config} \
--syslibdir=$out/lib \
--enable-wrapper
# Build
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
sed -i 's|/bin/sh|${bash}/bin/bash|' $out/bin/*
ln -s ../lib/libc.so $out/bin/ldd
''

View File

@@ -0,0 +1,97 @@
{
hostPlatform,
}:
rec {
name = "stage0-posix-${version}-source";
version = "1.6.0";
rev = "Release_${version}";
outputHashAlgo = "sha256";
outputHash = "sha256-epUaShjKiAd749ICvc6rS6WhUkS8R4heKuPdwUjEtsQ=";
/*
Since `make-minimal-bootstrap-sources` requires nixpkgs and nix it
will create a circular dependency if it is used in place of the
binary bootstrap-files. To break the circular dependency,
`minimal-bootstrap-sources` extends `make-minimal-bootstrap-sources`
by adding Fixed Output Derivation (FOD) attributes. These cause
the builder to be skipped if the expected output is found (by
its hash) in the store or on a substituter.
# How do I update the hash?
Run the following command:
```
nix --extra-experimental-features nix-command hash path $(nix build --print-out-paths -f '<nixpkgs>' make-minimal-bootstrap-sources)
```
# Why do we need this `.nar` archive?
This archive exists only because of a quirk/limitation of Nix: in
restricted mode the builtin fetchers can download only single
files; they have no way to unpack multi-file archives except for
NAR archives:
https://github.com/NixOS/nixpkgs/pull/232576#issuecomment-1592415619
# Why don't we have to upload this to tarballs.nixos.org like the binary bootstrap-files did?
Unlike this archive, the binary bootstrap-files contained binaries,
which meant that we had to:
1. Make sure they came from a trusted builder (Hydra)
2. Keep careful track of exactly what toolchain (i.e. nixpkgs
commit) that builder used to create them.
3. Keep copies of the built binaries, in case the toolchains that
produced them failed to be perfectly deterministic.
The curated archives at tarballs.nixos.org exist in order to
satisfy these requirements.
The second point created a significant burden: since the nixpkgs
toolchain used to build a given copy of the binary bootstrap-files
itself used a *previous* copy of the bootstrap-files, this meant
we had to track the provenance of all bootstrap-files tarballs
ever used, for all eternity. There was no explanation of where
the "original" bootstrap-files came from: turtles all the way
down. In spite of all this effort we still can't be sure of our
ability to reproduce the binary bootstrap-files, since the
compilers that built them don't always produce exactly bit-for-bit
deterministic results.
Since this archive contains no binaries and uses a format (NAR)
specifically designed for bit-exact reproducibility, none of the
requirements above apply to `minimal-bootstrap-sources`.
*/
minimal-bootstrap-sources = derivation {
inherit name;
system = hostPlatform.system;
outputHashMode = "recursive";
inherit outputHashAlgo outputHash;
# This builder always fails, but fortunately Nix will print the
# "builder", which is really the error message that we want the
# user to see.
builder = ''
#
#
# Neither your store nor your substituters seems to have:
#
# ${placeholder "out"}
#
# You can create this path from an already-bootstrapped nixpkgs
# using the following command:
#
# nix-build '<nixpkgs>' -A make-minimal-bootstrap-sources
#
# Or, if you prefer, you can create this file using only `git`,
# `nix`, and `xz`. For the commands needed in order to do this,
# see `make-bootstrap-sources.nix`. Once you have the manual
# result, do:
#
# nix-store --add-fixed --recursive ${outputHashAlgo} ./${name}
#
# to add it to your store.
'';
};
}

View File

@@ -0,0 +1,42 @@
{
lib,
newScope,
}:
lib.makeScope newScope (
self: with self; {
inherit (callPackage ./platforms.nix { })
platforms
stage0Arch
m2libcArch
m2libcOS
baseAddress
;
inherit (self.callPackage ./bootstrap-sources.nix { }) version minimal-bootstrap-sources;
src = minimal-bootstrap-sources;
m2libc = src + "/M2libc";
hex0 = callPackage ./hex0.nix { };
inherit (self.hex0) hex0-seed;
kaem = callPackage ./kaem { };
kaem-minimal = callPackage ./kaem/minimal.nix { };
mescc-tools-boot = callPackage ./mescc-tools-boot.nix { };
inherit (self.mescc-tools-boot)
blood-elf-0
hex2
kaem-unwrapped
M1
M2
;
mescc-tools = callPackage ./mescc-tools { };
mescc-tools-extra = callPackage ./mescc-tools-extra { };
}
)

View File

@@ -0,0 +1,52 @@
{
lib,
derivationWithMeta,
hostPlatform,
src,
version,
platforms,
stage0Arch,
}:
let
hash =
{
"AArch64" = "sha256-XTPsoKeI6wTZAF0UwEJPzuHelWOJe//wXg4HYO0dEJo=";
"AMD64" = "sha256-RCgK9oZRDQUiWLVkcIBSR2HeoB+Bh0czthrpjFEkCaY=";
"x86" = "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8=";
}
.${stage0Arch} or (throw "Unsupported system: ${hostPlatform.system}");
# Pinned from https://github.com/oriansj/stage0-posix/commit/3189b5f325b7ef8b88e3edec7c1cde4fce73c76c
# This 256 byte seed is the only pre-compiled binary in the bootstrap chain.
hex0-seed = import <nix/fetchurl.nix> {
name = "hex0-seed";
url = "https://github.com/oriansj/bootstrap-seeds/raw/b1263ff14a17835f4d12539226208c426ced4fba/POSIX/${stage0Arch}/hex0-seed";
executable = true;
inherit hash;
};
in
derivationWithMeta {
inherit version;
pname = "hex0";
builder = hex0-seed;
args = [
"${src}/${stage0Arch}/hex0_${stage0Arch}.hex0"
(placeholder "out")
];
meta = with lib; {
description = "Minimal assembler for bootstrapping";
homepage = "https://github.com/oriansj/stage0-posix";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
inherit platforms;
};
passthru = { inherit hex0-seed; };
# Ensure the untrusted hex0-seed binary produces a known-good hex0
outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = hash;
}

View File

@@ -0,0 +1,64 @@
{
lib,
derivationWithMeta,
writeText,
kaem,
kaem-unwrapped,
mescc-tools,
mescc-tools-extra,
version,
platforms,
}:
# Once mescc-tools-extra is available we can install kaem at /bin/kaem
# to make it findable in environments
derivationWithMeta {
inherit version kaem-unwrapped;
pname = "kaem";
builder = kaem-unwrapped;
args = [
"--verbose"
"--strict"
"--file"
(builtins.toFile "kaem-wrapper.kaem" ''
mkdir -p ''${out}/bin
cp ''${kaem-unwrapped} ''${out}/bin/kaem
chmod 555 ''${out}/bin/kaem
'')
];
PATH = lib.makeBinPath [ mescc-tools-extra ];
passthru.runCommand =
name: env: buildCommand:
derivationWithMeta (
{
inherit name;
builder = "${kaem}/bin/kaem";
args = [
"--verbose"
"--strict"
"--file"
(writeText "${name}-builder" buildCommand)
];
PATH = lib.makeBinPath (
(env.nativeBuildInputs or [ ])
++ [
kaem
mescc-tools
mescc-tools-extra
]
);
}
// (removeAttrs env [ "nativeBuildInputs" ])
);
meta = with lib; {
description = "Minimal build tool for running scripts on systems that lack any shell";
homepage = "https://github.com/oriansj/mescc-tools";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
inherit platforms;
};
}

View File

@@ -0,0 +1,26 @@
{
lib,
derivationWithMeta,
src,
hex0,
version,
platforms,
stage0Arch,
}:
derivationWithMeta {
inherit version;
pname = "kaem-minimal";
builder = hex0;
args = [
"${src}/${stage0Arch}/kaem-minimal.hex0"
(placeholder "out")
];
meta = with lib; {
description = "First stage minimal scriptable build tool for bootstrapping";
homepage = "https://github.com/oriansj/stage0-posix";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
inherit platforms;
};
}

View File

@@ -0,0 +1,61 @@
# Packaged source files for the first bootstrapping stage.
#
# We don't have access to utilities such as fetchgit and fetchzip since this
# is this is part of the bootstrap process and would introduce a circular
# dependency. The only tool we have to fetch source trees is `import <nix/fetchurl.nix>`
# with the unpack option, taking a NAR file as input. This requires source
# tarballs to be repackaged.
#
# To build:
#
# nix-build '<nixpkgs>' -A make-minimal-bootstrap-sources
#
{
lib,
hostPlatform,
fetchFromGitHub,
fetchpatch,
}:
let
expected = import ./bootstrap-sources.nix { inherit hostPlatform; };
in
fetchFromGitHub {
inherit (expected) name rev;
owner = "oriansj";
repo = "stage0-posix";
sha256 = expected.outputHash;
fetchSubmodules = true;
postFetch = ''
# Seed binaries will be fetched separately
echo "Removing seed binaries"
rm -rf $out/bootstrap-seeds/*
# Remove vendored/duplicate M2libc's
echo "Removing duplicate M2libc"
rm -rf \
$out/M2-Mesoplanet/M2libc \
$out/M2-Planet/M2libc \
$out/mescc-tools/M2libc \
$out/mescc-tools-extra/M2libc
# aarch64: syscall: mkdir -> mkdirat
# https://github.com/oriansj/M2libc/pull/17
patch -Np1 -d $out/M2libc -i ${
(fetchpatch {
url = "https://github.com/oriansj/M2libc/commit/ff7c3023b3ab6cfcffc5364620b25f8d0279e96b.patch";
hash = "sha256-QAKddv4TixIQHpFa9SVu9fAkeKbzhQaxjaWzW2yJy7A=";
})
}
'';
meta = with lib; {
description = "Packaged sources for the first bootstrapping stage";
homepage = "https://github.com/oriansj/stage0-posix";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
platforms = platforms.all;
};
}

View File

@@ -0,0 +1,608 @@
# Mes --- Maxwell Equations of Software
# Copyright © 2017,2019 Jan Nieuwenhuizen <janneke@gnu.org>
# Copyright © 2017,2019 Jeremiah Orians
#
# This file is part of Mes.
#
# Mes is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# Mes is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mes. If not, see <http://www.gnu.org/licenses/>.
# This is a translation of stage0-posix/stage0-posix/x86/mescc-tools-mini-kaem.kaem to nix
# https://github.com/oriansj/stage0-posix-x86/blob/56e6b8df3e95f4bc04f8b420a4cd8c82c70b9efa/mescc-tools-mini-kaem.kaem
#
# We have access to mini-kaem at this point but it doesn't support substituting
# environment variables. Without variables there's no way of passing in store inputs,
# or the $out path, other than as command line arguments directly
# Warning all binaries prior to the use of blood-elf will not be readable by
# Objdump, you may need to use ndism or gdb to view the assembly in the binary.
{
lib,
derivationWithMeta,
hostPlatform,
hex0,
m2libc,
src,
version,
platforms,
stage0Arch,
m2libcArch,
baseAddress,
}:
rec {
out = placeholder "out";
endianFlag = if hostPlatform.isLittleEndian then "--little-endian" else "--big-endian";
bloodFlags = lib.optional hostPlatform.is64bit "--64";
run =
pname: builder: args:
derivationWithMeta {
inherit
pname
version
builder
args
;
meta = with lib; {
description = "Collection of tools written for use in bootstrapping";
homepage = "https://github.com/oriansj/stage0-posix";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
inherit platforms;
};
};
################################
# Phase-1 Build hex1 from hex0 #
################################
hex1 = run "hex1" hex0 [
"${src}/${stage0Arch}/hex1_${stage0Arch}.hex0"
out
];
# hex1 adds support for single character labels and is available in various forms
# in mescc-tools/x86_bootstrap to allow you various ways to verify correctness
################################
# Phase-2 Build hex2 from hex1 #
################################
hex2-0 = run "hex2" hex1 [
"${src}/${stage0Arch}/hex2_${stage0Arch}.hex1"
out
];
# hex2 adds support for long labels and absolute addresses thus allowing it
# to function as an effective linker for later stages of the bootstrap
# This is a minimal version which will be used to bootstrap a much more advanced
# version in a later stage.
#################################
# Phase-2b Build catm from hex2 #
#################################
catm =
if hostPlatform.isAarch64 then
run "catm" hex1 [
"${src}/${stage0Arch}/catm_${stage0Arch}.hex1"
out
]
else
run "catm" hex2-0 [
"${src}/${stage0Arch}/catm_${stage0Arch}.hex2"
out
];
# catm removes the need for cat or shell support for redirection by providing
# equivalent functionality via catm output_file input1 input2 ... inputN
##############################
# Phase-3 Build M0 from hex2 #
##############################
M0_hex2 = run "M0.hex2" catm [
out
"${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2"
"${src}/${stage0Arch}/M0_${stage0Arch}.hex2"
];
M0 = run "M0" hex2-0 [
M0_hex2
out
];
# M0 is the architecture specific version of M1 and is by design single
# architecture only and will be replaced by the C code version of M1
################################
# Phase-4 Build cc_arch from M0 #
################################
cc_arch-0_hex2 = run "cc_arch-0.hex2" M0 [
"${src}/${stage0Arch}/cc_${m2libcArch}.M1"
out
];
cc_arch-1_hex2 = run "cc_arch-1.hex2" catm [
out
"${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2"
cc_arch-0_hex2
];
cc_arch = run "cc_arch" hex2-0 [
cc_arch-1_hex2
out
];
########################################
# Phase-5 Build M2-Planet from cc_arch #
########################################
M2-0_c = run "M2-0.c" catm [
out
"${m2libc}/${m2libcArch}/linux/bootstrap.c"
"${src}/M2-Planet/cc.h"
"${m2libc}/bootstrappable.c"
"${src}/M2-Planet/cc_globals.c"
"${src}/M2-Planet/cc_reader.c"
"${src}/M2-Planet/cc_strings.c"
"${src}/M2-Planet/cc_types.c"
"${src}/M2-Planet/cc_core.c"
"${src}/M2-Planet/cc_macro.c"
"${src}/M2-Planet/cc.c"
];
M2-0_M1 = run "M2-0.M1" cc_arch [
M2-0_c
out
];
M2-0-0_M1 = run "M2-0-0.M1" catm [
out
"${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1"
"${m2libc}/${m2libcArch}/libc-core.M1"
M2-0_M1
];
M2-0_hex2 = run "M2-0.hex2" M0 [
M2-0-0_M1
out
];
M2-0-0_hex2 = run "M2-0-0.hex2" catm [
out
"${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2"
M2-0_hex2
];
M2 = run "M2" hex2-0 [
M2-0-0_hex2
out
];
############################################
# Phase-6 Build blood-elf-0 from C sources #
############################################
blood-elf-0_M1 = run "blood-elf-0.M1" M2 [
"--architecture"
m2libcArch
"-f"
"${m2libc}/${m2libcArch}/linux/bootstrap.c"
"-f"
"${m2libc}/bootstrappable.c"
"-f"
"${src}/mescc-tools/stringify.c"
"-f"
"${src}/mescc-tools/blood-elf.c"
"--bootstrap-mode"
"-o"
out
];
blood-elf-0-0_M1 = run "blood-elf-0-0.M1" catm [
out
"${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1"
"${m2libc}/${m2libcArch}/libc-core.M1"
blood-elf-0_M1
];
blood-elf-0_hex2 = run "blood-elf-0.hex2" M0 [
blood-elf-0-0_M1
out
];
blood-elf-0-0_hex2 = run "blood-elf-0-0.hex2" catm [
out
"${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2"
blood-elf-0_hex2
];
blood-elf-0 = run "blood-elf-0" hex2-0 [
blood-elf-0-0_hex2
out
];
# This is the last stage where the binaries will not have debug info
# and the last piece built that isn't part of the output binaries
#####################################
# Phase-7 Build M1-0 from C sources #
#####################################
M1-macro-0_M1 = run "M1-macro-0.M1" M2 [
"--architecture"
m2libcArch
"-f"
"${m2libc}/${m2libcArch}/linux/bootstrap.c"
"-f"
"${m2libc}/bootstrappable.c"
"-f"
"${src}/mescc-tools/stringify.c"
"-f"
"${src}/mescc-tools/M1-macro.c"
"--bootstrap-mode"
"--debug"
"-o"
out
];
M1-macro-0-footer_M1 = run "M1-macro-0-footer.M1" blood-elf-0 (
bloodFlags
++ [
"-f"
M1-macro-0_M1
endianFlag
"-o"
out
]
);
M1-macro-0-0_M1 = run "M1-macro-0-0.M1" catm [
out
"${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1"
"${m2libc}/${m2libcArch}/libc-core.M1"
M1-macro-0_M1
M1-macro-0-footer_M1
];
M1-macro-0_hex2 = run "M1-macro-0.hex2" M0 [
M1-macro-0-0_M1
out
];
M1-macro-0-0_hex2 = run "M1-macro-0-0.hex2" catm [
out
"${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2"
M1-macro-0_hex2
];
M1-0 = run "M1-0" hex2-0 [
M1-macro-0-0_hex2
out
];
# This is the last stage where catm will need to be used and the last stage where
# M0 is used, as we will being using it's much more powerful and cross-platform
# version with a bunch of extra goodies.
#######################################
# Phase-8 Build hex2-1 from C sources #
#######################################
hex2_linker-0_M1 = run "hex2_linker-0.M1" M2 [
"--architecture"
m2libcArch
"-f"
"${m2libc}/sys/types.h"
"-f"
"${m2libc}/stddef.h"
"-f"
"${m2libc}/${m2libcArch}/linux/unistd.c"
"-f"
"${m2libc}/${m2libcArch}/linux/fcntl.c"
"-f"
"${m2libc}/fcntl.c"
"-f"
"${m2libc}/${m2libcArch}/linux/sys/stat.c"
"-f"
"${m2libc}/stdlib.c"
"-f"
"${m2libc}/stdio.h"
"-f"
"${m2libc}/stdio.c"
"-f"
"${m2libc}/bootstrappable.c"
"-f"
"${src}/mescc-tools/hex2.h"
"-f"
"${src}/mescc-tools/hex2_linker.c"
"-f"
"${src}/mescc-tools/hex2_word.c"
"-f"
"${src}/mescc-tools/hex2.c"
"--debug"
"-o"
out
];
hex2_linker-0-footer_M1 = run "hex2_linker-0-footer.M1" blood-elf-0 (
bloodFlags
++ [
"-f"
hex2_linker-0_M1
endianFlag
"-o"
out
]
);
hex2_linker-0_hex2 = run "hex2_linker-0.hex2" M1-0 [
"--architecture"
m2libcArch
endianFlag
"-f"
"${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1"
"-f"
"${m2libc}/${m2libcArch}/libc-full.M1"
"-f"
hex2_linker-0_M1
"-f"
hex2_linker-0-footer_M1
"-o"
out
];
hex2_linker-0-0_hex2 = run "hex2_linker-0-0.hex2" catm [
out
"${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2"
hex2_linker-0_hex2
];
hex2-1 = run "hex2-1" hex2-0 [
hex2_linker-0-0_hex2
out
];
# This is the last stage where we will be using the handwritten hex2 and instead
# be using the far more powerful, cross-platform version with a bunch more goodies
###################################
# Phase-9 Build M1 from C sources #
###################################
M1-macro-1_M1 = run "M1-macro-1.M1" M2 [
"--architecture"
m2libcArch
"-f"
"${m2libc}/sys/types.h"
"-f"
"${m2libc}/stddef.h"
"-f"
"${m2libc}/${m2libcArch}/linux/fcntl.c"
"-f"
"${m2libc}/fcntl.c"
"-f"
"${m2libc}/${m2libcArch}/linux/unistd.c"
"-f"
"${m2libc}/string.c"
"-f"
"${m2libc}/stdlib.c"
"-f"
"${m2libc}/stdio.h"
"-f"
"${m2libc}/stdio.c"
"-f"
"${m2libc}/bootstrappable.c"
"-f"
"${src}/mescc-tools/stringify.c"
"-f"
"${src}/mescc-tools/M1-macro.c"
"--debug"
"-o"
out
];
M1-macro-1-footer_M1 = run "M1-macro-1-footer.M1" blood-elf-0 (
bloodFlags
++ [
"-f"
M1-macro-1_M1
endianFlag
"-o"
out
]
);
M1-macro-1_hex2 = run "M1-macro-1.hex2" M1-0 [
"--architecture"
m2libcArch
endianFlag
"-f"
"${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1"
"-f"
"${m2libc}/${m2libcArch}/libc-full.M1"
"-f"
M1-macro-1_M1
"-f"
M1-macro-1-footer_M1
"-o"
out
];
M1 = run "M1" hex2-1 [
"--architecture"
m2libcArch
endianFlag
"--base-address"
baseAddress
"-f"
"${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2"
"-f"
M1-macro-1_hex2
"-o"
out
];
######################################
# Phase-10 Build hex2 from C sources #
######################################
hex2_linker-2_M1 = run "hex2_linker-2.M1" M2 [
"--architecture"
m2libcArch
"-f"
"${m2libc}/sys/types.h"
"-f"
"${m2libc}/stddef.h"
"-f"
"${m2libc}/${m2libcArch}/linux/unistd.c"
"-f"
"${m2libc}/${m2libcArch}/linux/fcntl.c"
"-f"
"${m2libc}/fcntl.c"
"-f"
"${m2libc}/${m2libcArch}/linux/sys/stat.c"
"-f"
"${m2libc}/stdlib.c"
"-f"
"${m2libc}/stdio.h"
"-f"
"${m2libc}/stdio.c"
"-f"
"${m2libc}/bootstrappable.c"
"-f"
"${src}/mescc-tools/hex2.h"
"-f"
"${src}/mescc-tools/hex2_linker.c"
"-f"
"${src}/mescc-tools/hex2_word.c"
"-f"
"${src}/mescc-tools/hex2.c"
"--debug"
"-o"
out
];
hex2_linker-2-footer_M1 = run "hex2_linker-2-footer.M1" blood-elf-0 (
bloodFlags
++ [
"-f"
hex2_linker-2_M1
endianFlag
"-o"
out
]
);
hex2_linker-2_hex2 = run "hex2_linker-2.hex2" M1 [
"--architecture"
m2libcArch
endianFlag
"-f"
"${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1"
"-f"
"${m2libc}/${m2libcArch}/libc-full.M1"
"-f"
hex2_linker-2_M1
"-f"
hex2_linker-2-footer_M1
"-o"
out
];
hex2 = run "hex2" hex2-1 [
"--architecture"
m2libcArch
endianFlag
"--base-address"
baseAddress
"-f"
"${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2"
"-f"
hex2_linker-2_hex2
"-o"
out
];
######################################
# Phase-11 Build kaem from C sources #
######################################
kaem_M1 = run "kaem.M1" M2 [
"--architecture"
m2libcArch
"-f"
"${m2libc}/sys/types.h"
"-f"
"${m2libc}/stddef.h"
"-f"
"${m2libc}/string.c"
"-f"
"${m2libc}/${m2libcArch}/linux/unistd.c"
"-f"
"${m2libc}/${m2libcArch}/linux/fcntl.c"
"-f"
"${m2libc}/fcntl.c"
"-f"
"${m2libc}/stdlib.c"
"-f"
"${m2libc}/stdio.h"
"-f"
"${m2libc}/stdio.c"
"-f"
"${m2libc}/bootstrappable.c"
"-f"
"${src}/mescc-tools/Kaem/kaem.h"
"-f"
"${src}/mescc-tools/Kaem/variable.c"
"-f"
"${src}/mescc-tools/Kaem/kaem_globals.c"
"-f"
"${src}/mescc-tools/Kaem/kaem.c"
"--debug"
"-o"
out
];
kaem-footer_M1 = run "kaem-footer.M1" blood-elf-0 (
bloodFlags
++ [
"-f"
kaem_M1
endianFlag
"-o"
out
]
);
kaem_hex2 = run "kaem.hex2" M1 [
"--architecture"
m2libcArch
endianFlag
"-f"
"${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1"
"-f"
"${m2libc}/${m2libcArch}/libc-full.M1"
"-f"
kaem_M1
"-f"
kaem-footer_M1
"-o"
out
];
kaem-unwrapped = run "kaem-unwrapped" hex2 [
"--architecture"
m2libcArch
endianFlag
"-f"
"${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2"
"-f"
kaem_hex2
"--base-address"
baseAddress
"-o"
out
];
}

View File

@@ -0,0 +1,39 @@
# This is a modified version of mescc-tools-extra/mescc-tools-extra.kaem
# https://github.com/oriansj/mescc-tools-extra/blob/ec53af69d6d2119b47b369cd0ec37ac806e7ad60/mescc-tools-extra.kaem
# - Paths to build inputs have been changed for nix
# - Added additional step to create $out directory
## Copyright (C) 2017 Jeremiah Orians
## This file is part of mescc-tools.
##
## mescc-tools is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## mescc-tools is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
alias CC="${mescc-tools}/bin/M2-Mesoplanet --operating-system ${m2libcOS} --architecture ${m2libcArch} -f"
cd ${src}/mescc-tools-extra
# Create output folder
CC mkdir.c -o ${TMP}/mkdir
${TMP}/mkdir -p ${out}/bin
CC sha256sum.c -o ${out}/bin/sha256sum
CC match.c -o ${out}/bin/match
CC mkdir.c -o ${out}/bin/mkdir
CC untar.c -o ${out}/bin/untar
CC ungz.c -o ${out}/bin/ungz
CC unbz2.c -o ${out}/bin/unbz2
CC catm.c -o ${out}/bin/catm
CC cp.c -o ${out}/bin/cp
CC chmod.c -o ${out}/bin/chmod
CC rm.c -o ${out}/bin/rm
CC replace.c -o ${out}/bin/replace

View File

@@ -0,0 +1,36 @@
{
lib,
derivationWithMeta,
kaem-unwrapped,
mescc-tools,
src,
version,
platforms,
m2libcArch,
m2libcOS,
}:
derivationWithMeta {
inherit
version
src
mescc-tools
m2libcArch
m2libcOS
;
pname = "mescc-tools-extra";
builder = kaem-unwrapped;
args = [
"--verbose"
"--strict"
"--file"
./build.kaem
];
meta = with lib; {
description = "Collection of tools written for use in bootstrapping";
homepage = "https://github.com/oriansj/mescc-tools-extra";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
inherit platforms;
};
}

View File

@@ -0,0 +1,204 @@
# This is a modified version of stage0-posix/x86/mescc-tools-full-kaem.kaem
# https://github.com/oriansj/stage0-posix-x86/blob/56e6b8df3e95f4bc04f8b420a4cd8c82c70b9efa/mescc-tools-full-kaem.kaem
# - Paths to build inputs have been changed for nix
# Mes --- Maxwell Equations of Software
# Copyright © 2017,2019 Jan Nieuwenhuizen <janneke@gnu.org>
# Copyright © 2017,2019 Jeremiah Orians
#
# This file is part of Mes.
#
# Mes is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
#
# Mes is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Mes. If not, see <http://www.gnu.org/licenses/>.
${mkdir} -p ${out}/bin
${cp} ${M2} ${out}/bin/M2
${chmod} 0555 ${out}/bin/M2
${cp} ${M1} ${out}/bin/M1
${chmod} 0555 ${out}/bin/M1
${cp} ${hex2} ${out}/bin/hex2
${chmod} 0555 ${out}/bin/hex2
# M2-Mesoplanet searches for runtime dependencies in environment variables
# We can hardcode them with the "replace" utility from mescc-tools-extra
${replace} \
--file ${src}/M2-Mesoplanet/cc.c \
--output ./cc_patched.c \
--match-on "env_lookup(\"M2LIBC_PATH\")" \
--replace-with "\"${m2libc}\""
${replace} \
--file ${src}/M2-Mesoplanet/cc_spawn.c \
--output ./cc_spawn_patched.c \
--match-on "env_lookup(\"PATH\")" \
--replace-with "\"${out}/bin:\""
###############################################
# Phase-12 Build M2-Mesoplanet from M2-Planet #
###############################################
${M2} --architecture ${m2libcArch} \
-f ${m2libc}/sys/types.h \
-f ${m2libc}/stddef.h \
-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
-f ${m2libc}/fcntl.c \
-f ${m2libc}/${m2libcArch}/linux/unistd.c \
-f ${m2libc}/${m2libcArch}/linux/sys/stat.c \
-f ${m2libc}/stdlib.c \
-f ${m2libc}/stdio.h \
-f ${m2libc}/stdio.c \
-f ${m2libc}/string.c \
-f ${m2libc}/bootstrappable.c \
-f ${src}/M2-Mesoplanet/cc.h \
-f ${src}/M2-Mesoplanet/cc_globals.c \
-f ${src}/M2-Mesoplanet/cc_env.c \
-f ${src}/M2-Mesoplanet/cc_reader.c \
-f ./cc_spawn_patched.c \
-f ${src}/M2-Mesoplanet/cc_core.c \
-f ${src}/M2-Mesoplanet/cc_macro.c \
-f ./cc_patched.c \
--debug \
-o ./M2-Mesoplanet-1.M1
${blood-elf-0} ${endianFlag} ${bloodFlag} -f ./M2-Mesoplanet-1.M1 -o ./M2-Mesoplanet-1-footer.M1
${M1} --architecture ${m2libcArch} \
${endianFlag} \
-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
-f ${m2libc}/${m2libcArch}/libc-full.M1 \
-f ./M2-Mesoplanet-1.M1 \
-f ./M2-Mesoplanet-1-footer.M1 \
-o ./M2-Mesoplanet-1.hex2
${hex2} --architecture ${m2libcArch} \
${endianFlag} \
--base-address ${baseAddress} \
-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
-f ./M2-Mesoplanet-1.hex2 \
-o ${out}/bin/M2-Mesoplanet
#################################################
# Phase-13 Build final blood-elf from C sources #
#################################################
${M2} --architecture ${m2libcArch} \
-f ${m2libc}/sys/types.h \
-f ${m2libc}/stddef.h \
-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
-f ${m2libc}/fcntl.c \
-f ${m2libc}/${m2libcArch}/linux/unistd.c \
-f ${m2libc}/stdlib.c \
-f ${m2libc}/stdio.h \
-f ${m2libc}/stdio.c \
-f ${m2libc}/bootstrappable.c \
-f ${src}/mescc-tools/stringify.c \
-f ${src}/mescc-tools/blood-elf.c \
--debug \
-o ./blood-elf-1.M1
${blood-elf-0} ${endianFlag} ${bloodFlag} -f ./blood-elf-1.M1 -o ./blood-elf-1-footer.M1
${M1} --architecture ${m2libcArch} \
${endianFlag} \
-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
-f ${m2libc}/${m2libcArch}/libc-full.M1 \
-f ./blood-elf-1.M1 \
-f ./blood-elf-1-footer.M1 \
-o ./blood-elf-1.hex2
${hex2} --architecture ${m2libcArch} \
${endianFlag} \
--base-address ${baseAddress} \
-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
-f ./blood-elf-1.hex2 \
-o ${out}/bin/blood-elf
# Now we have our shipping debuggable blood-elf, the rest will be down hill from
# here as we have ALL of the core pieces of compiling and assembling debuggable
# programs in a debuggable form with corresponding C source code.
#############################################
# Phase-14 Build get_machine from C sources #
#############################################
${M2} --architecture ${m2libcArch} \
-f ${m2libc}/sys/types.h \
-f ${m2libc}/stddef.h \
-f ${m2libc}/${m2libcArch}/linux/unistd.c \
-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
-f ${m2libc}/fcntl.c \
-f ${m2libc}/stdlib.c \
-f ${m2libc}/stdio.h \
-f ${m2libc}/stdio.c \
-f ${m2libc}/bootstrappable.c \
-f ${src}/mescc-tools/get_machine.c \
--debug \
-o get_machine.M1
${out}/bin/blood-elf ${endianFlag} ${bloodFlag} -f ./get_machine.M1 -o ./get_machine-footer.M1
${M1} --architecture ${m2libcArch} \
${endianFlag} \
-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
-f ${m2libc}/${m2libcArch}/libc-full.M1 \
-f ./get_machine.M1 \
-f ./get_machine-footer.M1 \
-o ./get_machine.hex2
${hex2} --architecture ${m2libcArch} \
${endianFlag} \
--base-address ${baseAddress} \
-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
-f ./get_machine.hex2 \
-o ${out}/bin/get_machine
############################################
# Phase-15 Build M2-Planet from M2-Planet #
############################################
${M2} --architecture ${m2libcArch} \
-f ${m2libc}/sys/types.h \
-f ${m2libc}/stddef.h \
-f ${m2libc}/${m2libcArch}/linux/unistd.c \
-f ${m2libc}/${m2libcArch}/linux/fcntl.c \
-f ${m2libc}/fcntl.c \
-f ${m2libc}/stdlib.c \
-f ${m2libc}/stdio.h \
-f ${m2libc}/stdio.c \
-f ${m2libc}/bootstrappable.c \
-f ${src}/M2-Planet/cc.h \
-f ${src}/M2-Planet/cc_globals.c \
-f ${src}/M2-Planet/cc_reader.c \
-f ${src}/M2-Planet/cc_strings.c \
-f ${src}/M2-Planet/cc_types.c \
-f ${src}/M2-Planet/cc_core.c \
-f ${src}/M2-Planet/cc_macro.c \
-f ${src}/M2-Planet/cc.c \
--debug \
-o ./M2-1.M1
${out}/bin/blood-elf ${endianFlag} ${bloodFlag} -f ./M2-1.M1 -o ./M2-1-footer.M1
${M1} --architecture ${m2libcArch} \
${endianFlag} \
-f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
-f ${m2libc}/${m2libcArch}/libc-full.M1 \
-f ./M2-1.M1 \
-f ./M2-1-footer.M1 \
-o ./M2-1.hex2
${hex2} --architecture ${m2libcArch} \
${endianFlag} \
--base-address ${baseAddress} \
-f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
-f ./M2-1.hex2 \
-o ${out}/bin/M2-Planet

View File

@@ -0,0 +1,116 @@
{
lib,
derivationWithMeta,
hostPlatform,
kaem-unwrapped,
M1,
M2,
blood-elf-0,
hex2,
m2libc,
src,
version,
platforms,
m2libcArch,
baseAddress,
}:
let
endianFlag = if hostPlatform.isLittleEndian then "--little-endian" else "--big-endian";
bloodFlag = if hostPlatform.is64bit then "--64" else " ";
# We need a few tools from mescc-tools-extra to assemble the output folder
buildMesccToolsExtraUtil =
name:
derivationWithMeta {
pname = "mescc-tools-extra-${name}";
builder = kaem-unwrapped;
args = [
"--verbose"
"--strict"
"--file"
(builtins.toFile "build-${name}.kaem" ''
''${M2} --architecture ${m2libcArch} \
-f ''${m2libc}/sys/types.h \
-f ''${m2libc}/stddef.h \
-f ''${m2libc}/${m2libcArch}/linux/fcntl.c \
-f ''${m2libc}/fcntl.c \
-f ''${m2libc}/${m2libcArch}/linux/unistd.c \
-f ''${m2libc}/${m2libcArch}/linux/sys/stat.c \
-f ''${m2libc}/stdlib.c \
-f ''${m2libc}/stdio.h \
-f ''${m2libc}/stdio.c \
-f ''${m2libc}/string.c \
-f ''${m2libc}/bootstrappable.c \
-f ''${src}/mescc-tools-extra/${name}.c \
--debug \
-o ${name}.M1
''${blood-elf-0} ${endianFlag} ${bloodFlag} -f ${name}.M1 -o ${name}-footer.M1
''${M1} --architecture ${m2libcArch} \
${endianFlag} \
-f ''${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \
-f ''${m2libc}/${m2libcArch}/libc-full.M1 \
-f ${name}.M1 \
-f ${name}-footer.M1 \
-o ${name}.hex2
''${hex2} --architecture ${m2libcArch} \
${endianFlag} \
-f ''${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \
-f ${name}.hex2 \
--base-address ${baseAddress} \
-o ''${out}
'')
];
inherit
version
M1
M2
blood-elf-0
hex2
m2libc
src
;
};
mkdir = buildMesccToolsExtraUtil "mkdir";
cp = buildMesccToolsExtraUtil "cp";
chmod = buildMesccToolsExtraUtil "chmod";
replace = buildMesccToolsExtraUtil "replace";
in
derivationWithMeta {
pname = "mescc-tools";
builder = kaem-unwrapped;
args = [
"--verbose"
"--strict"
"--file"
./build.kaem
];
inherit
version
M1
M2
blood-elf-0
hex2
mkdir
cp
chmod
replace
m2libc
src
m2libcArch
baseAddress
bloodFlag
endianFlag
;
meta = with lib; {
description = "Collection of tools written for use in bootstrapping";
homepage = "https://github.com/oriansj/mescc-tools";
license = licenses.gpl3Plus;
teams = [ teams.minimal-bootstrap ];
inherit platforms;
};
}

View File

@@ -0,0 +1,38 @@
# Platform specific constants
{
lib,
hostPlatform,
}:
rec {
# meta.platforms
platforms = [
"aarch64-linux"
"i686-linux"
"x86_64-linux"
];
# system arch as used within the stage0 project
stage0Arch =
{
"aarch64-linux" = "AArch64";
"i686-linux" = "x86";
"x86_64-linux" = "AMD64";
}
.${hostPlatform.system} or (throw "Unsupported system: ${hostPlatform.system}");
# lower-case form is widely used by m2libc
m2libcArch = lib.toLower stage0Arch;
# Passed to M2-Mesoplanet as --operating-system
m2libcOS =
if hostPlatform.isLinux then "linux" else throw "Unsupported system: ${hostPlatform.system}";
baseAddress =
{
"aarch64-linux" = "0x00600000";
"i686-linux" = "0x08048000";
"x86_64-linux" = "0x00600000";
}
.${hostPlatform.system} or (throw "Unsupported system: ${hostPlatform.system}");
}

View File

@@ -0,0 +1,180 @@
# Bootstrappable TCC is a fork from mainline TCC development
# that can be compiled by MesCC
# Build steps adapted from https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/tcc-0.9.26/tcc-0.9.26.kaem
#
# SPDX-FileCopyrightText: 2021-22 fosslinux <fosslinux@aussies.space>
#
# SPDX-License-Identifier: GPL-3.0-or-later
{
lib,
callPackage,
fetchurl,
kaem,
mes,
mes-libc,
}:
let
inherit (callPackage ./common.nix { }) buildTinyccMes recompileLibc;
version = "unstable-2023-04-20";
rev = "80114c4da6b17fbaabb399cc29f427e368309bc8";
tarball = fetchurl {
url = "https://gitlab.com/janneke/tinycc/-/archive/${rev}/tinycc-${rev}.tar.gz";
sha256 = "1a0cw9a62qc76qqn5sjmp3xrbbvsz2dxrw21lrnx9q0s74mwaxbq";
};
src =
(kaem.runCommand "tinycc-bootstrappable-${version}-source" { } ''
ungz --file ${tarball} --output tinycc.tar
mkdir -p ''${out}
cd ''${out}
untar --file ''${NIX_BUILD_TOP}/tinycc.tar
# Patch
cd tinycc-${rev}
# Static link by default
replace --file libtcc.c --output libtcc.c --match-on "s->ms_extensions = 1;" --replace-with "s->ms_extensions = 1; s->static_link = 1;"
'')
+ "/tinycc-${rev}";
meta = with lib; {
description = "Tiny C Compiler's bootstrappable fork";
homepage = "https://gitlab.com/janneke/tinycc";
license = licenses.lgpl21Only;
teams = [ teams.minimal-bootstrap ];
platforms = [ "i686-linux" ];
};
pname = "tinycc-boot-mes";
tinycc-boot-mes = rec {
compiler =
kaem.runCommand "${pname}-${version}"
{
passthru.tests.get-version =
result:
kaem.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/tcc -version
mkdir ''${out}
'';
}
''
catm config.h
${mes.compiler}/bin/mes --no-auto-compile -e main ${mes.srcPost.bin}/bin/mescc.scm -- \
-S \
-o tcc.s \
-I . \
-D BOOTSTRAP=1 \
-I ${src} \
-D TCC_TARGET_I386=1 \
-D inline= \
-D CONFIG_TCCDIR=\"\" \
-D CONFIG_SYSROOT=\"\" \
-D CONFIG_TCC_CRTPREFIX=\"{B}\" \
-D CONFIG_TCC_ELFINTERP=\"/mes/loader\" \
-D CONFIG_TCC_LIBPATHS=\"{B}\" \
-D CONFIG_TCC_SYSINCLUDEPATHS=\"${mes-libc}/include\" \
-D TCC_LIBGCC=\"${mes-libc}/lib/x86-mes/libc.a\" \
-D CONFIG_TCC_LIBTCC1_MES=0 \
-D CONFIG_TCCBOOT=1 \
-D CONFIG_TCC_STATIC=1 \
-D CONFIG_USE_LIBGCC=1 \
-D TCC_MES_LIBC=1 \
-D TCC_VERSION=\"${version}\" \
-D ONE_SOURCE=1 \
${src}/tcc.c
mkdir -p ''${out}/bin
${mes.compiler}/bin/mes --no-auto-compile -e main ${mes.srcPost.bin}/bin/mescc.scm -- \
-L ${mes.libs}/lib \
-l c+tcc \
-o ''${out}/bin/tcc \
tcc.s
'';
libs = recompileLibc {
inherit pname version;
tcc = compiler;
src = mes-libc;
libtccOptions = mes-libc.CFLAGS;
};
};
# Bootstrap stage build flags obtained from
# https://gitlab.com/janneke/tinycc/-/blob/80114c4da6b17fbaabb399cc29f427e368309bc8/boot.sh
tinycc-boot0 = buildTinyccMes {
pname = "tinycc-boot0";
inherit src version meta;
prev = tinycc-boot-mes;
buildOptions = [
"-D HAVE_LONG_LONG_STUB=1"
"-D HAVE_SETJMP=1"
];
libtccBuildOptions = [
"-D HAVE_LONG_LONG_STUB=1"
];
};
tinycc-boot1 = buildTinyccMes {
pname = "tinycc-boot1";
inherit src version meta;
prev = tinycc-boot0;
buildOptions = [
"-D HAVE_BITFIELD=1"
"-D HAVE_LONG_LONG=1"
"-D HAVE_SETJMP=1"
];
libtccBuildOptions = [
"-D HAVE_LONG_LONG=1"
];
};
tinycc-boot2 = buildTinyccMes {
pname = "tinycc-boot2";
inherit src version meta;
prev = tinycc-boot1;
buildOptions = [
"-D HAVE_BITFIELD=1"
"-D HAVE_FLOAT_STUB=1"
"-D HAVE_LONG_LONG=1"
"-D HAVE_SETJMP=1"
];
libtccBuildOptions = [
"-D HAVE_FLOAT_STUB=1"
"-D HAVE_LONG_LONG=1"
];
};
tinycc-boot3 = buildTinyccMes {
pname = "tinycc-boot3";
inherit src version meta;
prev = tinycc-boot2;
buildOptions = [
"-D HAVE_BITFIELD=1"
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
"-D HAVE_SETJMP=1"
];
libtccBuildOptions = [
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
];
};
in
buildTinyccMes {
pname = "tinycc-bootstrappable";
inherit src version meta;
prev = tinycc-boot3;
buildOptions = [
"-D HAVE_BITFIELD=1"
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
"-D HAVE_SETJMP=1"
];
libtccBuildOptions = [
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
];
}

View File

@@ -0,0 +1,130 @@
{
lib,
kaem,
mes-libc,
}:
rec {
# Recompile libc: crt{1,n,i}, libtcc.a, libc.a, libgetopt.a
recompileLibc =
{
tcc,
pname,
version,
src,
libtccOptions,
}:
let
crt = kaem.runCommand "crt" { } ''
mkdir -p ''${out}/lib
${tcc}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crt1.o ${mes-libc}/lib/crt1.c
${tcc}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crtn.o ${mes-libc}/lib/crtn.c
${tcc}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crti.o ${mes-libc}/lib/crti.c
'';
library =
lib: options: source:
kaem.runCommand "${lib}.a" { } ''
${tcc}/bin/tcc ${options} -c -o ${lib}.o ${source}
${tcc}/bin/tcc -ar cr ''${out} ${lib}.o
'';
libtcc1 = library "libtcc1" libtccOptions "${src}/lib/libtcc1.c";
libc = library "libc" mes-libc.CFLAGS "${mes-libc}/lib/libc.c";
libgetopt = library "libgetopt" mes-libc.CFLAGS "${mes-libc}/lib/libgetopt.c";
in
kaem.runCommand "${pname}-libs-${version}" { } ''
mkdir -p ''${out}/lib
cp ${crt}/lib/crt1.o ''${out}/lib
cp ${crt}/lib/crtn.o ''${out}/lib
cp ${crt}/lib/crti.o ''${out}/lib
cp ${libtcc1} ''${out}/lib/libtcc1.a
cp ${libc} ''${out}/lib/libc.a
cp ${libgetopt} ''${out}/lib/libgetopt.a
'';
buildTinyccMes =
{
pname,
version,
src,
prev,
buildOptions,
libtccBuildOptions,
meta,
}:
let
options = lib.strings.concatStringsSep " " buildOptions;
libtccOptions = lib.strings.concatStringsSep " " (
[
"-c"
"-D"
"TCC_TARGET_I386=1"
]
++ libtccBuildOptions
);
compiler =
kaem.runCommand "${pname}-${version}"
{
inherit pname version meta;
passthru.tests = {
get-version =
result:
kaem.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/tcc -version
mkdir ''${out}
'';
chain =
result:
kaem.runCommand "${pname}-chain-${version}" { } ''
echo ${prev.compiler.tests.chain or prev.compiler.tests.get-version};
${result}/bin/tcc -version
mkdir ''${out}
'';
};
}
''
catm config.h
mkdir -p ''${out}/bin
${prev.compiler}/bin/tcc \
-B ${prev.libs}/lib \
-g \
-v \
-o ''${out}/bin/tcc \
-D BOOTSTRAP=1 \
${options} \
-I . \
-I ${src} \
-D TCC_TARGET_I386=1 \
-D CONFIG_TCCDIR=\"\" \
-D CONFIG_SYSROOT=\"\" \
-D CONFIG_TCC_CRTPREFIX=\"{B}\" \
-D CONFIG_TCC_ELFINTERP=\"\" \
-D CONFIG_TCC_LIBPATHS=\"{B}\" \
-D CONFIG_TCC_SYSINCLUDEPATHS=\"${mes-libc}/include\" \
-D TCC_LIBGCC=\"libc.a\" \
-D TCC_LIBTCC1=\"libtcc1.a\" \
-D CONFIG_TCCBOOT=1 \
-D CONFIG_TCC_STATIC=1 \
-D CONFIG_USE_LIBGCC=1 \
-D TCC_MES_LIBC=1 \
-D TCC_VERSION=\"${version}\" \
-D ONE_SOURCE=1 \
${src}/tcc.c
'';
libs = recompileLibc {
inherit
pname
version
src
libtccOptions
;
tcc = compiler;
};
in
{
inherit prev compiler libs;
};
}

View File

@@ -0,0 +1,13 @@
--- tccelf.c
+++ tccelf.c
@@ -710,8 +710,9 @@ ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size,
#if 0
printf("new_bind=%x new_shndx=%x new_vis=%x old_bind=%x old_shndx=%x old_vis=%x\n",
sym_bind, shndx, new_vis, esym_bind, esym->st_shndx, esym_vis);
-#endif
tcc_error_noabort("'%s' defined twice", name);
+#endif
+ goto do_patch;
}
} else {
esym->st_other = other;

View File

@@ -0,0 +1,21 @@
--- tccgen.c
+++ tccgen.c
@@ -4941,7 +4941,7 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td)
next();
n = -1;
t1 = 0;
- if (td & TYPE_PARAM) while (1) {
+ while (1) {
/* XXX The optional type-quals and static should only be accepted
in parameter decls. The '*' as well, and then even only
in prototypes (not function defs). */
@@ -4972,7 +4972,8 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td)
}
break;
- } else if (tok != ']') {
+ }
+ if (tok != ']') {
if (!local_stack || (storage & VT_STATIC))
vpushi(expr_const());
else {

View File

@@ -0,0 +1,99 @@
# Build steps adapted from https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/tcc-0.9.27/tcc-0.9.27.kaem
#
# SPDX-FileCopyrightText: 2021-22 fosslinux <fosslinux@aussies.space>
#
# SPDX-License-Identifier: GPL-3.0-or-later
{
lib,
fetchurl,
callPackage,
kaem,
tinycc-bootstrappable,
}:
let
inherit (callPackage ./common.nix { }) buildTinyccMes;
version = "unstable-2023-04-20";
rev = "86f3d8e33105435946383aee52487b5ddf918140";
tarball = fetchurl {
url = "https://repo.or.cz/tinycc.git/snapshot/${rev}.tar.gz";
sha256 = "11idrvbwfgj1d03crv994mpbbbyg63j1k64lw1gjy7mkiifw2xap";
};
src =
(kaem.runCommand "tinycc-${version}-source" { } ''
ungz --file ${tarball} --output tinycc.tar
mkdir -p ''${out}
cd ''${out}
untar --file ''${NIX_BUILD_TOP}/tinycc.tar
# Patch
cd tinycc-${builtins.substring 0 7 rev}
# Static link by default
replace --file libtcc.c --output libtcc.c --match-on "s->ms_extensions = 1;" --replace-with "s->ms_extensions = 1; s->static_link = 1;"
'')
+ "/tinycc-${builtins.substring 0 7 rev}";
meta = with lib; {
description = "Small, fast, and embeddable C compiler and interpreter";
homepage = "https://repo.or.cz/w/tinycc.git";
license = licenses.lgpl21Only;
teams = [ teams.minimal-bootstrap ];
platforms = [ "i686-linux" ];
};
tccdefs = kaem.runCommand "tccdefs-${version}" { } ''
mkdir ''${out}
${tinycc-bootstrappable.compiler}/bin/tcc \
-B ${tinycc-bootstrappable.libs}/lib \
-DC2STR \
-o c2str \
${src}/conftest.c
./c2str ${src}/include/tccdefs.h ''${out}/tccdefs_.h
'';
tinycc-mes-boot = buildTinyccMes {
pname = "tinycc-mes-boot";
inherit src version meta;
prev = tinycc-bootstrappable;
buildOptions = [
"-D HAVE_BITFIELD=1"
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
"-D HAVE_SETJMP=1"
"-D CONFIG_TCC_PREDEFS=1"
"-I ${tccdefs}"
"-D CONFIG_TCC_SEMLOCK=0"
];
libtccBuildOptions = [
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
"-D CONFIG_TCC_PREDEFS=1"
"-I ${tccdefs}"
"-D CONFIG_TCC_SEMLOCK=0"
];
};
in
buildTinyccMes {
pname = "tinycc-mes";
inherit src version meta;
prev = tinycc-mes-boot;
buildOptions = [
"-std=c99"
"-D HAVE_BITFIELD=1"
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
"-D HAVE_SETJMP=1"
"-D CONFIG_TCC_PREDEFS=1"
"-I ${tccdefs}"
"-D CONFIG_TCC_SEMLOCK=0"
];
libtccBuildOptions = [
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
"-D CONFIG_TCC_PREDEFS=1"
"-I ${tccdefs}"
"-D CONFIG_TCC_SEMLOCK=0"
];
}

View File

@@ -0,0 +1,163 @@
{
lib,
fetchurl,
callPackage,
bash,
tinycc-bootstrappable,
musl,
gnupatch,
gnutar,
gzip,
}:
let
pname = "tinycc-musl";
# next commit introduces use of realpath (unsupported in mes-libc)
version = "unstable-2023-07-10";
rev = "fd6d2180c5c801bb0b4c5dde27d61503059fc97d";
src = fetchurl {
url = "https://repo.or.cz/tinycc.git/snapshot/${rev}.tar.gz";
hash = "sha256-R81SNbEmh4s9FNQxCWZwUiMCYRkkwOHAdRf0aMnnRiA=";
};
patches = [
./ignore-duplicate-symbols.patch
./ignore-static-inside-array.patch
./static-link.patch
];
meta = with lib; {
description = "Small, fast, and embeddable C compiler and interpreter";
homepage = "https://repo.or.cz/w/tinycc.git";
license = licenses.lgpl21Only;
teams = [ teams.minimal-bootstrap ];
platforms = [ "i686-linux" ];
};
tinycc-musl =
bash.runCommand "${pname}-${version}"
{
inherit pname version meta;
nativeBuildInputs = [
tinycc-bootstrappable.compiler
gnupatch
gnutar
gzip
];
}
''
# Unpack
tar xzf ${src}
cd tinycc-${builtins.substring 0 7 rev}
# Patch
${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches}
# Configure
touch config.h
# Build
# We first have to recompile using tcc-0.9.26 as tcc-0.9.27 is not self-hosting,
# but when linked with musl it is.
ln -s ${musl}/lib/libtcc1.a ./libtcc1.a
tcc \
-B ${tinycc-bootstrappable.libs}/lib \
-DC2STR \
-o c2str \
conftest.c
./c2str include/tccdefs.h tccdefs_.h
tcc -v \
-static \
-o tcc-musl \
-D TCC_TARGET_I386=1 \
-D CONFIG_TCCDIR=\"\" \
-D CONFIG_TCC_CRTPREFIX=\"{B}\" \
-D CONFIG_TCC_ELFINTERP=\"/musl/loader\" \
-D CONFIG_TCC_LIBPATHS=\"{B}\" \
-D CONFIG_TCC_SYSINCLUDEPATHS=\"${musl}/include\" \
-D TCC_LIBGCC=\"libc.a\" \
-D TCC_LIBTCC1=\"libtcc1.a\" \
-D CONFIG_TCC_STATIC=1 \
-D CONFIG_USE_LIBGCC=1 \
-D TCC_VERSION=\"0.9.27\" \
-D ONE_SOURCE=1 \
-D TCC_MUSL=1 \
-D CONFIG_TCC_PREDEFS=1 \
-D CONFIG_TCC_SEMLOCK=0 \
-B . \
-B ${tinycc-bootstrappable.libs}/lib \
tcc.c
# libtcc1.a
rm -f libtcc1.a
tcc -c -D HAVE_CONFIG_H=1 lib/libtcc1.c
tcc -ar cr libtcc1.a libtcc1.o
# Rebuild tcc-musl with itself
./tcc-musl \
-v \
-static \
-o tcc-musl \
-D TCC_TARGET_I386=1 \
-D CONFIG_TCCDIR=\"\" \
-D CONFIG_TCC_CRTPREFIX=\"{B}\" \
-D CONFIG_TCC_ELFINTERP=\"/musl/loader\" \
-D CONFIG_TCC_LIBPATHS=\"{B}\" \
-D CONFIG_TCC_SYSINCLUDEPATHS=\"${musl}/include\" \
-D TCC_LIBGCC=\"libc.a\" \
-D TCC_LIBTCC1=\"libtcc1.a\" \
-D CONFIG_TCC_STATIC=1 \
-D CONFIG_USE_LIBGCC=1 \
-D TCC_VERSION=\"0.9.27\" \
-D ONE_SOURCE=1 \
-D TCC_MUSL=1 \
-D CONFIG_TCC_PREDEFS=1 \
-D CONFIG_TCC_SEMLOCK=0 \
-B . \
-B ${musl}/lib \
tcc.c
# libtcc1.a
rm -f libtcc1.a
./tcc-musl -c -D HAVE_CONFIG_H=1 lib/libtcc1.c
./tcc-musl -c -D HAVE_CONFIG_H=1 lib/alloca.S
./tcc-musl -ar cr libtcc1.a libtcc1.o alloca.o
# Install
install -D tcc-musl $out/bin/tcc
install -Dm444 libtcc1.a $out/lib/libtcc1.a
'';
in
{
compiler = bash.runCommand "${pname}-${version}-compiler" {
inherit pname version meta;
passthru.tests.hello-world =
result:
bash.runCommand "${pname}-simple-program-${version}" { } ''
cat <<EOF >> test.c
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
EOF
${result}/bin/tcc -v -static -B${musl}/lib -o test test.c
./test
mkdir $out
'';
passthru.tinycc-musl = tinycc-musl;
} "install -D ${tinycc-musl}/bin/tcc $out/bin/tcc";
libs =
bash.runCommand "${pname}-${version}-libs"
{
inherit pname version meta;
}
''
mkdir $out
cp -r ${musl}/* $out
chmod +w $out/lib/libtcc1.a
cp ${tinycc-musl}/lib/libtcc1.a $out/lib/libtcc1.a
'';
}

View File

@@ -0,0 +1,10 @@
--- libtcc.c
+++ libtcc.c
@@ -793,6 +793,7 @@ LIBTCCAPI TCCState *tcc_new(void)
s->gnu_ext = 1;
s->tcc_ext = 1;
+ s->static_link = 1;
s->nocommon = 1;
s->dollars_in_identifiers = 1; /*on by default like in gcc/clang*/
s->cversion = 199901; /* default unless -std=c11 is supplied */

View File

@@ -0,0 +1,79 @@
{
lib,
buildPlatform,
callPackage,
kaem,
mescc-tools-extra,
checkMeta,
}:
rec {
derivationWithMeta =
attrs:
let
passthru = attrs.passthru or { };
validity = checkMeta.assertValidity { inherit meta attrs; };
meta = checkMeta.commonMeta { inherit validity attrs; };
baseDrv = derivation (
{
inherit (buildPlatform) system;
inherit (meta) name;
}
// (removeAttrs attrs [
"meta"
"passthru"
])
);
passthru' =
passthru
// lib.optionalAttrs (passthru ? tests) {
tests = lib.mapAttrs (_: f: f baseDrv) passthru.tests;
};
in
lib.extendDerivation validity.handled (
{
inherit meta;
passthru = passthru';
}
// passthru'
) baseDrv;
writeTextFile =
{
name, # the name of the derivation
text,
executable ? false, # run chmod +x ?
destination ? "", # relative path appended to $out eg "/bin/foo"
}:
derivationWithMeta {
inherit name text;
passAsFile = [ "text" ];
builder = "${kaem}/bin/kaem";
args = [
"--verbose"
"--strict"
"--file"
(builtins.toFile "write-text-file.kaem" (
''
target=''${out}''${destination}
''
+ lib.optionalString (dirOf destination == ".") ''
mkdir -p ''${out}''${destinationDir}
''
+ ''
cp ''${textPath} ''${target}
''
+ lib.optionalString executable ''
chmod 555 ''${target}
''
))
];
PATH = lib.makeBinPath [ mescc-tools-extra ];
destinationDir = dirOf destination;
inherit destination;
};
writeText = name: text: writeTextFile { inherit name text; };
}

View File

@@ -0,0 +1,77 @@
{
lib,
buildPlatform,
hostPlatform,
fetchurl,
bash,
tinycc,
gnumake,
gnused,
gnugrep,
gawk,
gnutar,
gzip,
}:
let
pname = "xz";
version = "5.4.3";
src = fetchurl {
url = "https://tukaani.org/xz/xz-${version}.tar.gz";
hash = "sha256-HDguC8Lk4K9YOYqQPdYv/35RAXHS3keh6+BtFSjpt+k=";
};
in
bash.runCommand "${pname}-${version}"
{
inherit pname version;
nativeBuildInputs = [
tinycc.compiler
gnumake
gnused
gnugrep
gawk
gnutar
gzip
];
passthru.tests.get-version =
result:
bash.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/xz --version
mkdir $out
'';
meta = with lib; {
description = "General-purpose data compression software, successor of LZMA";
homepage = "https://tukaani.org/xz";
license = with licenses; [
gpl2Plus
lgpl21Plus
];
teams = [ teams.minimal-bootstrap ];
platforms = platforms.unix;
};
}
''
# Unpack
tar xzf ${src}
cd xz-${version}
# Configure
export CC="tcc -B ${tinycc.libs}/lib"
export AR="tcc -ar"
export LD=tcc
bash ./configure \
--prefix=$out \
--build=${buildPlatform.config} \
--host=${hostPlatform.config} \
--disable-shared \
--disable-assembler
# Build
make -j $NIX_BUILD_CORES
# Install
make -j $NIX_BUILD_CORES install
''