1 1.1 dyoung #!/bin/sh 2 1.1 dyoung # 3 1.1 dyoung # culldeps 4 1.1 dyoung # 5 1.1 dyoung # Filter redundant dependencies. 6 1.1 dyoung # 7 1.1 dyoung # Emit all the dependencies on the standard input to the standard 8 1.1 dyoung # output EXCEPT the dependencies which can be derived from other 9 1.1 dyoung # dependencies by the transitive rule. For example, omit both A C 10 1.1 dyoung # and A D from 11 1.1 dyoung # 12 1.1 dyoung # A B 13 1.1 dyoung # B C 14 1.1 dyoung # C D 15 1.1 dyoung # A C 16 1.1 dyoung # A D 17 1.1 dyoung # 18 1.1 dyoung # because A C can be derived from A B and B C by transitivity, 19 1.1 dyoung # and A D can be derived from A B, B C, C D by transitivity. 20 1.1 dyoung # 21 1.1 dyoung 22 1.3 apb prog="${0##*/}" 23 1.4 apb rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/" 24 1.4 apb . "${rundir}/sets.subr" 25 1.4 apb 26 1.3 apb SCRATCH="$(${MKTEMP} -d "/var/tmp/${prog}.XXXXXX")" 27 1.3 apb NEXTLEFTOVERS="${SCRATCH}/leftovers0" 28 1.3 apb LASTJOIN="${SCRATCH}/join0" 29 1.3 apb NEXTJOIN="${SCRATCH}/join1" 30 1.1 dyoung TAB=" " 31 1.1 dyoung 32 1.3 apb ${SORT} -k 1 > "${LASTJOIN}" 33 1.1 dyoung 34 1.3 apb LEFTOVERS="${LASTJOIN}" 35 1.1 dyoung 36 1.3 apb while [ "$(${WC} -l "${LASTJOIN}" | ${AWK} '{ print $1; }')" -ne 0 ]; do 37 1.1 dyoung 38 1.1 dyoung # 39 1.3 apb # From dependencies X-requires-Y in ${LEFTOVERS} and Y-requires-Z in 40 1.3 apb # ${LASTJOIN}, produce dependencies X-requires-Z and write them to 41 1.3 apb # ${NEXTJOIN}. 42 1.1 dyoung # 43 1.3 apb ${SORT} -k 2 < "${LEFTOVERS}" | \ 44 1.3 apb ${JOIN} -1 2 -2 1 -o '1.1 2.2' - "${LASTJOIN}" | \ 45 1.3 apb ${SORT} -u > "${NEXTJOIN}" 46 1.1 dyoung if [ ${DEBUG:-0} -gt 0 ]; then 47 1.5 apb echo >&2 "${prog}: ### begin filtered results ###" 48 1.3 apb ${JOIN} -t "${TAB}" "${NEXTJOIN}" "${LEFTOVERS}" | ${SORT} 1>&2 49 1.5 apb echo >&2 "${prog}: ### end filtered results ###" 50 1.1 dyoung fi 51 1.1 dyoung 52 1.1 dyoung # 53 1.3 apb # Filter out of ${LEFTOVERS} all of the dependencies X-requires-Z, which 54 1.1 dyoung # were produced in the previous step. Write the new leftovers to 55 1.3 apb # ${NEXTLEFTOVERS}. 56 1.1 dyoung # 57 1.3 apb ${JOIN} -v 2 -t "${TAB}" "${NEXTJOIN}" "${LEFTOVERS}" | \ 58 1.3 apb ${SORT} -u > "${NEXTLEFTOVERS}" 59 1.1 dyoung 60 1.1 dyoung # 61 1.1 dyoung # Swap output files before repeating. 62 1.1 dyoung # 63 1.3 apb LASTJOIN="${NEXTJOIN}" 64 1.3 apb if [ "$(basename "${NEXTJOIN}")" = join0 ]; then 65 1.3 apb NEXTJOIN="${SCRATCH}/join1" 66 1.1 dyoung else 67 1.3 apb NEXTJOIN="${SCRATCH}/join0" 68 1.1 dyoung fi 69 1.3 apb LEFTOVERS="${NEXTLEFTOVERS}" 70 1.3 apb if [ "$(basename "${NEXTLEFTOVERS}")" = leftovers0 ]; then 71 1.3 apb NEXTLEFTOVERS="${SCRATCH}/leftovers1" 72 1.1 dyoung else 73 1.3 apb NEXTLEFTOVERS="${SCRATCH}/leftovers0" 74 1.1 dyoung fi 75 1.1 dyoung done 76 1.1 dyoung 77 1.1 dyoung # 78 1.1 dyoung # Output all of the dependencies that were not culled and clean up. 79 1.1 dyoung # 80 1.3 apb cat "${LEFTOVERS}" 81 1.3 apb rm -r "${SCRATCH}" 82