summaryrefslogtreecommitdiff
path: root/Mk/Scripts/depends-list.sh
blob: 21b7ec103661ed0338a999549cf44e3293813443 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
# MAINTAINER: portmgr@FreeBSD.org
# $FreeBSD$

set -e

. ${dp_SCRIPTSDIR}/functions.sh

recursive=0
requires_wrkdir=0
while getopts "rw" FLAG; do
	case "${FLAG}" in
		r)
			recursive=1
			;;
		w)
			# Only list dependencies that have a WRKDIR.  Used for
			# 'make clean-depends'.
			requires_wrkdir=1
			;;
		*)
			echo "Unknown flag" >&2
			exit 1
			;;
	esac
done
shift $((OPTIND-1))

validate_env dp_PORTSDIR dp_PKGNAME
if [ ${recursive} -eq 1 -o ${requires_wrkdir} -eq 1 ]; then
	validate_env dp_MAKE
	# Cache command executions to avoid looking them up again in every
	# sub-make.
	MAKE="${dp_MAKE}" PORTSDIR="${dp_PORTSDIR}" export_ports_env >/dev/null
fi

set -u

check_dep() {
	local _dep wrkdir show_dep

	for _dep ; do
		myifs=${IFS}
		IFS=:
		set -- ${_dep}
		IFS=${myifs}

		case "${2}" in
			/*) d=${2} ;;
			*) d=${dp_PORTSDIR}/${2} ;;
		esac

		case " ${checked} " in
			*\ ${d}\ *) continue ;; # Already checked
		esac
		checked="${checked} ${d}"
		# Check if the dependency actually exists or skip otherwise.
		if [ ! -d ${d} ]; then
			echo "${dp_PKGNAME}: \"${d}\" non-existent -- dependency list incomplete" >&2
			continue
		fi

		# Grab any needed vars from the port.

		if [ ${requires_wrkdir} -eq 1 -a ${recursive} -eq 1 ]; then
			set -- $(${dp_MAKE} -C ${d} -VWRKDIR -V_UNIFIED_DEPENDS)
			wrkdir="$1"
			shift
		elif [ ${requires_wrkdir} -eq 1 -a ${recursive} -eq 0 ]; then
			set -- "$(${dp_MAKE} -C ${d} -VWRKDIR)"
			wrkdir="$1"
		elif [ ${recursive} -eq 1 ]; then
			set -- $(${dp_MAKE} -C ${d} -V_UNIFIED_DEPENDS)
		fi

		# If a WRKDIR is required to show the dependency, check for it.
		show_dep=1
		if [ ${requires_wrkdir} -eq 1 ] && ! [ -d "${wrkdir}" ]; then
			show_dep=0
		fi
		[ ${show_dep} -eq 1 ] && echo ${d}
		if [ ${recursive} -eq 1 ]; then
			check_dep $@
		fi
	done
}

checked=
check_dep $@