#!/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 : " -- 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) are not in pkgsrc: the archive of each, from # its last commit, goes into DISTDIR, the recipes into pkgsrc/ (MCDE and its # Motif are one archive, one tool). Only the forks the list names. ext_prepare() { for d in "$TOP"/ext/src/*/pkgsrc; do [ -f "$d/Makefile" ] || continue n=$(basename "$(dirname "$d")") "$TOP/tools/pkglist.sh" built | grep -q "/$n\$" || continue if [ "$n" = mcde ]; then "$TOP/tools/mcde-dist.sh" || die "tools/mcde-dist.sh failed" else "$TOP/tools/ext-dist.sh" "$n" || die "tools/ext-dist.sh $n failed" fi done esout=$TOP/build/ext-sync.out "$TOP/tools/ext-sync.sh" > "$esout" || die "tools/ext-sync.sh failed" FORKS=$(sed 's/^ext-sync: //' "$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). make_repo() { repo=$("$TOP/tools/pkglist.sh" repo) [ -n "$repo" ] || return 0 out=$TOP/build/packages/$ARCH/All rm -rf "$out" mkdir -p "$out" for p in $repo; do { echo "$p" (cd "$PKGSRC/$p" && "$BMAKE" show-depends-recursive 2> /dev/null) } | sort -u | while read -r d; do n=$(cd "$PKGSRC/$d" && "$BMAKE" -V '${PKGNAME}') cp "$TOP/build/packages/All/$n.tgz" "$out/" || echo "userland: no package $n.tgz for $d" >&2 done done (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" </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)" "$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 n in $("$TOP/tools/pkglist.sh" sysroot -n); do 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 } # 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 echo "userland: $1: recipe changed, configuring again (objects kept)" 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 } 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 for p in $("$TOP/tools/pkglist.sh" built); do phase "package $p" echo "=== chroot: $p" "$TOP/tools/pkgchroot.sh" build "$p" || failed="$failed $p" done else for p in $("$TOP/tools/pkglist.sh" built); do # a fork of ext/ starts from a clean work directory when its recipe # changed -- otherwise pkgsrc keeps the old configure. A new archive # (distinfo) is not a reason: tools/ext-resync.sh puts only the files that # differ into the work directory, and make builds what depends on them # (a new archive used to mean a build from nothing: ten minutes of MCDE # for one changed file, build/logs/userland-2026-11-14p.log). The # PLIST is not part of the key either: it only needs the install again. forkclean= case " $(echo $FORKS) " in *" $p "*) key=$(cd "$PKGSRC/$p" && find . -type f ! -name distinfo ! -name PLIST | sort | xargs cat | 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 if ! "$TOP/tools/ext-resync.sh" resync "$p"; then (cd "$PKGSRC/$p" && "$BMAKE" clean) > /dev/null 2>&1 || true forkclean=yes 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) archive=$(cd "$PKGSRC/$p" && "$BMAKE" show-var VARNAME=DISTDIR)/$(cd "$PKGSRC/$p" && "$BMAKE" show-var VARNAME=DISTFILES | awk '{print $1}') 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, archive or distinfo changed cand="$key:$(sha256_of "$archive" 2>/dev/null)" 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" # the archive this work directory was extracted from, for the next resync. # Kept also when the build failed: the work directory holds that archive # all the same, and without .pristine the next run had to `bmake clean' # and compile MCDE from nothing after every error (2026-11-17, # build/logs/userland-2026-11-17b..d.log). case " $(echo $FORKS) " in *" $p "*) w=$(ls -d "$TOP/build/pkgsrc-work/$p"/work.* 2>/dev/null | head -1) if [ -n "$w" ] && [ -f "$w/.extract_done" ] && { [ "$forkclean" = yes ] || [ ! -d "$TOP/build/pkgsrc-work/$p/.pristine" ]; }; then "$TOP/tools/ext-resync.sh" snapshot "$p" || true fi 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)"