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.3 apb SCRATCH="$(${MKTEMP} -d "/var/tmp/${prog}.XXXXXX")" 24 1.3 apb NEXTLEFTOVERS="${SCRATCH}/leftovers0" 25 1.3 apb LASTJOIN="${SCRATCH}/join0" 26 1.3 apb NEXTJOIN="${SCRATCH}/join1" 27 1.1 dyoung TAB=" " 28 1.1 dyoung 29 1.3 apb ${SORT} -k 1 > "${LASTJOIN}" 30 1.1 dyoung 31 1.3 apb LEFTOVERS="${LASTJOIN}" 32 1.1 dyoung 33 1.3 apb while [ "$(${WC} -l "${LASTJOIN}" | ${AWK} '{ print $1; }')" -ne 0 ]; do 34 1.1 dyoung 35 1.1 dyoung # 36 1.3 apb # From dependencies X-requires-Y in ${LEFTOVERS} and Y-requires-Z in 37 1.3 apb # ${LASTJOIN}, produce dependencies X-requires-Z and write them to 38 1.3 apb # ${NEXTJOIN}. 39 1.1 dyoung # 40 1.3 apb ${SORT} -k 2 < "${LEFTOVERS}" | \ 41 1.3 apb ${JOIN} -1 2 -2 1 -o '1.1 2.2' - "${LASTJOIN}" | \ 42 1.3 apb ${SORT} -u > "${NEXTJOIN}" 43 1.1 dyoung if [ ${DEBUG:-0} -gt 0 ]; then 44 1.1 dyoung echo "### filtered ###" 1>&2 45 1.3 apb ${JOIN} -t "${TAB}" "${NEXTJOIN}" "${LEFTOVERS}" | ${SORT} 1>&2 46 1.1 dyoung echo "###" 1>&2 47 1.1 dyoung fi 48 1.1 dyoung 49 1.1 dyoung # 50 1.3 apb # Filter out of ${LEFTOVERS} all of the dependencies X-requires-Z, which 51 1.1 dyoung # were produced in the previous step. Write the new leftovers to 52 1.3 apb # ${NEXTLEFTOVERS}. 53 1.1 dyoung # 54 1.3 apb ${JOIN} -v 2 -t "${TAB}" "${NEXTJOIN}" "${LEFTOVERS}" | \ 55 1.3 apb ${SORT} -u > "${NEXTLEFTOVERS}" 56 1.1 dyoung 57 1.1 dyoung # 58 1.1 dyoung # Swap output files before repeating. 59 1.1 dyoung # 60 1.3 apb LASTJOIN="${NEXTJOIN}" 61 1.3 apb if [ "$(basename "${NEXTJOIN}")" = join0 ]; then 62 1.3 apb NEXTJOIN="${SCRATCH}/join1" 63 1.1 dyoung else 64 1.3 apb NEXTJOIN="${SCRATCH}/join0" 65 1.1 dyoung fi 66 1.3 apb LEFTOVERS="${NEXTLEFTOVERS}" 67 1.3 apb if [ "$(basename "${NEXTLEFTOVERS}")" = leftovers0 ]; then 68 1.3 apb NEXTLEFTOVERS="${SCRATCH}/leftovers1" 69 1.1 dyoung else 70 1.3 apb NEXTLEFTOVERS="${SCRATCH}/leftovers0" 71 1.1 dyoung fi 72 1.1 dyoung done 73 1.1 dyoung 74 1.1 dyoung # 75 1.1 dyoung # Output all of the dependencies that were not culled and clean up. 76 1.1 dyoung # 77 1.3 apb cat "${LEFTOVERS}" 78 1.3 apb rm -r "${SCRATCH}" 79