Files
lotherk 6199effa3c $Makronix$ in libmxlinux, the rule in AGENTS.md, and build/logs for a clone
Three gaps, all found by running `make release' on a fresh clone instead of
trusting the tree that had been built in for weeks.

1. tools/userland.sh: fetch_binaries redirects into build/logs/, but nothing
   created that directory: a clone has no build/ below AGENTS.md, so step 2/7
   died with "Error code 1" from the shell, before pkg-binaries.sh ran, and
   the log it points at was never written.  mkdir -p first.  The other two
   redirects into build/logs (pkg-add, pkg-delete) come after it.

2. src/lib/libmxlinux: four files had no header at all (mx_termios.h,
   mxlinux.h, mx_locale.c, mx_fgetwln.c).  They now carry `/*\t$Makronix$\t*/'
   like the other 61 there, and all 71 files of the directory have one.
   Checked with gcc -fsyntax-only on each of the four.

3. AGENTS.md says the header rule once, in "Licence": `#\t$Makronix$' in a
   file Makronix wrote, `$NetBSD: <file>,v <rev> ... Exp $' in one taken from
   pkgsrc, never the unfilled template -- the detail is in ext/AGENTS.md
   ("Header").

Tested: tools/test-tools.sh 42 ok, 0 bad.  gcc -fsyntax-only clean on the four
files.  The directory builds through `make userland' (mobile/userland/mk/
mx.prog.mk: mx-lib), not standalone: a plain `bmake' in src/lib/libmxlinux has
no NETBSDSRCDIR (getopt.c comes through .PATH) -- not caused by this change,
the same command failed the same way before it.
2026-11-24 03:33:56 +00:00

