Path: blob/main/targets/pseudo/bootstrap-packages/bootstrap-packages.sh
39478 views
#!/bin/sh12# SPDX-License-Identifier: BSD-2-Clause34# Our input is the output of something like:5#6# (cd ${SRCTOP} &&7# find *bin etc lib* -name Makefile |8# xargs grep '^PACKAGE[[:space:]]*=' )9#10# With some cleanup and looks like:11#12# usr.bin/ofed/libibverbs/Makefile:PACKAGE=FreeBSD-rdma13# usr.bin/last/Makefile:PACKAGE=acct14# usr.bin/lastcomm/Makefile:PACKAGE=acct15# usr.bin/users/Makefile:PACKAGE=acct16# usr.bin/who/Makefile:PACKAGE=acct17# usr.sbin/ac/Makefile:PACKAGE=acct18# usr.sbin/accton/Makefile:PACKAGE=acct19# usr.sbin/lastlogin/Makefile:PACKAGE=acct20# ..21#22# which we use to populate $PACKAGES/*/Makefile.depend23# and $PACKAGES/Makefile.depend to make it easier to keep24# Makefile.depend files throughout the tree up-to-date.25#26# We attempt to handle MK_* knobs that impact DIRDEPS, by27# identifying the intermediate *bin and *lib Makefiles and28# checking if they had a subdir for the current reldir via a construct29# like:30#31# SUBDIR.${MK_OPT}+= sub32#33# in which case we extract the option OPT and add the reldir34# to a Makefile.depend.options file in targets/packages/sub/35#36# Of course the above is only *one* way optional SUBDIRs are handled37# in the tree. We also attempt to handle:38#39# .if ${MK_OPT} == "yes"40# SUBDIR+= sub41# .endif42#4344Mydir=`dirname $0`4546SKIP_LOG=return4748while :49do50case "$1" in51*=*) eval "$1"; shift;;52-v) SKIP_LOG=:; shift;;53*) break;;54esac55done5657to_reldir() {58sed "s,$SRCTOP/,,"59}6061SRCTOP=${SRCTOP:-$(realpath $Mydir/../../..)}62. ${SRCTOP}/libexec/rc/debug.sh63DebugOn bootstrap-packages6465PACKAGES=${PACKAGES:-$(realpath $Mydir/../..)}66case "$PACKAGES" in67/*) ;;68*) PACKAGES=$SRCTOP/$PACKAGES;;69esac7071script_name=$(realpath $0 | to_reldir)7273log() {74$SKIP_LOG 075echo $1 | to_reldir >&276}7778start_depend() {79depfile=$18081log $182mkdir -p ${depfile%/*}83cat <<EOF > $depfile84# Generated by $script_name8586DIRDEPS= \\87EOF88}8990end_depend() {91end_options $1.options92cat <<EOF >> $19394.include <dirdeps.mk>95EOF96}9798start_options() {99ofile=$1100101log $1102mkdir -p ${ofile%/*}103opts=$opt104eq==105cat <<EOF > $ofile106# Generated by $script_name107108DIRDEPS_OPTIONS= $opt109EOF110}111112end_options() {113test -s $1 || return114cat <<EOF >> $1115116.include <dirdeps-options.mk>117EOF118}119120no_plus() {121case "$1" in122*+*) echo "$1" | sed 's,+,\\\\+,g';;123*) echo "$1";;124esac125}126127find_opt() {128mf=$1129sub="`no_plus $2`"130shift 2131egrep "$@" "^[^#].*[[:space:]]$sub([[:space:]]|\$)" $mf |132tr '{' '\n' |133sed -n 's,^MK_\([^}]*\).*,\1,p' |134tr '\n' ' '135}136137start_depend $PACKAGES/Makefile.depend || exit 1138sort -t= -k2 "$@" | sed 's,/Makefile:PACKAGE=, ,' |139(140lpackage=141while read reldir package142do143# use these below144dname=${reldir%/*}145bname=${reldir##*/}146# check parent does not have it commented out147# otherwise we should ignore it.148# if the parent makefile does not exist, we will skip it.149pmf=$SRCTOP/$dname/Makefile150egrep -q "^[^#].*[[:space:]]`no_plus $bname`([[:space:]]|\$)" $pmf 2> /dev/null || continue151: reldir=$reldir152case "$reldir" in153*lib/*) sub=${reldir#*lib/};;154*bin/*) sub=${reldir#*bin/};;155*libexec/*) sub=${reldir#*libexec/};;156*) opt= sub=;;157esac158if [ -n "$sub" ]; then159smf=${SRCTOP}/${reldir%/$sub}/Makefile160# now we need just the immediate subdir161sub=${sub%%/*}162# SUBDIR.${MK_OPT}+= sub163opt=`find_opt $smf $sub`164# .if ${MK_OPT} == "yes"165# SUBDIR+= sub166opt=${opt:-`find_opt $smf $sub -B2`}167fi168case "$reldir" in169*/tests|*/tests/*) opt=${opt:-TESTS};;170esac171# PACKAGES is set to either a simple string like 'runtime'172# or for some libraries 'lib${LIB}'173# or even 'lib${LIB:tl}' when LIB contains upper case174# the majority of libs in FreeBSD use lib${LIB} for their dirname175# but we allow for just ${LIB} too.176: package=$package177case "$package" in \178lib?{LIB*) package=`echo lib${bname#lib} | tr 'A-Z' 'a-z'`;;179esac180if test "$package" != "$lpackage"; then \181test -z "$lpackage" || end_depend $ddeps182target=$PACKAGES/$package183ddeps=$target/Makefile.depend184odeps=$ddeps.options185rm -f $odeps186start_depend $ddeps187lpackage=$package188echo " $target \\"189fi190if [ -n "$opt" ]; then191[ -s $odeps ] || start_options $odeps192{193case " $opts " in194*" $opt "*) ;;195*) echo DIRDEPS_OPTIONS+= $opt196opts="$opts $opt"197eq==198;;199esac200for o in $opt201do202echo DIRDEPS.$o.yes$eq $reldir203done204eq=+=205} >> $odeps206else207echo " $reldir \\" >> $ddeps208fi209done210end_depend $ddeps211) | to_reldir >> $PACKAGES/Makefile.depend212end_depend $PACKAGES/Makefile.depend213214215