Merge pull request #231019 from emilytrau/minimal-bootstrap-gnumake

minimal-bootstrap.gnumake: init at 4.4.1
This commit is contained in:
John Ericson 2023-05-11 09:11:28 -04:00 committed by GitHub
commit eed2172ffe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 439 additions and 3 deletions

View file

@ -10,15 +10,21 @@ lib.makeScope
# declared here.
(extra: lib.callPackageWith ({ inherit lib config buildPlatform hostPlatform; } // extra))
(self: with self; {
inherit (callPackage ./utils.nix { }) fetchurl derivationWithMeta writeTextFile writeText runCommand;
inherit (callPackage ./stage0-posix { }) kaem m2libc mescc-tools mescc-tools-extra;
gnupatch = callPackage ./gnupatch { tinycc = tinycc-mes; };
gnumake = callPackage ./gnumake { tinycc = tinycc-mes; };
ln-boot = callPackage ./ln-boot { };
mes = callPackage ./mes { };
mes-libc = callPackage ./mes/libc.nix { };
ln-boot = callPackage ./ln-boot { };
inherit (callPackage ./stage0-posix { }) kaem m2libc mescc-tools mescc-tools-extra;
tinycc-bootstrappable = callPackage ./tinycc/bootstrappable.nix { };
tinycc-mes = callPackage ./tinycc/mes.nix { };
inherit (callPackage ./utils.nix { }) fetchurl derivationWithMeta writeTextFile writeText runCommand;
})

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,190 @@
{ lib
, runCommand
, fetchurl
, 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-mes}/bin/tcc -static" \
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"] (builtins.baseNameOf x)) sources;
in
runCommand "${pname}-${version}" {
inherit pname version;
nativeBuildInputs = [ tinycc gnupatch ];
meta = with lib; {
description = "A tool to control the generation of non-source files from sources";
homepage = "https://www.gnu.org/software/make";
license = licenses.gpl3Plus;
maintainers = with maintainers; [ emilytrau ];
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 ${lib.concatStringsSep " " CFLAGS}"
${lib.concatMapStringsSep "\n" (f: "CC -c ${f}") sources}
# Link
CC -static -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,107 @@
{ lib
, runCommand
, fetchurl
, 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"] (builtins.baseNameOf x)) sources;
in
runCommand "${pname}-${version}" {
inherit pname version;
nativeBuildInputs = [ tinycc ];
meta = with lib; {
description = "GNU Patch, a program to apply differences to files";
homepage = "https://www.gnu.org/software/patch";
license = licenses.gpl3Plus;
maintainers = with maintainers; [ emilytrau ];
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 ${lib.concatStringsSep " " CFLAGS}"
${lib.concatMapStringsSep "\n" (f: "CC -c ${f}") sources}
# Link
CC -static -o patch ${lib.concatStringsSep " " objects}
# Check
./patch --version
# Install
mkdir -p ''${out}/bin
cp ./patch ''${out}/bin
chmod 555 ''${out}/bin/patch
''