mag

a binary package manager in one C file: apk and pacman repos, CRUX, Void and Exherbo ports
git clone https://github.com/tortr-rs/mag
Log | Files | Refs | README | LICENSE

commit 1ec8f0a74daa958df98f82c6ee02e5f94fe2671d
parent 25aabf62f27460d1cc6121cdb3b45b9f36902e0c
Author: torter <koubbamohamedrayan@gmail.com>
Date:   Sat, 14 Nov 2026 16:06:26 +0000

pkgsrc: patches go through nbpatch, install mode variables, libnbcompat

Diffstat:
Mmag.c | 13+++++++++++--
Mrepo/PROVIDES | 1+
Mtests/run.sh | 15++++++++++++++-
3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/mag.c b/mag.c @@ -792,7 +792,7 @@ static struct recipe *parse_pkgsrc(const char *id, const char *dir, const char * { "CHMOD", "chmod" }, { "TRUE", "true" }, { "CAT", "cat" }, { "TEST", "test" }, { "TOUCH", "touch" }, { "MAKE", "make" }, { "INSTALL_PROGRAM", "install -m 755" }, { "INSTALL_LIB", "install -m 755" }, { "INSTALL_LIB_DIR", "install -d -m 755" }, { "INSTALL_GAME", "install -m 755" }, { "INSTALL_GAME_DATA", "install -m 644" }, { "INSTALL_SCRIPT", "install -m 755" }, { "INSTALL_DATA", "install -m 644" }, { "INSTALL_MAN", "install -m 644" }, { "INSTALL_PROGRAM_DIR", "install -d -m 755" }, { "INSTALL_DATA_DIR", "install -d -m 755" }, - { "INSTALL_SCRIPT_DIR", "install -d -m 755" }, { "INSTALL_MAN_DIR", "install -d -m 755" }, { "CC", "cc" }, { "LIBTOOL", "libtool" }, { "PKG_SYSCONFDIR", "/etc" }, { "VARBASE", "/var" }, { "MACHINE_GNU_ARCH", "x86_64" }, { "MACHINE_GNU_PLATFORM", "x86_64-pc-linux-gnu" }, { "PKG_SHELL", "" }, { "REAL_ROOT_USER", "root" }, { "REAL_ROOT_GROUP", "root" }, { "RUN", "" }, { "RCD_SCRIPTS_DIR", "/etc/rc.d" }, { NULL, NULL } + { "INSTALL_SCRIPT_DIR", "install -d -m 755" }, { "INSTALL_MAN_DIR", "install -d -m 755" }, { "CC", "cc" }, { "LIBTOOL", "libtool" }, { "PKG_SYSCONFDIR", "/etc" }, { "VARBASE", "/var" }, { "MACHINE_GNU_ARCH", "x86_64" }, { "MACHINE_GNU_PLATFORM", "x86_64-pc-linux-gnu" }, { "PKG_SHELL", "" }, { "BINMODE", "755" }, { "NONBINMODE", "644" }, { "LIBMODE", "644" }, { "SHAREMODE", "644" }, { "MANMODE", "644" }, { "DIRMODE", "755" }, { "BINOWN", "root" }, { "BINGRP", "root" }, { "SHAREOWN", "root" }, { "SHAREGRP", "root" }, { "MANOWN", "root" }, { "MANGRP", "root" }, { "REAL_ROOT_USER", "root" }, { "REAL_ROOT_GROUP", "root" }, { "RUN", "" }, { "RCD_SCRIPTS_DIR", "/etc/rc.d" }, { NULL, NULL } }; int k; for (k = 0; sh[k][0]; k++) var_set(&vs, sh[k][0], sh[k][1]); @@ -904,6 +904,15 @@ static struct recipe *parse_pkgsrc(const char *id, const char *dir, const char * } free(s); } + { + char *pdir = fmt("%s/%s", dir, var_get(&vs, "PATCHDIR") ? var_get(&vs, "PATCHDIR") : "patches"); + DIR *pd2 = opendir(pdir); + struct dirent *pe; + int has_patch = 0; + if (pd2) { while ((pe = readdir(pd2))) if (!strncmp(pe->d_name, "patch-", 6)) has_patch = 1; closedir(pd2); } + if (has_patch && strcmp(id, "devel/nbpatch") && strcmp(id, "pkgtools/libnbcompat") && strcmp(id, "devel/bmake") && strcmp(id, "pkgtools/bootstrap-mk-files")) dep_add(r, "devel/nbpatch"); + free(pdir); + } /* the steps: patches, configure, build, install, each from the variables pkgsrc has for it */ { const char *prefix_args = ""; @@ -945,7 +954,7 @@ static struct recipe *parse_pkgsrc(const char *id, const char *dir, const char * if (wrksrc && !strncmp(wrksrc, "$SRC/../", 8)) cmd += sprintf(cmd, "cd %s\n", wrksrc); } if (hook[1]) cmd += sprintf(cmd, "%s\n", hook[1]); - cmd += sprintf(cmd, "for p in \"$RECIPE_DIR\"/%s/patch-*; do [ -f \"$p\" ] || continue; patch -p0 < \"$p\"; done\n", pd); + cmd += sprintf(cmd, "P=patch; command -v nbpatch >/dev/null && P=nbpatch\nfor p in \"$RECIPE_DIR\"/%s/patch-*; do [ -f \"$p\" ] || continue; $P -p0 < \"$p\"; done\n", pd); if (hook[2]) cmd += sprintf(cmd, "%s\n", hook[2]); if (hook[3]) cmd += sprintf(cmd, "%s\n", hook[3]); else if (hasconfig && !cmake) cmd += sprintf(cmd, "%s ./configure --prefix=$PREFIX --mandir=$PREFIX/man --sysconfdir=/etc --localstatedir=/var %s\n", cenv, cfg); diff --git a/repo/PROVIDES b/repo/PROVIDES @@ -11,3 +11,4 @@ needs shells/oksh dev-libs/netbsd-curses needs editors/vim dev-libs/netbsd-curses lang/tcl - x11/tk - +needs devel/nbpatch pkgtools/libnbcompat diff --git a/tests/run.sh b/tests/run.sh @@ -128,6 +128,19 @@ steps: chmod 755 \$DESTDIR\$PREFIX/bin/bmake R +sum=$(mktar nbpatch 1.0 "nbpatch 1.0") +cat >"$T/repo/devel/nbpatch" <<R +desc: nbpatch stand-in +version: 1.0 +url: file://$T/src/nbpatch-\${version}.tar +sha256: $sum +deps: +steps: + mkdir -p \$DESTDIR\$PREFIX/bin + printf '#!/bin/sh\nexec patch "\$@"\n' >\$DESTDIR\$PREFIX/bin/nbpatch + chmod 755 \$DESTDIR\$PREFIX/bin/nbpatch +R + # pkgsrc packages: a Makefile and a distinfo, read in place mkdir -p "$T/repo/mk/fetch" "$T/repo/devel/hello" "$T/repo/devel/hello/patches" "$T/repo/devel/base" "$T/src/hello-2.1" printf 'MASTER_SITE_LOCAL+=\tfile://%s/src/\n' "$T" >"$T/repo/mk/fetch/sites.mk" @@ -159,7 +172,7 @@ printf '%s\n' '$NetBSD$' '' '--- hello.txt.orig' '+++ hello.txt' '@@ -1 +1 @@' ' check 'pkgsrc info' "devel/hello 2.1 a pkgsrc test package source: file://$T/src/hello-2.1.tar - deps: devel/base devel/bmake + deps: devel/base devel/nbpatch devel/bmake recipe: $T/repo/devel/hello/Makefile not installed" "$($MAG info devel/hello)" $MAG install devel/hello >"$T/out" 2>&1; check 'pkgsrc install' 0 $?