739 lines
32 KiB
Bash
Executable File

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# userland.sh -- the pkgsrc userland of Makronix, in one command.
#
# usage: userland.sh
#
# Builds the packages of packages.list (tools/pkglist.sh reads it): the ones of
# the "makronix" set are installed into the sysroot and listed by
# tools/makronix-set.sh, the ones of the media's repository ("repo") become
# the binary repository build/packages/ARCH/All with a pkg_summary.gz.
#
# One build for both hosts, detected here once (root AGENTS.md, "Building"):
#
# cross the host is not NetBSD: pkgsrc's cross mode builds for the target
# with this tree's toolchain (tools/pkgsrc-cross.mk.conf) and
# installs into build/obj/destdir.ARCH.
# native the host is NetBSD: the same packages, built by the host's pkgsrc
# into its /usr/pkg. (Written to the same list and the same loop;
# not run yet -- there is no NetBSD build host in this tree today.)
#
# Nothing is built in a VM. A package that fails does not stop the others:
# every package is tried, the ones that failed are named at the end, and the
# exit status is that of the whole run.
set -eu
TOP=$(cd "$(dirname "$0")/.." && pwd)
# This tool writes build/obj or releasedir: only inside the build lock.
if [ -z "${BUILD_LOCK_HELD:-}" ] || [ ! -d "$BUILD_LOCK_HELD" ]; then
echo "${0##*/}: run this through make or tools/build-lock.sh" >&2
exit 1
fi
export MAKRONIX_TOP=$TOP
# The root Makefile is run by the host's make(1) (bmake on Linux), which passes
# `.MAKE.LEVEL.ENV=MAKELEVEL' in MAKEFLAGS; the older bmake of pkgsrc
# (build/pkg/bin/bmake) stops on it: 'Cannot delete ".MAKE.LEVEL.ENV" as it is
# read-only' (measured 2026-11-22, make release step 2). Nothing below wants
# the parent's flags.
unset MAKEFLAGS MAKELEVEL MFLAGS
ARCH=amd64
PKGSRC=$TOP/pkgsrc
# How the packages of the set are built. Both paths fill the same sysroot
# (build/obj/destdir.$ARCH, PREFIX /usr/pkg) and both end in the same makronix
# set; the difference is only how this host can build a Makronix program:
#
# chroot this host IS Makronix: chroot into the sysroot and build there with
# its compiler, its libraries and its package tools
# (tools/pkgchroot.sh). NetBSD builds its own packages this way.
# cross the host is not Makronix (Linux): pkgsrc cross-builds for the
# sysroot with this tree's toolchain (tools/pkgsrc-cross.mk.conf).
#
# Measured 2026-11-20: the cross path is what made x11-links, the cross
# libtool, freetype and the host X tools fail one after the other on
# makronix-build; in the chroot they build with no case for the host at all.
# USERLAND_MODE=native keeps the old branch for packages of the running host.
MODE=${USERLAND_MODE:-}
[ -n "$MODE" ] || case $(uname -s) in
NetBSD) MODE=chroot ;;
*) MODE=cross ;;
esac
case $MODE in
native) BMAKE=${BMAKE:-/usr/pkg/bin/bmake} ;;
chroot) BMAKE=$TOP/build/pkg/bin/bmake ;; # -V queries only; the build runs in the chroot
cross) BMAKE=$TOP/build/pkg/bin/bmake ;;
*) echo "userland: unknown USERLAND_MODE=$MODE" >&2; exit 1 ;;
esac
die()
{
echo "userland: $*" >&2
exit 1
}
# sha256 on Linux and on NetBSD (cksum(1) there; there is no sha256sum),
# the same helper tools/build-stamp.sh and tools/makronix-distfiles.sh carry.
# Without it every key here came out empty and the fork archives got no
# distinfo entry ("checksum: No checksum recorded" in pkgsrc/x11/mcde-motif,
# measured 2026-11-19 on makronix-build).
sha256_in()
{
if command -v sha256sum > /dev/null 2>&1; then
sha256sum | cut -d' ' -f1
else
cksum -a sha256 | awk '{ print $NF }'
fi
}
sha256_of()
{
if command -v sha256sum > /dev/null 2>&1; then
sha256sum "$1" | cut -d' ' -f1
else
cksum -a sha256 "$1" | awk '{ print $NF }'
fi
}
# serialize runs: another userland (or a dist invocation) holding the lock
# makes this one stop instead of overwriting shared distfiles (tasksd t0229)
LOCK=$TOP/build/.userland.lock
acquire_lock()
{
if mkdir "$LOCK" 2>/dev/null; then
echo $$ > "$LOCK/pid"
return 0
fi
ipid=$(cat "$LOCK/pid" 2>/dev/null || true)
if [ -n "$ipid" ] && kill -0 "$ipid" 2>/dev/null; then
echo "userland: another run holds $LOCK (pid $ipid); aborting" >&2
exit 1
fi
rm -rf "$LOCK"
if mkdir "$LOCK" 2>/dev/null; then
echo $$ > "$LOCK/pid"
return 0
fi
echo "userland: cannot acquire $LOCK" >&2
exit 1
}
release_lock() { rm -rf "$LOCK"; }
trap release_lock EXIT HUP INT TERM
acquire_lock
# ext-dist.sh and mcde-dist.sh are called from this run: they see that this
# pid holds the lock and must not take it again or release it
export MX_USERLAND_LOCK=$$
# pkgsrc's mk.conf holds the copy of tools/pkgsrc-cross.mk.conf that the
# bootstrap made; the live file is included after it (plain assignments, so
# twice is the same), and a change in the fragment needs no re-bootstrap.
ensure_mkconf()
{
mk=$TOP/build/pkg/etc/mk.conf
grep -q '^\.include.*pkgsrc-cross\.mk\.conf' "$mk" ||
printf '\n.include "%s/tools/pkgsrc-cross.mk.conf"\n' "$TOP" >> "$mk"
}
# configure records CFLAGS/CPPFLAGS/LDFLAGS in a package's work Makefile, so an
# existing work directory keeps the flags it was configured with. When the cross
# fragment or the generated host mk.conf changes, the build list must be
# reconfigured (measured 2026-11-13: -include freetype/ftsynth.h took effect
# only after `bmake clean' in fonts/Xft2). Key over tools/pkgsrc-cross.mk.conf
# and build/pkg/etc/mk-host.conf (if present), like the per-fork recipe key.
ensure_mk_key()
{
[ $MODE = cross ] || return 0
hc=$TOP/build/pkg/etc/mk-host.conf
kf=$TOP/build/pkgsrc-work/.makronix-mk-key
key=$( (cat "$TOP/tools/pkgsrc-cross.mk.conf"; [ -f "$hc" ] && cat "$hc") \
| sha256_in)
[ "$(cat "$kf" 2>/dev/null)" = "$key" ] && return 0
echo "userland: mk.conf changed, cleaning package work directories"
# every package that has a work directory for the target, not only the ones
# of packages.list: flex, tcl and Xft2 are built as dependencies, and kept the
# configuration of the old mk.conf (t0195, build/logs/userland-2026-11-14g.log).
# The host tools have work directories of their own platform
# (work.Linux-...), which `bmake clean' here leaves alone.
for w in "$TOP"/build/pkgsrc-work/*/*/work.NetBSD-*; do
[ -d "$w" ] || continue
p=${w%/*}; p=${p##*/pkgsrc-work/}
[ -f "$PKGSRC/$p/Makefile" ] || continue
(cd "$PKGSRC/$p" && "$BMAKE" clean) > /dev/null 2>&1 || true
done
mkdir -p "${kf%/*}" && printf "%s\n" "$key" > "$kf"
}
# pkgsrc's bootstrap: the prefix with bmake and the package tools for this
# host, in build/pkg. Needed for "from zero": `make release` on a fresh tree
# has no build/pkg, and every mode reads it -- cross for the tool bmake, chroot
# and native for pkg_info and pkg_delete, which tools/makronix-set.sh and the
# reinstall logic call by that path. The target system does not need it: it
# has /usr/bin/make and /usr/sbin/pkg_add in its base sets (base-util-bin,
# base-pkgutil-bin), so pkgsrc works there with no bootstrap of its own.
ensure_bootstrap()
{
[ -x "$BMAKE" ] && return 0
echo "=== pkgsrc bootstrap ($MODE)"
[ -d "$PKGSRC/bootstrap" ] || die "no $PKGSRC/bootstrap (pkgsrc submodule, PINS)"
if [ $MODE = cross ]; then
# The bootstrap copies the fragment it is given into mk.conf, and a later
# change of tools/pkgsrc-cross.mk.conf then never took effect (13.11.: NATIVE_CC
# for devel/gmp; t0053). What it is given is a fragment that only includes
# the real one, so mk.conf always reads the file of the tree and holds no
# copy of its values.
frag=$TOP/build/pkgsrc-mk-fragment.conf
printf '# written by tools/userland.sh (ensure_bootstrap): the settings are in the tree\n.include "%s/tools/pkgsrc-cross.mk.conf"\n' "$TOP" > "$frag"
(cd "$PKGSRC/bootstrap" && env MAKRONIX_TOP="$TOP" \
./bootstrap --unprivileged --prefer-native=yes --prefix "$TOP/build/pkg" \
--mk-fragment "$frag" \
--workdir "$TOP/build/pkgsrc-bootstrap")
else
# native and chroot build for this host, so the bootstrap's own
# defaults are right; --unprivileged because the build runs as the
# user who owns the tree (chroot installs into the sysroot, not into
# the host's /usr/pkg).
(cd "$PKGSRC/bootstrap" && env MAKRONIX_TOP="$TOP" \
./bootstrap --unprivileged --prefer-native=yes --prefix "$TOP/build/pkg" \
--workdir "$TOP/build/pkgsrc-bootstrap")
fi
[ -x "$BMAKE" ] || die "bootstrap did not produce $BMAKE"
}
# A pkg_add that dies leaves the sysroot's by-file index claiming files of a
# package that is not registered, and every later install then stops with
# "conflicting PLIST with <pkg>: <file>" -- measured 2026-11-13: x11-links-1.37,
# 751 entries in pkgdb.byfile.db for a package the pkgdb no longer knew, and
# x11/mcde-motif and wm/mcde failed on it (build/logs/userland-2026-11-13r.log).
# pkg_admin rebuild is pkg_install's own repair; it has no prefix option and so
# sees only /usr/pkg of this host, which leaves an index with few entries --
# the point is that the stale ones are gone, and pkg_add adds what it installs.
ensure_pkgdb()
{
db=$TOP/build/obj/destdir.$ARCH/usr/pkg/pkgdb
[ -d "$db" ] || return 0
"$TOP/build/pkg/sbin/pkg_admin" -K "$db" rebuild > /dev/null 2>&1 || true
}
# The forks of ext/ (ext/AGENTS.md) build from their own source tree, which is
# in this repository and travels with the source set -- no archive is made and
# none is fetched (the recipe's do-extract copies ext/src/<name> into WRKSRC).
# Their recipes have to be visible inside pkgsrc, which is what ext-sync.sh
# does: a mirror of symlinks to ext/src/<name>/pkgsrc.
ext_prepare()
{
esout=$TOP/build/ext-sync.out
"$TOP/tools/ext-sync.sh" > "$esout" || die "tools/ext-sync.sh failed"
# the first field only: "<category>/<name> from <dir>"
FORKS=$(sed -n 's/^ext-sync: \([^ ]*\) from .*/\1/p' "$esout")
}
# The media's repository: the packages of kind "repo" and what they need at
# run time, from the packages the build made (build/packages/All), as a
# repository with a pkg_summary.gz that pkg_add can use (tools/cd3.sh).
#
# Only run-time dependencies belong here, and the built package itself says
# which those are: +CONTENTS carries them as @pkgdep. `show-depends-recursive'
# was wrong for this: it lists the build tools as well (pkgtools/cwrappers,
# libnbcompat, mktools, digest), which are built for the build host and have no
# package for the target -- seven "no package ... .tgz" lines in every release
# (measured 2026-11-23). A run-time dependency that the build did not produce
# is a real error and is reported as one.
make_repo()
{
repo=$("$TOP/tools/pkglist.sh" repo)
[ -n "$repo" ] || return 0
out=$TOP/build/packages/$ARCH/All
# This directory also holds the NetBSD project's binary packages
# (tools/pkg-binaries.sh), 935 MB that a run must not throw away: this used
# to be an `rm -rf $out', so every release deleted the download and fetched
# it again (measured 2026-11-23 on the MacBook, four runs of 20 minutes).
# What is cleared is exactly what this function copied last time, listed in
# .repo-files. It used to consult .fetch-files for that, but that manifest
# is written one level up ($ARCH, not $ARCH/All): it was never found here,
# every .tgz looked foreign, and the whole download was deleted anyway
# (measured 2026-11-23: 282 packages gone, then perl missing for automake).
mkdir -p "$out"
if [ -f "$out/.repo-files" ]; then
while read -r b; do
[ -n "$b" ] && rm -f "$out/$b"
done < "$out/.repo-files"
fi
: > "$out/.repo-files"
missing=
# The run-time closure. A package's +CONTENTS names its own run-time
# dependencies as "@pkgdep name>=version", and those can depend again:
# pkg_add reads only what is in this repository, so the closure is closed
# here. One pass per package is enough in practice, but the loop keeps
# going while the set still grows -- a three-deep chain is not unusual.
# `show-depends-recursive' was wrong for this: it also lists the build
# tools (pkgtools/cwrappers, libnbcompat, mktools, digest), which are made
# for the build host and have no package for the target -- seven "no
# package ... .tgz" lines in every release (measured 2026-11-23).
add_pkg()
{
[ -f "$out/$1.tgz" ] && return 0
if [ ! -f "$TOP/build/packages/All/$1.tgz" ]; then
missing="$missing $1"
return 0
fi
cp "$TOP/build/packages/All/$1.tgz" "$out/"
echo "$1.tgz" >> "$out/.repo-files"
}
for p in $repo; do
n=$(cd "$PKGSRC/$p" && "$BMAKE" -V '${PKGNAME}')
add_pkg "$n"
done
grew=1
while [ -n "$grew" ]; do
grew=
before=$(ls "$out" | grep -c '\.tgz$' || true)
for f in "$out"/*.tgz; do
[ -f "$f" ] || continue
tar -xzOf "$f" +CONTENTS 2>/dev/null |
sed -n 's/^@pkgdep //p' |
sed 's/[<>=].*$//' > "$out/.deps" || true
while read -r d; do
[ -n "$d" ] || continue
add_pkg "$d"
done < "$out/.deps"
done
rm -f "$out/.deps"
after=$(ls "$out" | grep -c '\.tgz$' || true)
if [ "$after" -gt "$before" ]; then grew=1; fi
done
[ -z "$missing" ] ||
echo "userland: no package for:$missing -- these are run-time dependencies" >&2
(cd "$out" && "$TOP/build/pkg/sbin/pkg_info" -X ./*.tgz | gzip -9 > pkg_summary.gz)
echo "userland: $(ls "$out" | grep -c '\.tgz$') packages in ${out#$TOP/}"
}
# The host tools -- the stage that build.sh calls "tools" for NetBSD itself.
# pkgsrc's cross mode expects a NetBSD host, where a package built for the
# target also runs as a build tool. On this host a missing tool (TOOL_DEPENDS:
# glib2-tools, py-docutils, p5-XML-Parser, ...) would be built with the target
# compiler and refused by pkg_add ("was built for a different platform"). So
# each one is built for THIS host, with the host's compiler, into the Linux
# prefix build/pkg, by a configuration that has none of the cross settings
# (mk-host.conf); the cross build then finds it installed.
host_tools()
{
hc=$TOP/build/pkg/etc/mk-host.conf
# the archives: distfiles/ of the tree (they are part of the repository
# since 2026-11-19), else the shared directory beside it
HOSTDIST=$TOP/distfiles
[ -d "$HOSTDIST" ] || HOSTDIST=$TOP/../distfiles
# the awk of the bootstrap where it made one (a Linux host), else the
# system's: a bootstrap on NetBSD installs no nawk, and pointing at the
# missing file stopped every dependency check ("build/pkg/bin/nawk: not
# found", measured 2026-11-20 on the MacBook)
HOSTAWK=
[ -x "$TOP/build/pkg/bin/nawk" ] && HOSTAWK="TOOLS_PLATFORM.awk?= $TOP/build/pkg/bin/nawk"
cat > "$hc" <<CONF
# written by tools/userland.sh: pkgsrc for THIS host (no cross settings)
.ifdef BSD_PKG_MK
ABI= 64
UNPRIVILEGED= yes
PKG_DBDIR= $TOP/build/pkg/pkgdb
LOCALBASE= $TOP/build/pkg
SYSCONFBASE= $TOP/build/pkg/etc
VARBASE= $TOP/build/pkg/var
PKG_TOOLS_BIN= $TOP/build/pkg/sbin
PKGINFODIR= info
PKGMANDIR= man
PREFER_NATIVE= yes
X11_TYPE= modular
SKIP_LICENSE_CHECK= yes
DISTDIR= $HOSTDIST
WRKOBJDIR= $TOP/build/pkgsrc-work-host
PACKAGES= $TOP/build/packages-host
$HOSTAWK
.endif
CONF
# Looking the tools up costs 38 s (84 package directories, two bmake runs
# each; measured 2026-11-17) and finds nothing new as long as the list,
# the pkgsrc pin and this configuration are the same: keyed, and the key
# is written only after a run in which every tool was there or got built.
htkey=$( { "$TOP/tools/pkglist.sh" built; git -C "$PKGSRC" rev-parse HEAD
cat "$hc"; } | sha256_in)
htkf=$TOP/build/pkg/.makronix-host-tools-key
if [ "$(cat "$htkf" 2>/dev/null)" = "$htkey" ]; then
echo "userland: host tools unchanged"
return 0
fi
# the tools of every package that gets built, not only of the listed
# ones: a dependency's TOOL_DEPENDS (cmake, curl for a library of the X
# server) is built on the way just the same
dirs=$(for p in $("$TOP/tools/pkglist.sh" built); do
echo "$p"
(cd "$PKGSRC/$p" && "$BMAKE" show-depends-recursive 2> /dev/null)
done | sort -u)
wanted=$(for d in $dirs; do
(cd "$PKGSRC/$d" && "$BMAKE" show-var VARNAME=TOOL_DEPENDS 2> /dev/null)
done | tr ' ' '\n' | grep ':\.\./\.\./' | sort -u)
hostfailed=
for t in $wanted; do
pat=${t%%:*}
d=${t#*:../../}
"$TOP/build/pkg/sbin/pkg_info" -K "$TOP/build/pkg/pkgdb" -E "$pat" \
> /dev/null 2>&1 && continue
echo "=== host tool: $d ($pat)"
(cd "$PKGSRC/$d" && MAKECONF=$hc "$BMAKE" install) ||
hostfailed="$hostfailed $d"
done
if [ -z "$hostfailed" ]; then
printf '%s\n' "$htkey" > "$htkf"
else
rm -f "$htkf"
echo "userland: host tools that failed:$hostfailed" >&2
fi
}
# The packages of kind "fetch" (tools/pkglist.sh fetch): the NetBSD project's
# binaries, taken instead of a build because Makronix does not patch them.
# They are installed into the sysroot BEFORE the build loop, for two reasons:
# a package built here can depend on one -- wm/mcde needs ksh93 for dtksh, and
# ksh93's own bin/package refuses to cross-build (tools/pkglist.sh; t0172) --
# and the makronix set is read back from what is installed
# (tools/makronix-set.sh), so the set then holds the binaries that are really
# there instead of leftovers from an earlier run.
fetch_binaries()
{
[ -n "$("$TOP/tools/pkglist.sh" fetch)" ] || return 0
echo "=== binary packages (fetch)"
# a fresh clone has no build/logs: the directory is what this run writes
# into, and redirecting into a directory that does not exist fails before
# pkg-binaries.sh runs (measured 2026-11-24 on a clone, step 2/7)
mkdir -p "$TOP/build/logs" || die "cannot create build/logs"
"$TOP/tools/pkg-binaries.sh" -a "$ARCH" fetch \
> "$TOP/build/logs/pkg-binaries-$ARCH.log" 2>&1 ||
die "tools/pkg-binaries.sh fetch failed (build/logs/pkg-binaries-$ARCH.log)"
repo=$TOP/build/packages/$ARCH/All
[ -d "$repo" ] || die "no binary packages in ${repo#$TOP/}"
dest=/usr/pkg
db=/usr/pkg/pkgdb
if [ $MODE != native ]; then
dest=$TOP/build/obj/destdir.$ARCH/usr/pkg
db=$dest/pkgdb
fi
# only the kind "bin": the others are on the media for sysinst, and pkg_add into
# the sysroot refused most of them anyway (a library it could not find, a name
# that is not the last part of the PKGPATH) -- noise in every run (t0205)
for pp in $("$TOP/tools/pkglist.sh" sysroot); do
# the name of a package is not the last part of its PKGPATH
# (lang/perl5 is perl-5.x, sysutils/py-borgbackup py313-...):
# ask the repository summary the fetch just wrote, and fall back
# to the path when it has no entry
n=
for sum in "$repo/pkg_summary.gz" "$TOP/build/packages/$ARCH/pkg_summary.repo.gz"; do
[ -s "$sum" ] || continue
n=$(zcat "$sum" 2>/dev/null |
awk -v p="$pp" '/^PKGNAME=/{n = substr($0, 9)}
/^PKGPATH=/{ if (substr($0, 9) == p && n != "") { print n; exit } }')
[ -n "$n" ] && break
done
[ -n "$n" ] || n=${pp##*/}
if "$TOP/build/pkg/sbin/pkg_info" -K "$db" -e "$n" > /dev/null 2>&1; then
continue
fi
echo "=== fetch: $n"
# cross: -P makes the sysroot the root of every path, -K included
# (pkg_add(1): "Prefix all file and directory names with
# destdir"), so the libraries a package REQUIRES are looked for
# there; with -p alone pkg_add looked on this host and refused
# ksh93: "missing required library: /usr/lib/libc.so.12"
# (build/logs/pkg-add-ksh93.log, 2026-11-14), and wm/mcde, which
# needs it, failed again building it from source
if [ $MODE != native ]; then
set -- -P "$TOP/build/obj/destdir.$ARCH" -K /usr/pkg/pkgdb
else
set -- -K "$db"
fi
PKG_PATH=$repo "$TOP/build/pkg/sbin/pkg_add" "$@" \
-m "NetBSD/x86_64 11.99.9" -I "$n" \
> "$TOP/build/logs/pkg-add-$n.log" 2>&1 ||
echo "userland: could not install $n (build/logs/pkg-add-$n.log)" >&2
done
}
# What the build of a fork is made from: the commit of its source tree, or --
# for a recipe that builds from an archive (afpfs-ng) -- the hash of its
# distinfo. A tree that is not a git checkout (a source set on a target)
# contributes nothing, which keeps the key stable there.
srcid_of()
{
case $1 in
x11/mcde-motif) _s=$TOP/ext/src/mcde ;;
*) _s=$TOP/ext/src/${1##*/} ;;
esac
if [ -e "$_s/.git" ]; then
git -C "$_s" rev-parse HEAD 2>/dev/null
git -C "$_s" status --porcelain 2>/dev/null
elif [ -f "$TOP/pkgsrc/$1/distinfo" ]; then
sha256_in < "$TOP/pkgsrc/$1/distinfo"
fi
}
# fork_reconfigure PKGPATH -- the recipe of a fork changed: run pkgsrc again
# from `depends' on, but keep the extracted sources and the built objects.
# `bmake clean' here meant hours of MCDE for a one-line recipe change
# (2026-11-17, ac_cv_path_GO). The forks have no patches/ (checked
# 2026-11-17: ext/src/*/pkgsrc*/patches does not exist), so extract and patch
# stay valid; SUBST keeps its cookies (a second pass over a substituted file
# is a no-op, which SUBST treats as an error). configure runs again in the
# tree: config.status rewrites config.h only when it differs, so make
# recompiles what the new configuration touches. .package_done goes too: in
# a cross build `install' adds the binary package, and a kept cookie installs
# the old one (pkgsrc/mk/package/package.mk:35).
fork_reconfigure()
{
w=$(ls -d "$TOP/build/pkgsrc-work/$1"/work.* 2>/dev/null | head -1)
[ -n "$w" ] && [ -f "$w/.extract_done" ] || return 0
# A commit in the fork changes the source, and do-extract runs only once
# (its cookie): without dropping that cookie the work directory keeps the
# copy of the commit it was extracted from, and the release ships a binary
# that does not match the tree (measured 2026-11-23 for mcde). The
# extract is cheap now -- tools/ext-extract.sh copies only the files that
# differ and leaves the time stamps of the rest alone, so the object files
# of everything else survive.
if [ "$(srcid_of "$1")" != "$(cat "$TOP/build/pkgsrc-work/$1/.makronix-srcid" 2>/dev/null)" ]; then
echo "userland: $1: source changed, extracting the copy again"
rm -f "$w/.extract_done" "$w/.patch_done"
mkdir -p "$TOP/build/pkgsrc-work/$1"
srcid_of "$1" > "$TOP/build/pkgsrc-work/$1/.makronix-srcid"
else
echo "userland: $1: recipe changed, configuring again (objects kept)"
fi
rm -f "$w/.barrier_cookie" "$w/.depends_done" "$w/.depends" \
"$w/.rdepends" "$w/.rrdepends" "$w/.tools_done" "$w/.wrapper_done" \
"$w/.configure_done" "$w/.build_done" "$w/.install_done" \
"$w/.package_done" "$w"/.PLIST* "$w/.tools_makevars.mk" \
"$w/.wrapper_makevars.mk" "$w/.configure_makevars.mk" \
"$w/.build_makevars.mk" "$w/.stage-install_makevars.mk"
rm -rf "$w/.buildlink" "$w/.x11-buildlink" "$w/.cwrapper" "$w/.tools" \
"$w/.gcc" "$w/.compiler"
# pkgsrc reaches the tools phase only on the way to extract, which stays
# done: without this, configure found no compiler wrapper ("C compiler
# cannot create executables", build/logs/userland-2026-11-17i.log:304)
(cd "$PKGSRC/$1" && "$BMAKE" tools) || return 1
}
# The tree carries pkgsrc, the forks of ext/ and the reference trees as git
# submodules (git submodule status). A fresh clone has none of them checked
# out, and the release cannot run without them: PKGSRC/bootstrap, the recipes
# in ext/src/*/pkgsrc, tools/ext-dist.sh's archives. Doing it here, before
# anything reads those paths, is what makes `make release` on a bare clone the
# same command as on a tree that was prepared by hand (Konrad, 2026-11-23:
# makronix carries everything it needs, in the repository, always complete).
#
# --depth 1 is not used: PINS records a commit per submodule and a shallow
# clone cannot check out anything but the tip. A submodule that is already at
# its pinned commit costs one `git submodule update` that does nothing.
ensure_submodules()
{
[ -f "$TOP/.gitmodules" ] || return 0
# `git submodule status' prefixes the commit: '-' for one that is not
# checked out, '+' for one at the wrong commit, ' ' for the pinned one.
# (The prefix is glued to the hash, so the test is on the first character
# of the line, not on a field.)
#
# refs/ is left out: those are reference trees (the Linux kernel alone is
# tens of gigabytes) that tools/srctree-stage.sh keeps out of the source
# set and no build step reads. Checking them out turned a fresh clone's
# `make release` into a 36 GB download (measured 2026-11-23).
#
# `|| true' on the pipeline: this script runs under `set -e', and grep
# exits 1 when the filter leaves nothing -- which is the good case, every
# submodule at its pin. Without it the build stopped here in silence
# (measured 2026-11-23: step 2, exit 1, no message).
need=$(cd "$TOP" && git submodule status 2>/dev/null |
awk 'substr($0, 1, 1) == "-" || substr($0, 1, 1) == "+" { print $2 }' |
grep -v '^refs/' || true)
[ -n "$need" ] || return 0
echo "userland: submodules at their pin: $(echo $need)"
# A submodule that cannot be fetched (a private tree this build does not
# use, no credentials on the host) must not stop the release: it is only
# needed when something reads it, and that read fails with a clear message.
# The ones that matter -- pkgsrc and the ext/ forks -- are checked below.
for sub in $need; do
(cd "$TOP" && git submodule update --init -- "$sub") ||
echo "userland: warning: $sub is not checked out" >&2
done
[ -d "$PKGSRC/bootstrap" ] ||
die "$PKGSRC is not checked out (git submodule update --init pkgsrc)"
for w in "$TOP"/ext/src/*/pkgsrc; do
[ -d "$w" ] || continue
p=${w%/pkgsrc}; p=${p##*/}
[ -n "$(ls -A "$w" 2>/dev/null)" ] ||
die "ext/src/$p is not checked out (its recipe is needed)"
done
}
ensure_submodules
ensure_bootstrap
echo "userland: $MODE build on $(uname -s)"
[ $MODE = cross ] && ensure_mkconf
# both paths install into the sysroot; a pkg_add that died leaves its by-file
# index pointing at files nobody owns, and the next install of that package
# stops with "conflicting PLIST" (see ensure_pkgdb)
[ $MODE != native ] && ensure_pkgdb
# the time of each step in the log: where a run spends its minutes
phase() { echo "userland: [$(date +%T)] $*"; }
# Every package in the sysroot was built the same way, and its .la files say
# which way: a cross build writes "=/usr/pkg/lib/..." and a path into its
# work tree, a native one writes the plain path. Mixing both does not link --
# measured 2026-11-21: the MacBook kept the cross libgcrypt.la (pkg_add sees
# the same version already installed) and xmlto stopped with "'/usr/pkg/lib/
# libintl.la' is not a valid libtool archive". A change of way starts from an
# empty /usr/pkg; the old tree stays under build/ for inspection.
sf=$TOP/build/.sysroot-mode
pkgdir=$TOP/build/obj/destdir.$ARCH/usr/pkg
if [ -d "$pkgdir" ] && [ -n "$(ls -A "$pkgdir" 2>/dev/null)" ] &&
[ "$(cat "$sf" 2>/dev/null)" != "$MODE" ]; then
old=$TOP/build/usr-pkg.$(cat "$sf" 2>/dev/null || echo unknown)-$(date +%Y%m%d-%H%M)
mv "$pkgdir" "$old" ||
die "could not move the sysroot's /usr/pkg aside"
echo "userland: /usr/pkg was built as $(cat "$sf" 2>/dev/null || echo another way), this run is $MODE -- kept as ${old#$TOP/}"
mkdir -p "$pkgdir"
# the work directories belong to the same way: a cross work directory
# keeps its .depends_done and would install a package whose dependencies
# this sysroot no longer has
if [ -d "$TOP/build/sandbox/work" ] && [ -n "$(ls -A "$TOP/build/sandbox/work" 2>/dev/null)" ]; then
mv "$TOP/build/sandbox/work" "$old-work" ||
die "could not move the work directories aside"
fi
fi
mkdir -p "$pkgdir"
printf '%s\n' "$MODE" > "$sf"
phase "archives of the forks"
ext_prepare
phase "binary packages"
fetch_binaries
phase "host tools"
[ $MODE = cross ] && host_tools
ensure_mk_key
failed=
if [ $MODE = chroot ]; then
# Two targets, the same split the cross path makes: a package of the
# "makronix" set is installed into the sysroot, a package of the media's
# repository is built as a binary package. `install' does neither for a
# repository package -- it sees the version already recorded and keeps
# the old files, so build/packages/All stayed empty and make_repo had
# nothing to put on the media (measured 2026-11-23 on the MacBook).
for p in $("$TOP/tools/pkglist.sh" built); do
phase "package $p"
echo "=== chroot: $p"
if "$TOP/tools/pkglist.sh" repo | grep -qx "$p"; then
tgt=package
else
tgt=install
fi
"$TOP/tools/pkgchroot.sh" build "$tgt" "$p" || failed="$failed $p"
done
else
for p in $("$TOP/tools/pkglist.sh" built); do
# A fork of ext/ builds from its source tree, which the do-extract step
# copies into the work directory each build. When the recipe changed,
# the work directory starts clean -- otherwise pkgsrc keeps the old
# configure and the old Makefiles. There is no archive to resync any
# more: no tool has to bring a work directory up to date with a commit.
# The PLIST is not part of the key: it only needs the install again.
case " $(echo $FORKS) " in
*" $p "*)
# The work directory holds a *copy* of the source tree, made when
# pkgsrc extracted (do-extract: cp -R). A commit does not touch
# the recipe, so the recipe key alone would keep the old copy and
# the release would ship the binary of the last commit
# (2026-11-23: mcde 288d1383 built from 2026-11-22). The
# source commit is in the key for that reason.
key=$(cd "$PKGSRC/$p" && find . -type f ! -name PLIST | sort | xargs cat | sha256_in)
key="$key:$(srcid_of "$p" | sha256_in)"
kf=$TOP/build/pkgsrc-work/$p/.makronix-recipe-key
if [ "$(cat "$kf" 2>/dev/null)" != "$key" ]; then
fork_reconfigure "$p"
mkdir -p "${kf%/*}" && printf "%s\n" "$key" > "$kf"
fi
# the PLIST changed: install and package again, nothing else
pk=$TOP/build/pkgsrc-work/$p/.makronix-plist-key
pkey=$(sha256_in < "$PKGSRC/$p/PLIST")
if [ "$(cat "$pk" 2>/dev/null)" != "$pkey" ]; then
w=$(ls -d "$TOP/build/pkgsrc-work/$p"/work.* 2>/dev/null | head -1)
[ -z "$w" ] || rm -f "$w/.install_done" "$w"/.PLIST*
mkdir -p "${pk%/*}" && printf "%s\n" "$pkey" > "$pk"
fi ;;
esac
# a fork that is already registered in the sysroot is not installed again:
# pkg_add says "package `mcde-0.1.0' already recorded as installed" and the
# sysroot keeps the files of the build before -- libDtSvc.la with the work
# directory in it, 20:36, when the staged one was fixed at 23:04
# (build/logs/userland-2026-11-14t.log). The old version is removed first,
# so what is installed is what was built, and the makronix set is read from it.
case " $(echo $FORKS) " in
*" $p "*)
# Build the package BEFORE the old one is removed (bmake package
# runs the PLIST check): a package that fails here keeps the
# version in the sysroot. Measured 2026-11-16: the wm/mcde
# PLIST failure deleted the installed MCDE first, 2.5k files
# were gone and checkflist stopped every release
# (build/logs/userland-2026-11-16-signify2.log).
if ! (cd "$PKGSRC/$p" && "$BMAKE" package); then
failed="$failed $p"
continue
fi
if [ $MODE = cross ]; then
pn=$(cd "$PKGSRC/$p" && "$BMAKE" show-var VARNAME=PKGNAME)
if [ -n "$pn" ] && "$TOP/build/pkg/sbin/pkg_info" \
-K "$TOP/build/obj/destdir.$ARCH/usr/pkg/pkgdb" -e "$pn" > /dev/null 2>&1; then
# idempotent: only reinstall when the recipe or the
# source changed ($key carries both for a fork; a
# fork has no archive to hash)
cand="$key"
if [ "$(cat "$TOP/build/pkgsrc-work/$p/.installed-key" 2>/dev/null)" != "$cand" ]; then
"$TOP/build/pkg/sbin/pkg_delete" -f -P "$TOP/build/obj/destdir.$ARCH" \
-K /usr/pkg/pkgdb "$pn" > "$TOP/build/logs/pkg-delete-$pn.log" 2>&1 ||
echo "userland: could not remove $pn from the sysroot (build/logs/pkg-delete-$pn.log)" >&2
fi
printf '%s\n' "$cand" > "$TOP/build/pkgsrc-work/$p/.installed-candidate" 2>/dev/null || true
fi
fi ;;
esac
phase "package $p"
echo "=== $MODE: $p"
# set: installed into the sysroot; repo: the binary package (pkgsrc
# installs what it needs on the way)
if "$TOP/tools/pkglist.sh" repo | grep -qx "$p"; then
target=package
else
target=install
fi
(cd "$PKGSRC/$p" && "$BMAKE" $target) || failed="$failed $p"
case " $(echo $FORKS) " in
*" $p "*)
if [ -z "$failed" ] || [ "$failed" = "${failed% $p}" ]; then
# remember this build as the installed version, so the next run skips pkg_delete
[ -f "$TOP/build/pkgsrc-work/$p/.installed-candidate" ] && \
mv "$TOP/build/pkgsrc-work/$p/.installed-candidate" \
"$TOP/build/pkgsrc-work/$p/.installed-key"
fi ;;
esac
done
fi
phase "set and repository"
if [ $MODE != native ] && [ -z "$failed" ]; then
# a program a fork builds for its own build and runs (tradcpp, makestrs,
# wml ...) must be a binary of this host; one built for the target stops
# a cross build far from the cause (tasksd t0197). Measured ok on
# build/logs/userland-2026-11-15a.log.
[ $MODE = cross ] && { "$TOP/tools/check-buildtools.sh" ||
die "a build tool of a fork was built for the target (check-buildtools above)"; }
"$TOP/tools/makronix-set.sh"
fi
make_repo
[ -z "$failed" ] || die "these packages failed:$failed"
phase "done ($MODE)"