Makefile: NetBSD make, not GNU make

Konrad, 2026-11-19: "bmake natuerlich".  On Makronix make(1) is NetBSD make
and stopped at the first conditional (Makefile:26: Invalid line
"ifeq ($(ARCH),amd64)"; $(shell ...) was read as a variable name).
$(CURDIR) becomes ${.CURDIR}, the $(shell ...) defaults become != under
.if !defined(), ifeq becomes .if, and the one $(shell uname -s) in a recipe
is the shell's $$(uname -s).  JOBS also asks /sbin/sysctl, which a
non-login PATH lacks.  The comment on MAKE_CMD now says what make(1) does
with -n (runs only .MAKE targets or lines starting with +).

Tested on makronix-build: make -n for all 18 targets rc=0 with the expected
build.sh lines; JOBS=3 and ARCH=i386 override.  On Linux the same file is
read by bmake (AGENTS.md, "Building").
This commit is contained in:
lotherk committed 2026-11-19 10:43:15 +01:00
1 parent eb4b6ba65e
commit e57d47bd3b
2 files changed
+23 -13

No files matched your search

+3 -2
View File
@@ -68,8 +68,9 @@ in a fork gets the CNCL line; a changed upstream file keeps the notice it has.
## Building
Everything builds from the root `Makefile`. The interface is meant to stay
this small -- **do not add targets**:
Everything builds from the root `Makefile`. It is NetBSD make (Konrad,
2026-11-19): `make` on Makronix, `bmake` on a Linux host; GNU make does not
read it. The interface is meant to stay this small -- **do not add targets**:
make the build (sets)
make release the release: sets, kernels, ramdisks, media
+20 -11
View File
@@ -9,34 +9,43 @@
# ARCH is the name a person types (amd64, sparc64, evbarm); MACHINE is
# NetBSD's internal name for the same thing. When the host is NetBSD and ARCH
# is not given, the host decides; otherwise amd64.
#
# This file is NetBSD make (make(1), bmake on other systems; Konrad,
# 2026-11-19: "bmake natuerlich"). GNU make does not read it.
TOP := $(CURDIR)
TOP := ${.CURDIR}
SRC := $(TOP)/src
# X for the base, as NetBSD builds it (build.sh -x -X, src/BUILDING): imported
# like src/, its upstream commit in xsrc/BASE (Konrad, 2026-11-13).
XSRC := $(TOP)/xsrc
OBJ := $(TOP)/build/obj
JOBS ?= $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 2)
# sysctl(8) is in /sbin, which a non-login shell's PATH may lack.
.if !defined(JOBS)
JOBS != nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || \
/sbin/sysctl -n hw.ncpu 2>/dev/null || echo 2
.endif
ARCH ?= $(shell uname -m 2>/dev/null | sed -e 's/x86_64/amd64/' -e 's/aarch64/evbarm/' || echo amd64)
.if !defined(ARCH)
ARCH != uname -m 2>/dev/null | sed -e 's/x86_64/amd64/' -e 's/aarch64/evbarm/' || echo amd64
.endif
# build.sh wants NetBSD's machine name. For the architectures where the two
# names differ, this is the mapping; everything else is passed through.
MACHINE := $(ARCH)
ifeq ($(ARCH),amd64)
.if ${ARCH} == "amd64"
MACHINE := amd64
endif
ifeq ($(ARCH),i386)
.elif ${ARCH} == "i386"
MACHINE := i386
endif
.endif
BUILD_SH := cd $(SRC) && ./build.sh \
-U -u -j $(JOBS) -m $(MACHINE) \
-M $(OBJ) -O $(OBJ) -x -X $(XSRC)
# The recursive make for cdtest. Not spelled $(MAKE): GNU make runs a recipe
# that contains $(MAKE) even with -n, and the rest of the cdtest line would
# start a VM; MAKE_CMD is only printed.
# The recursive make for cdtest and release. With -n, make(1) runs a command
# only for a .MAKE target or a line starting with `+' (make(1), -n), so `make -n
# cdtest' prints the line and starts no VM. MAKE_CMD keeps it that way should
# the recipe ever be marked .MAKE.
MAKE_CMD := $(MAKE)
.PHONY: all build release install tools kernel clean-sanity stamp test compress \
@@ -174,7 +183,7 @@ install:
@uname -s | grep -qx NetBSD || { \
echo "make install: this installs over the running system,"; \
echo "make install: which only makes sense on Makronix/NetBSD."; \
echo "make install: on $(shell uname -s), build with 'make' instead."; \
echo "make install: on $$(uname -s), build with 'make' instead."; \
exit 1; }
@tools/build-lock.sh '$(BUILD_SH) install=/'