1#!/bin/sh 2 3# SPDX-License-Identifier: BSD-2-Clause 4 5# Our input is the output of something like: 6# 7# (cd ${SRCTOP} && 8# find *bin etc lib* -name Makefile | 9# xargs grep '^PACKAGE[[:space:]]*=' ) 10# 11# With some cleanup and looks like: 12# 13# usr.bin/ofed/libibverbs/Makefile:PACKAGE=FreeBSD-rdma 14# usr.bin/last/Makefile:PACKAGE=acct 15# usr.bin/lastcomm/Makefile:PACKAGE=acct 16# usr.bin/users/Makefile:PACKAGE=acct 17# usr.bin/who/Makefile:PACKAGE=acct 18# usr.sbin/ac/Makefile:PACKAGE=acct 19# usr.sbin/accton/Makefile:PACKAGE=acct 20# usr.sbin/lastlogin/Makefile:PACKAGE=acct 21# .. 22# 23# which we use to populate $PACKAGES/*/Makefile.depend 24# and $PACKAGES/Makefile.depend to make it easier to keep 25# Makefile.depend files throughout the tree up-to-date. 26# 27# The result is not ideal, as we do not (yet) take into account all 28# the MK_* knobs that can impact DIRDEPS. 29# 30 31Mydir=`dirname $0` 32 33while : 34do 35 case "$1" in 36 *=*) eval "$1"; shift;; 37 *) break;; 38 esac 39done 40 41to_reldir() { 42 sed "s,$SRCTOP/,," 43} 44 45SRCTOP=${SRCTOP:-$(realpath $Mydir/../../..)} 46PACKAGES=${PACKAGES:-$(realpath $Mydir/../..)} 47case "$PACKAGES" in 48/*) ;; 49*) PACKAGES=$SRCTOP/$PACKAGES;; 50esac 51 52script_name=$(realpath $0 | to_reldir) 53 54start_depend() { 55 depfile=$1 56 57 mkdir -p ${depfile%/*} 58 cat <<EOF > $depfile 59# Generated by $script_name 60 61DIRDEPS= \\ 62EOF 63} 64 65end_depend() { 66 depfile=$1 67 68 cat <<EOF >> $depfile 69 70.include <dirdeps.mk> 71EOF 72} 73 74start_depend $PACKAGES/Makefile.depend || exit 1 75sort -t= -k2 "$@" | sed 's,/Makefile:PACKAGE=, ,' | 76( 77 lpackage= 78 while read reldir package 79 do 80 case "$package" in \ 81 lib?{LIB}) package=${reldir##*/};; 82 lib?{LIB:tl}) package=`echo ${reldir##*/} | tr 'A-Z' 'a-z'`;; 83 esac 84 if test "$package" != "$lpackage"; then \ 85 test -z "$lpackage" || end_depend $ddeps 86 target=$PACKAGES/$package 87 ddeps=$target/Makefile.depend 88 start_depend $ddeps 89 lpackage=$package 90 echo " $target \\" 91 fi 92 echo " $reldir \\" >> $ddeps 93 done 94 end_depend $ddeps 95) | to_reldir >> $PACKAGES/Makefile.depend 96end_depend $PACKAGES/Makefile.depend 97