#!/bin/sh # License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree. # # ext-sync.sh -- put the recipes of ext/ into the pkgsrc tree # # usage: tools/ext-sync.sh [PKGSRCDIR] # # A fork under ext/src// (ext/AGENTS.md) keeps its pkgsrc recipe in # ext/src//pkgsrc/. pkgsrc builds a recipe only from inside its tree # (the recipe includes ../../mk/bsd.pkg.mk), so this copies it to # PKGSRCDIR//, the category being the first word of the # recipe's CATEGORIES -- the way an owned copy is kept in this tree. # PKGSRCDIR defaults to pkgsrc/ of this tree. # # A copy, not a link: the source set and the VM need real files. The # target is only ever replaced when upstream pkgsrc does not own that path # (`git ls-files' of the pkgsrc import is empty for it): an upstream package # of the same name is never overwritten. set -eu TOP=$(cd "$(dirname "$0")/.." && pwd) PKGSRCDIR=${1:-$TOP/pkgsrc} # ext/src//pkgsrc is /; a second package from the same # tree, ext/src//pkgsrc-, is /- (MCDE's # Motif: ext/src/mcde/pkgsrc-motif, x11/mcde-motif) for recipe in "$TOP"/ext/src/*/pkgsrc "$TOP"/ext/src/*/pkgsrc-*; do [ -f "$recipe/Makefile" ] || continue name=$(basename "$(dirname "$recipe")") case ${recipe##*/} in pkgsrc-*) name=$name-${recipe##*/pkgsrc-} ;; esac cat=$(sed -n 's/^CATEGORIES=[[:space:]]*\([^[:space:]]*\).*/\1/p' \ "$recipe/Makefile") [ -n "$cat" ] || { echo "ext-sync: no CATEGORIES in $recipe/Makefile" >&2; exit 1; } dst=$PKGSRCDIR/$cat/$name if [ -d "$PKGSRCDIR/.git" ] && [ -n "$(git -C "$PKGSRCDIR" ls-files -- "$cat/$name" | head -1)" ]; then echo "ext-sync: $cat/$name belongs to upstream pkgsrc, not replaced" >&2 exit 1 fi rm -rf "$dst" mkdir -p "$dst" (cd "$recipe" && tar -cf - .) | (cd "$dst" && tar -xf -) echo "ext-sync: $cat/$name" done