about summary refs log tree commit diff
path: root/pkgs/development/tools/build-managers/bmake
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-04-13 00:10:06 +0000
committerAlyssa Ross <hi@alyssa.is>2021-04-16 12:56:48 +0000
commit53b88f966e01b6a51e40d3298c68be2d22243e3a (patch)
tree6332b1154adff55966be6730008c0305b5bca7e8 /pkgs/development/tools/build-managers/bmake
parent262b73f8af242f9879801ecc23734286e801eed9 (diff)
bmake: add setupHook
With this change,

    nativeBuildInputs = [ bmake ];

will cause bmake to be used instead of GNU make, but with the usual
stdenv API.  Packages using bmake will no longer need to implement
their own {build,check,dist}Phase.
Diffstat (limited to 'pkgs/development/tools/build-managers/bmake')
-rw-r--r--pkgs/development/tools/build-managers/bmake/default.nix2
-rw-r--r--pkgs/development/tools/build-managers/bmake/setup-hook.sh117
2 files changed, 119 insertions, 0 deletions
diff --git a/pkgs/development/tools/build-managers/bmake/default.nix b/pkgs/development/tools/build-managers/bmake/default.nix
index e1e9b348503cd..e79e06a71f4ec 100644
--- a/pkgs/development/tools/build-managers/bmake/default.nix
+++ b/pkgs/development/tools/build-managers/bmake/default.nix
@@ -18,6 +18,8 @@ stdenv.mkDerivation rec {
     ./fix-unexport-env-test.patch
   ];
 
+  setupHook = ./setup-hook.sh;
+
   meta = with lib; {
     description = "Portable version of NetBSD 'make'";
     homepage    = "http://www.crufty.net/help/sjg/bmake.html";
diff --git a/pkgs/development/tools/build-managers/bmake/setup-hook.sh b/pkgs/development/tools/build-managers/bmake/setup-hook.sh
new file mode 100644
index 0000000000000..ae8f78ec90fa4
--- /dev/null
+++ b/pkgs/development/tools/build-managers/bmake/setup-hook.sh
@@ -0,0 +1,117 @@
+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[@]}"
+    unset flagsArray
+
+    runHook postBuild
+}
+
+if [ -z "${dontUseBmakeBuild-}" -a -z "${buildPhase-}" ]; then
+    buildPhase=bmakeBuildPhase
+fi
+
+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
+        # shellcheck disable=SC2086
+        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[@]}"
+
+        unset flagsArray
+    fi
+
+    runHook postCheck
+}
+
+if [ -z "${dontUseBmakeCheck-}" -a -z "${checkPhase-}" ]; then
+    checkPhase=bmakeCheckPhase
+fi
+
+bmakeInstallPhase() {
+    runHook preInstall
+
+    if [ -n "$prefix" ]; then
+        mkdir -p "$prefix"
+    fi
+
+    # shellcheck disable=SC2086
+    local flagsArray=(
+        SHELL=$SHELL
+        # Old bash empty array hack
+        $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"}
+        $installFlags ${installFlagsArray+"${installFlagsArray[@]}"}
+        ${installTargets:-install}
+    )
+
+    echoCmd 'install flags' "${flagsArray[@]}"
+    bmake ${makefile:+-f $makefile} "${flagsArray[@]}"
+    unset flagsArray
+
+    runHook postInstall
+}
+
+if [ -z "${dontUseBmakeInstall-}" -a -z "${installPhase-}" ]; then
+    installPhase=bmakeInstallPhase
+fi
+
+bmakeDistPhase() {
+    runHook preDist
+
+    if [ -n "$prefix" ]; then
+        mkdir -p "$prefix"
+    fi
+
+    # Old bash empty array hack
+    # shellcheck disable=SC2086
+    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.
+        # shellcheck disable=SC2086
+        cp -pvd ${tarballs:-*.tar.gz} "$out/tarballs"
+    fi
+
+    runHook postDist
+}
+
+if [ -z "${dontUseBmakeDist-}" -a -z "${distPhase-}" ]; then
+    distPhase=bmakeDistPhase
+fi