From c33d72f4d4ca3494dd59b5ca8f328d4b102eb581 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Tue, 22 Sep 2026 17:34:02 +0200 Subject: [PATCH] pkg-dist.mk, pkg.sh: Build RPMs in dist/build pkg.sh hardcodes $HOME/rpmbuild as the rpmbuild topdir while make computes the same location separately as PKG_DIR_BUILD, and a sandboxed shell cannot build at all: rpmbuild writes its scratch trees and results under the topdir, outside the project. - Default PKG_DIR_BUILD to $(TOPDIR)/dist/build for non-root builds and pass it to pkg.sh as the new -T option (root keeps /usr/src/packages; local.mk can still override) - Build with --define _topdir pointing at that directory, resolved to an absolute path, so the scratch tree, RPMS and SRPMS stay in the project tree where make clean drops them Signed-off-by: Jan Lindemann Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.87.0 --- make/pkg-dist.mk | 5 +++-- scripts/pkg.sh | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/make/pkg-dist.mk b/make/pkg-dist.mk index 6e3584ac..29b11eb7 100644 --- a/make/pkg-dist.mk +++ b/make/pkg-dist.mk @@ -67,9 +67,10 @@ else ifeq ($(BUILD_USER),root) PKG_DIR_BUILD = /usr/src/packages else - PKG_DIR_BUILD = $(HOME)/rpmbuild + PKG_DIR_BUILD ?= $(TOPDIR)/dist/build endif PKG_DIR_BINARY = $(PKG_DIR_BUILD)/RPMS/$(PKG_ARCH) + PKG_SH_EXTRA_ARGS += -T $(PKG_DIR_BUILD) endif DIST_DIRS = $(DIST_SRC_DIR) $(DIST_PCKG_DIR) @@ -106,7 +107,7 @@ PKG_SH = $(PKG_SH_EXE) \ -X "$(PKG_CONFLICTS_RUN)" -Y "$(PKG_CONFLICTS_DEVEL)" \ --provides-run "$(PKG_PROVIDES_RUN)" --provides-devel "$(PKG_PROVIDES_DEVEL)" \ -m $(JWB_SCRIPT_DIR) -a $(PKG_ARCH) -p $(DIST_PCKG_DIR) -F $(PKG_FORMAT) \ - -B $(PKG_UPLOAD_URLPREFIX) -A $(PKG_UPLOAD_FILE_ATTRIB) + -B $(PKG_UPLOAD_URLPREFIX) -A $(PKG_UPLOAD_FILE_ATTRIB) $(PKG_SH_EXTRA_ARGS) all: install: diff --git a/scripts/pkg.sh b/scripts/pkg.sh index ac8484a5..22e4738b 100644 --- a/scripts/pkg.sh +++ b/scripts/pkg.sh @@ -524,11 +524,12 @@ build_pkg() case "$PKG_FORMAT" in rpm) # --- build RPMs and copy them to source directory - local rpmbuild_root=$HOME/rpmbuild - [ `id -u` = 0 ] && rpmbuild_root=/usr/src/packages + local rpmbuild_root=${RPMBUILD_ROOT:-$HOME/rpmbuild} + mkdir -p $rpmbuild_root + rpmbuild_root=$(readlink -f $rpmbuild_root) local rpmbuild_srpms=$rpmbuild_root/SRPMS local rpmbuild_rpms=$rpmbuild_root/RPMS/$PKG_ARCH - rpmbuild -ta $DIST_PCKG_DIR/$tar_archive + rpmbuild --define "_topdir $rpmbuild_root" -ta $DIST_PCKG_DIR/$tar_archive cp $rpmbuild_srpms/$src_base.src.rpm $DIST_PCKG_DIR/ cp $rpmbuild_rpms/$PKG_PROJECT-*-$version.$PKG_ARCH.rpm $DIST_PCKG_DIR/ ;; @@ -1138,6 +1139,7 @@ PROJECT_DESCR_FILE=$TOPDIR/make/project.conf DIST_SRC_DIR=dist/src DIST_INST_DIR=dist/src DIST_PCKG_DIR=dist/pckg +RPMBUILD_ROOT="" PKG_PROJECT="$PROJECT" PKG_REQUIRES_RUN="" PKG_RECOMMENDS_RUN="" @@ -1160,6 +1162,10 @@ while [ ${1:0:1} = - ]; do eval DIST_SRC_DIR=\"$2\" shift ;; + -T) + eval RPMBUILD_ROOT=\"$2\" + shift + ;; -p) eval DIST_PCKG_DIR=\"$2\" shift