diff options
author | Emily Trau <emily@downunderctf.com> | 2023-05-10 16:23:28 +1000 |
---|---|---|
committer | Emily Trau <emily@downunderctf.com> | 2023-05-11 11:56:49 +1000 |
commit | 459643f5d2315c0a789f2cef3844eb5bc2eb3179 (patch) | |
tree | 8deac1b397ef1fd84a8885675e7549a6748663cb | |
parent | 575171d619d01e2031efd581a11ce1a7c559b675 (diff) |
minimal-bootstrap.gnumake: init at 4.4.1
5 files changed, 325 insertions, 0 deletions
diff --git a/pkgs/os-specific/linux/minimal-bootstrap/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/default.nix index f7207d380beb4..a0a9a7985d155 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/default.nix @@ -24,4 +24,6 @@ lib.makeScope gnupatch = callPackage ./gnupatch { tinycc = tinycc-mes; }; + gnumake = callPackage ./gnumake { tinycc = tinycc-mes; }; + }) diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gnumake/0001-No-impure-bin-sh.patch b/pkgs/os-specific/linux/minimal-bootstrap/gnumake/0001-No-impure-bin-sh.patch new file mode 100644 index 0000000000000..58ee2d6fe09b0 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gnumake/0001-No-impure-bin-sh.patch @@ -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 + diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gnumake/0002-remove-impure-dirs.patch b/pkgs/os-specific/linux/minimal-bootstrap/gnumake/0002-remove-impure-dirs.patch new file mode 100644 index 0000000000000..e62aee7d9993d --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gnumake/0002-remove-impure-dirs.patch @@ -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 + diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gnumake/0003-tinycc-support.patch b/pkgs/os-specific/linux/minimal-bootstrap/gnumake/0003-tinycc-support.patch new file mode 100644 index 0000000000000..e2e3f33951536 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gnumake/0003-tinycc-support.patch @@ -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)); diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gnumake/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/gnumake/default.nix new file mode 100644 index 0000000000000..0db52e2874253 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gnumake/default.nix @@ -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 +'' |