diff --git a/targets/pseudo/bootstrap-packages/Makefile b/targets/pseudo/bootstrap-packages/Makefile new file mode 100644 index 000000000000..6523e88f84db --- /dev/null +++ b/targets/pseudo/bootstrap-packages/Makefile @@ -0,0 +1,23 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# Compensate (a bit) for the lack of per package makefiles or other means +# of knowing what goes in each package in the base system. +# We can derive some of the information we want from the makefiles that +# set PACKAGE. + +all: +.if ${.MAKE.LEVEL} > 0 +all: packages +.endif + +PACKAGES?= ${.CURDIR:H:H}/packages + +packages: package-makefile.list + @${.CURDIR}/bootstrap-packages.sh PACKAGES=${PACKAGES} ${.ALLSRC} + +package-makefile.list: + @(cd ${SRCTOP} && \ + find ${TOPS:U*bin etc lib*} -name 'Makefile' | \ + xargs grep '^PACKAGE[[:space:]]*=' ) | \ + sed 's/[[:space:]]*=[[:space:]]*/=/' > ${.TARGET} + diff --git a/targets/pseudo/bootstrap-packages/bootstrap-packages.sh b/targets/pseudo/bootstrap-packages/bootstrap-packages.sh new file mode 100755 index 000000000000..a2fe250d68a3 --- /dev/null +++ b/targets/pseudo/bootstrap-packages/bootstrap-packages.sh @@ -0,0 +1,96 @@ +#!/bin/sh + +# SPDX-License-Identifier: BSD-2-Clause + +# Our input is the output of something like: +# +# (cd ${SRCTOP} && +# find *bin etc lib* -name Makefile | +# xargs grep '^PACKAGE[[:space:]]*=' ) +# +# With some cleanup and looks like: +# +# usr.bin/ofed/libibverbs/Makefile:PACKAGE=FreeBSD-rdma +# usr.bin/last/Makefile:PACKAGE=acct +# usr.bin/lastcomm/Makefile:PACKAGE=acct +# usr.bin/users/Makefile:PACKAGE=acct +# usr.bin/who/Makefile:PACKAGE=acct +# usr.sbin/ac/Makefile:PACKAGE=acct +# usr.sbin/accton/Makefile:PACKAGE=acct +# usr.sbin/lastlogin/Makefile:PACKAGE=acct +# .. +# +# which we use to populate $PACKAGES/*/Makefile.depend +# and $PACKAGES/Makefile.depend to make it easier to keep +# Makefile.depend files throughout the tree up-to-date. +# +# The result is not ideal, as we do not (yet) take into account all +# the MK_* knobs that can impact DIRDEPS. +# + +Mydir=`dirname $0` + +while : +do + case "$1" in + *=*) eval "$1"; shift;; + *) break;; + esac +done + +to_reldir() { + sed "s,$SRCTOP/,," +} + +SRCTOP=${SRCTOP:-$(realpath $Mydir/../../..)} +PACKAGES=${PACKAGES:-$(realpath $Mydir/../..)} +case "$PACKAGES" in +/*) ;; +*) PACKAGES=$SRCTOP/$PACKAGES;; +esac + +script_name=$(realpath $0 | to_reldir) + +start_depend() { + depfile=$1 + + mkdir -p ${depfile%/*} + cat < $depfile +# Generated by $script_name + +DIRDEPS= \\ +EOF +} + +end_depend() { + depfile=$1 + + cat <> $depfile + +.include +EOF +} + +start_depend $PACKAGES/Makefile.depend || exit 1 +sort -t= -k2 "$@" | sed 's,/Makefile:PACKAGE=, ,' | +( + lpackage= + while read reldir package + do + case "$package" in \ + lib?{LIB}) package=${reldir##*/};; + lib?{LIB:tl}) package=`echo ${reldir##*/} | tr 'A-Z' 'a-z'`;; + esac + if test "$package" != "$lpackage"; then \ + test -z "$lpackage" || end_depend $ddeps + target=$PACKAGES/$package + ddeps=$target/Makefile.depend + start_depend $ddeps + lpackage=$package + echo " $target \\" + fi + echo " $reldir \\" >> $ddeps + done + end_depend $ddeps +) | to_reldir >> $PACKAGES/Makefile.depend +end_depend $PACKAGES/Makefile.depend