about summary refs log tree commit diff
path: root/pkgs/by-name
diff options
context:
space:
mode:
authorAnderson Torres <torres.anderson.85@protonmail.com>2023-09-16 23:34:11 -0300
committerAnderson Torres <torres.anderson.85@protonmail.com>2023-09-22 01:38:23 -0300
commit8a75a8f4cf0683006e2fb90df7ad6b832c041547 (patch)
tree0a7eb91a9ba23e8447a1d102bad71233a3ce913d /pkgs/by-name
parent449ff3b02f9d4aa15c9224af049d6ac170552554 (diff)
bmake: move to by-name
Diffstat (limited to 'pkgs/by-name')
-rw-r--r--pkgs/by-name/bm/bmake/bootstrap-fix.patch10
-rw-r--r--pkgs/by-name/bm/bmake/dont-test-while-installing.diff21
-rw-r--r--pkgs/by-name/bm/bmake/fix-unexport-env-test.patch13
-rw-r--r--pkgs/by-name/bm/bmake/package.nix108
-rw-r--r--pkgs/by-name/bm/bmake/setup-hook.sh122
-rw-r--r--pkgs/by-name/bm/bmake/unconditional-ksh-test.patch12
6 files changed, 286 insertions, 0 deletions
diff --git a/pkgs/by-name/bm/bmake/bootstrap-fix.patch b/pkgs/by-name/bm/bmake/bootstrap-fix.patch
new file mode 100644
index 0000000000000..9b1267257ad16
--- /dev/null
+++ b/pkgs/by-name/bm/bmake/bootstrap-fix.patch
@@ -0,0 +1,10 @@
+--- bmake/make-bootstrap.sh.in.orig     2019-02-19 10:55:21.733606117 -0800
++++ bmake/make-bootstrap.sh.in  2019-02-19 10:56:02.150771541 -0800
+@@ -4,6 +4,7 @@
+ 
+ srcdir=@srcdir@
+ 
++prefix="@prefix@"
+ DEFAULT_SYS_PATH="@default_sys_path@"
+ 
+ case "@use_meta@" in
diff --git a/pkgs/by-name/bm/bmake/dont-test-while-installing.diff b/pkgs/by-name/bm/bmake/dont-test-while-installing.diff
new file mode 100644
index 0000000000000..ab9399920c242
--- /dev/null
+++ b/pkgs/by-name/bm/bmake/dont-test-while-installing.diff
@@ -0,0 +1,21 @@
+diff -Naur bmake-old/boot-strap bmake-new/boot-strap
+--- bmake-old/boot-strap	2023-06-27 18:02:19.000000000 -0300
++++ bmake-new/boot-strap	2023-07-23 22:31:02.334720661 -0300
+@@ -413,9 +413,6 @@
+ 	[ -s make-bootstrap.sh ] || op_configure
+ 	chmod 755 make-bootstrap.sh || exit 1
+ 	./make-bootstrap.sh || exit 1
+-	case "$op" in
+-	build) op_test;;
+-	esac
+ }
+ 
+ op_test() {
+@@ -434,7 +431,6 @@
+ }
+ 
+ op_install() {
+-	op_test
+ 	case "$INSTALL_PREFIX,$INSTALL_BIN,$prefix" in
+ 	,$HOST_TARGET/bin,*/$HOST_TARGET)
+ 		INSTALL_PREFIX=`dirname $prefix`
diff --git a/pkgs/by-name/bm/bmake/fix-unexport-env-test.patch b/pkgs/by-name/bm/bmake/fix-unexport-env-test.patch
new file mode 100644
index 0000000000000..fbf7225a6d6f2
--- /dev/null
+++ b/pkgs/by-name/bm/bmake/fix-unexport-env-test.patch
@@ -0,0 +1,13 @@
+--- bmake/unit-tests/unexport-env.mk.orig	2021-05-27 14:44:45.263392298 +0200
++++ bmake/unit-tests/unexport-env.mk	2021-05-27 14:46:46.188881996 +0200
+@@ -4,8 +4,8 @@
+ FILTER_CMD=	grep ^UT_
+ .include "export.mk"
+ 
+-# an example of setting up a minimal environment.
+-PATH=	/bin:/usr/bin:/sbin:/usr/sbin
++# preserve PATH so commands used in the "all" target are still available
++PATH :=	${PATH}
+ 
+ # now clobber the environment to just PATH and UT_TEST
+ UT_TEST=	unexport-env
diff --git a/pkgs/by-name/bm/bmake/package.nix b/pkgs/by-name/bm/bmake/package.nix
new file mode 100644
index 0000000000000..4373e534bc58f
--- /dev/null
+++ b/pkgs/by-name/bm/bmake/package.nix
@@ -0,0 +1,108 @@
+{ lib
+, stdenv
+, fetchurl
+, fetchpatch
+, getopt
+, ksh
+, tzdata
+, pkgsMusl # for passthru.tests
+}:
+
+stdenv.mkDerivation (finalAttrs: {
+  pname = "bmake";
+  version = "20230723";
+
+  src = fetchurl {
+    url = "http://www.crufty.net/ftp/pub/sjg/bmake-${finalAttrs.version}.tar.gz";
+    hash = "sha256-xCoNlRuiP3ZlMxMJ+74h7cARNqI8uUFoULQxW+X7WQQ=";
+  };
+
+  patches = [
+    # make bootstrap script aware of the prefix in /nix/store
+    ./bootstrap-fix.patch
+    # preserve PATH from build env in unit tests
+    ./fix-unexport-env-test.patch
+    # Always enable ksh test since it checks in a impure location /bin/ksh
+    ./unconditional-ksh-test.patch
+    # decouple tests from build phase
+    ./dont-test-while-installing.diff
+  ];
+
+  # Make tests work with musl
+  # * Disable deptgt-delete_on_error test (alpine does this too)
+  # * Disable shell-ksh test (ksh doesn't compile with musl)
+  # * Fix test failing due to different strerror(3) output for musl and glibc
+  postPatch = lib.optionalString (stdenv.hostPlatform.libc == "musl") ''
+    sed -i unit-tests/Makefile \
+      -e '/deptgt-delete_on_error/d' \
+      -e '/shell-ksh/d'
+    substituteInPlace unit-tests/opt-chdir.exp --replace "File name" "Filename"
+  '';
+
+  nativeBuildInputs = [ getopt ];
+
+  # The generated makefile is a small wrapper for calling ./boot-strap with a
+  # given op. On a case-insensitive filesystem this generated makefile clobbers
+  # a distinct, shipped, Makefile and causes infinite recursion during tests
+  # which eventually fail with "fork: Resource temporarily unavailable"
+  configureFlags = [
+    "--without-makefile"
+  ];
+
+  buildPhase = ''
+    runHook preBuild
+
+    ./boot-strap --prefix=$out -o . op=build
+
+    runHook postBuild
+  '';
+
+  installPhase = ''
+    runHook preInstall
+
+    ./boot-strap --prefix=$out -o . op=install
+
+    runHook postInstall
+  '';
+
+  doCheck = true;
+
+  nativeCheckInputs = [
+    tzdata
+  ] ++ lib.optionals (stdenv.hostPlatform.libc != "musl") [
+    ksh
+  ];
+
+  # Disabled tests:
+  # opt-chdir: ofborg complains about it somehow
+  # opt-keep-going-indirect: not yet known
+  # varmod-localtime: musl doesn't support TZDIR and this test relies on impure,
+  # implicit paths
+  env.BROKEN_TESTS = builtins.concatStringsSep " " [
+    "opt-chdir"
+    "opt-keep-going-indirect"
+    "varmod-localtime"
+  ];
+
+  checkPhase = ''
+    runHook preCheck
+
+    ./boot-strap -o . op=test
+
+    runHook postCheck
+  '';
+
+  setupHook = ./setup-hook.sh;
+
+  passthru.tests.bmakeMusl = pkgsMusl.bmake;
+
+  meta = {
+    homepage = "http://www.crufty.net/help/sjg/bmake.html";
+    description = "Portable version of NetBSD 'make'";
+    license = lib.licenses.bsd3;
+    maintainers = with lib.maintainers; [ thoughtpolice AndersonTorres ];
+    platforms = lib.platforms.unix;
+    broken = stdenv.isAarch64; # failure on gnulib-tests
+  };
+})
+# TODO: report the quirks and patches to bmake devteam (especially the Musl one)
diff --git a/pkgs/by-name/bm/bmake/setup-hook.sh b/pkgs/by-name/bm/bmake/setup-hook.sh
new file mode 100644
index 0000000000000..a36d024b111e7
--- /dev/null
+++ b/pkgs/by-name/bm/bmake/setup-hook.sh
@@ -0,0 +1,122 @@
+# shellcheck shell=bash disable=SC2086,SC2154,SC2206
+
+addMakeFlags() {
+    export prefix="$out"
+    export MANDIR="${!outputMan}/share/man"
+    export MANTARGET=man
+    export BINOWN=
+    export STRIP_FLAG=
+}
+
+bmakeBuildPhase() {
+    runHook preBuild
+
+    local flagsArray=(
+        ${enableParallelBuilding:+-j${NIX_BUILD_CORES}}
+        SHELL="$SHELL"
+        $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
+        $buildFlags ${buildFlagsArray+"${buildFlagsArray[@]}"}
+    )
+
+    echoCmd 'build flags' "${flagsArray[@]}"
+    bmake ${makefile:+-f $makefile} "${flagsArray[@]}"
+
+    runHook postBuild
+}
+
+bmakeCheckPhase() {
+    runHook preCheck
+
+    if [ -z "${checkTarget:-}" ]; then
+        #TODO(@oxij): should flagsArray influence make -n?
+        if bmake -n ${makefile:+-f $makefile} check >/dev/null 2>&1; then
+            checkTarget="check"
+        elif bmake -n ${makefile:+-f $makefile} test >/dev/null 2>&1; then
+            checkTarget="test"
+        fi
+    fi
+
+    if [ -z "${checkTarget:-}" ]; then
+        echo "no test target found in bmake, doing nothing"
+    else
+        local flagsArray=(
+            ${enableParallelChecking:+-j${NIX_BUILD_CORES}}
+            SHELL="$SHELL"
+            # Old bash empty array hack
+            $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
+            ${checkFlags:-VERBOSE=y} ${checkFlagsArray+"${checkFlagsArray[@]}"}
+            ${checkTarget}
+        )
+
+        echoCmd 'check flags' "${flagsArray[@]}"
+        bmake ${makefile:+-f $makefile} "${flagsArray[@]}"
+    fi
+
+    runHook postCheck
+}
+
+bmakeInstallPhase() {
+    runHook preInstall
+
+    if [ -n "$prefix" ]; then
+        mkdir -p "$prefix"
+    fi
+
+    local flagsArray=(
+        ${enableParallelInstalling:+-j${NIX_BUILD_CORES}}
+        SHELL="$SHELL"
+        # Old bash empty array hack
+        $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
+        $installFlags ${installFlagsArray+"${installFlagsArray[@]}"}
+        ${installTargets:-install}
+    )
+
+    echoCmd 'install flags' "${flagsArray[@]}"
+    bmake ${makefile:+-f $makefile} "${flagsArray[@]}"
+
+    runHook postInstall
+}
+
+bmakeDistPhase() {
+    runHook preDist
+
+    if [ -n "$prefix" ]; then
+        mkdir -p "$prefix"
+    fi
+
+    # Old bash empty array hack
+    local flagsArray=(
+        $distFlags ${distFlagsArray+"${distFlagsArray[@]}"} ${distTarget:-dist}
+    )
+
+    echo 'dist flags: %q' "${flagsArray[@]}"
+    bmake ${makefile:+-f $makefile} "${flagsArray[@]}"
+
+    if [ "${dontCopyDist:-0}" != 1 ]; then
+        mkdir -p "$out/tarballs"
+
+        # Note: don't quote $tarballs, since we explicitly permit
+        # wildcards in there.
+        cp -pvd ${tarballs:-*.tar.gz} "$out/tarballs"
+    fi
+
+    runHook postDist
+}
+
+preConfigureHooks+=(addMakeFlags)
+
+if [ -z "${dontUseBmakeBuild-}" ] && [ -z "${buildPhase-}" ]; then
+    buildPhase=bmakeBuildPhase
+fi
+
+if [ -z "${dontUseBmakeCheck-}" ] && [ -z "${checkPhase-}" ]; then
+    checkPhase=bmakeCheckPhase
+fi
+
+if [ -z "${dontUseBmakeInstall-}" ] && [ -z "${installPhase-}" ]; then
+    installPhase=bmakeInstallPhase
+fi
+
+if [ -z "${dontUseBmakeDist-}" ] && [ -z "${distPhase-}" ]; then
+    distPhase=bmakeDistPhase
+fi
diff --git a/pkgs/by-name/bm/bmake/unconditional-ksh-test.patch b/pkgs/by-name/bm/bmake/unconditional-ksh-test.patch
new file mode 100644
index 0000000000000..117b85da16d1d
--- /dev/null
+++ b/pkgs/by-name/bm/bmake/unconditional-ksh-test.patch
@@ -0,0 +1,12 @@
+--- bmake/unit-tests/Makefile.orig	2021-07-04 19:13:09.068094922 +0200
++++ bmake/unit-tests/Makefile	2021-07-04 19:13:14.630080696 +0200
+@@ -295,9 +295,7 @@
+ TESTS+=		sh-single-line
+ TESTS+=		shell-csh
+ TESTS+=		shell-custom
+-.if exists(/bin/ksh)
+ TESTS+=		shell-ksh
+-.endif
+ TESTS+=		shell-sh
+ TESTS+=		suff-add-later
+ TESTS+=		suff-clear-regular