minix/distrib/sets/culldeps
Lionel Sambuc 9152e1c5a7 Upgrading build system to new NetBSD revision
The tested targets are the followgin ones:
 * tools
 * distribution
 * sets
 * release

The remaining NetBSD targets have not been disabled nor tested
*at all*. Try them at your own risk, they may reboot the earth.

For all compliant Makefiles, objects and generated files are put in
MAKEOBJDIR, which means you can now keep objects between two branch
switching. Same for DESTDIR, please refer to build.sh options.

Regarding new or modifications of Makefiles a few things:
 * Read share/mk/bsd.README
 * If you add a subdirectory, add a Makefile in it, and have it called
   by the parent through the SUBDIR variable.
 * Do not add arbitrary inclusion which crosses to another branch of
   the hierarchy; If you can't do without it, put a comment on why.
   If possible, do not use inclusion at all.
 * Use as much as possible the infrastructure, it is here to make
   life easier, do not fight it.

Sets and package are now used to track files.
We have one set called "minix", composed of one package called "minix-sys"
2012-11-15 16:07:29 +01:00

84 lines
2.1 KiB
Bash
Executable file

#!/bin/sh
#
# culldeps
#
# Filter redundant dependencies.
#
# Each line of input and output contains two syspkg names,
# where the first syspkg depends on the second syspkg.
#
# Emit all the dependencies on the standard input to the standard
# output EXCEPT the dependencies which can be derived from other
# dependencies by the transitive rule. For example, omit both A C
# and A D from
#
# A B
# B C
# C D
# A C
# A D
#
# because A C can be derived from A B and B C by transitivity,
# and A D can be derived from A B, B C, C D by transitivity.
#
prog="${0##*/}"
rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
. "${rundir}/sets.subr"
SCRATCH="$(${MKTEMP} -d "/var/tmp/${prog}.XXXXXX")"
NEXTLEFTOVERS="${SCRATCH}/leftovers0"
LASTJOIN="${SCRATCH}/join0"
NEXTJOIN="${SCRATCH}/join1"
TAB=" "
${SORT} -k 1 > "${LASTJOIN}"
LEFTOVERS="${LASTJOIN}"
while [ "$(${WC} -l "${LASTJOIN}" | ${AWK} '{ print $1; }')" -ne 0 ]; do
#
# From dependencies X-requires-Y in ${LEFTOVERS} and Y-requires-Z in
# ${LASTJOIN}, produce dependencies X-requires-Z and write them to
# ${NEXTJOIN}.
#
${SORT} -k 2 < "${LEFTOVERS}" | \
${JOIN} -1 2 -2 1 -o '1.1 2.2' - "${LASTJOIN}" | \
${SORT} -u > "${NEXTJOIN}"
if [ ${DEBUG:-0} -gt 0 ]; then
echo >&2 "${prog}: ### begin filtered results ###"
${JOIN} -t "${TAB}" "${NEXTJOIN}" "${LEFTOVERS}" | ${SORT} 1>&2
echo >&2 "${prog}: ### end filtered results ###"
fi
#
# Filter out of ${LEFTOVERS} all of the dependencies X-requires-Z, which
# were produced in the previous step. Write the new leftovers to
# ${NEXTLEFTOVERS}.
#
${JOIN} -v 2 -t "${TAB}" "${NEXTJOIN}" "${LEFTOVERS}" | \
${SORT} -u > "${NEXTLEFTOVERS}"
#
# Swap output files before repeating.
#
LASTJOIN="${NEXTJOIN}"
if [ "$(basename "${NEXTJOIN}")" = join0 ]; then
NEXTJOIN="${SCRATCH}/join1"
else
NEXTJOIN="${SCRATCH}/join0"
fi
LEFTOVERS="${NEXTLEFTOVERS}"
if [ "$(basename "${NEXTLEFTOVERS}")" = leftovers0 ]; then
NEXTLEFTOVERS="${SCRATCH}/leftovers1"
else
NEXTLEFTOVERS="${SCRATCH}/leftovers0"
fi
done
#
# Output all of the dependencies that were not culled and clean up.
#
cat "${LEFTOVERS}"
rm -r "${SCRATCH}"