Path: blob/main/Mk/Scripts/depends-list.sh
16124 views
#!/bin/sh1# MAINTAINER: [email protected]23set -e4set -o pipefail56. ${dp_SCRIPTSDIR}/functions.sh78flavors=09recursive=010missing=011requires_wrkdir=012while getopts "fmrw" FLAG; do13case "${FLAG}" in14f)15flavors=116;;17m)18missing=119recursive=120;;21r)22recursive=123;;24w)25# Only list dependencies that have a WRKDIR. Used for26# 'make clean-depends'.27# Without -r recurse when WRKDIR exists; with -r28# always recurse.29requires_wrkdir=130;;31*)32echo "Unknown flag" >&233exit 134;;35esac36done37shift $((OPTIND-1))3839validate_env PORTSDIR dp_OVERLAYS dp_PKGNAME40if [ ${recursive} -eq 1 -o ${requires_wrkdir} -eq 1 ]; then41validate_env dp_MAKE42# Cache command executions to avoid looking them up again in every43# sub-make.44MAKE="${dp_MAKE}" export_ports_env >/dev/null45fi4647[ -n "${DEBUG_MK_SCRIPTS}" -o -n "${DEBUG_MK_SCRIPTS_DEPENDS_LIST}" ] && set -x4849set -u5051if [ ${missing} -eq 1 ]; then52existing=$(${dp_PKG_INFO} -aoq|paste -d ' ' -s -)53fi5455check_dep() {56local _dep wrkdir show_dep5758for _dep ; do59unset FLAVOR60myifs=${IFS}61IFS=:62set -- ${_dep}63IFS=${myifs}6465case "${2}" in66/*) d=${2} ;;67*) for overlay in ${dp_OVERLAYS} ${PORTSDIR}; do68d=${overlay}/${2}69f=70case "${d}" in71*@*/*) ;; # Ignore @ in the path which would not be a flavor72*@*)73f=${d##*@}74d=${d%@*}75;;76esac77if [ -f ${d}/Makefile ]; then78if [ -n $f ]; then79export FLAVOR=$f80fi81break82fi83done84esac8586if [ ${flavors} -eq 1 -a -n "${FLAVOR:-}" ]; then87port_display="${d}@${FLAVOR}"88else89port_display="${d}"90fi9192case " ${checked} " in93*\ ${d}\ *) continue ;; # Already checked94esac95checked="${checked} ${d}"96# Check if the dependency actually exists or skip otherwise.97if [ ! -d "${d}" ]; then98echo "${dp_PKGNAME}: \"${port_display}\" non-existent -- dependency list incomplete" >&299continue100fi101102# If only looking for missing, show if missing103if [ ${missing} -eq 1 ]; then104case " ${existing} " in105*\ ${d#${PORTSDIR}/}\ *) continue ;; # We have it, nothing to see106esac107fi108109# Grab any needed vars from the port.110111if [ ${requires_wrkdir} -eq 1 ]; then112# shellcheck disable=SC2046113# We want word splitting here.114set -- $(${dp_MAKE} -C ${d} -VWRKDIR -V_UNIFIED_DEPENDS)115wrkdir="$1"116shift117elif [ ${recursive} -eq 1 ]; then118# shellcheck disable=SC2046119# We want word splitting here.120set -- $(${dp_MAKE} -C ${d} -V_UNIFIED_DEPENDS)121fi122123# If a WRKDIR is required to show the dependency, check for it.124show_dep=1125if [ ${requires_wrkdir} -eq 1 ] && ! [ -d "${wrkdir}" ]; then126show_dep=0127fi128[ ${show_dep} -eq 1 ] && echo "${port_display}"129if [ ${recursive} -eq 1 -o ${requires_wrkdir} -eq 1 -a ${show_dep} -eq 1 ]; then130# shellcheck disable=SC2068131# Do not add quotes, we want to split the string here.132check_dep $@133fi134done135}136137checked=138# shellcheck disable=SC2068139# Do not add quotes, we want to split the string here.140check_dep $@141142143