Index: tools/build/depend-cleanup.sh =================================================================== --- tools/build/depend-cleanup.sh +++ tools/build/depend-cleanup.sh @@ -17,12 +17,65 @@ # anyone would try a NO_CLEAN build against an object tree from before the # related change. One year should be sufficient. +set -e +set -u + +warn() +{ + echo "$(basename "$0"):" "$@" >&2 +} + +err() +{ + warn "$@" + exit 1 +} + +usage() +{ + echo "usage: $(basename $0) [-v] [-n] objtop" >&2 +} + +VERBOSE= +PRETEND= +while getopts vn o; do + case "$o" in + v) + VERBOSE=1 + ;; + n) + PRETEND=1 + ;; + *) + usage + exit 1 + ;; + esac +done +shift $((OPTIND-1)) + +if [ $# -ne 1 ]; then + usage + exit 1 +fi + OBJTOP=$1 +shift if [ ! -d "$OBJTOP" ]; then - echo "usage: $(basename $0) objtop" >&2 + err "$OBJTOP: Not a directory" exit 1 fi +run() +{ + if [ "$VERBOSE" ]; then + echo "$@" + fi + if ! [ "$PRETEND" ]; then + "$@" + fi +} + # $1 directory # $2 source filename w/o extension # $3 source extension @@ -31,7 +84,7 @@ if [ -e "$OBJTOP"/$1/.depend.$2.pico ] && \ egrep -qw "$2\.$3" "$OBJTOP"/$1/.depend.$2.pico; then \ echo "Removing stale dependencies for $2.$3"; \ - rm -f "$OBJTOP"/$1/.depend.$2.* \ + run rm -f "$OBJTOP"/$1/.depend.$2.* \ "$OBJTOP"/obj-lib32/$1/.depend.$2.* fi } @@ -47,14 +100,14 @@ egrep -qw "cddl/contrib/opensolaris/lib/libzfs/common/libzfs_changelist.c" \ "$OBJTOP"/cddl/lib/libzfs/.depend.libzfs_changelist.o; then echo "Removing old ZFS tree" - rm -rf "$OBJTOP"/cddl "$OBJTOP"/obj-lib32/cddl + run rm -rf "$OBJTOP"/cddl "$OBJTOP"/obj-lib32/cddl fi # 20200916 WARNS bumped, need bootstrapped crunchgen stubs if [ -e "$OBJTOP"/rescue/rescue/rescue.c ] && \ ! grep -q 'crunched_stub_t' "$OBJTOP"/rescue/rescue/rescue.c; then echo "Removing old rescue(8) tree" - rm -rf "$OBJTOP"/rescue/rescue + run rm -rf "$OBJTOP"/rescue/rescue fi # 20210105 fda7daf06301 pfctl gained its own version of pf_ruleset.c @@ -62,13 +115,13 @@ egrep -qw "sys/netpfil/pf/pf_ruleset.c" \ "$OBJTOP"/sbin/pfctl/.depend.pf_ruleset.o; then echo "Removing old pf_ruleset dependecy file" - rm -rf "$OBJTOP"/sbin/pfctl/.depend.pf_ruleset.o + run rm -rf "$OBJTOP"/sbin/pfctl/.depend.pf_ruleset.o fi # 20210108 821aa63a0940 non-widechar version of ncurses removed if [ -e "$OBJTOP"/lib/ncurses/ncursesw ]; then echo "Removing stale ncurses objects" - rm -rf "$OBJTOP"/lib/ncurses "$OBJTOP"/obj-lib32/lib/ncurses + run rm -rf "$OBJTOP"/lib/ncurses "$OBJTOP"/obj-lib32/lib/ncurses fi # 20210608 f20893853e8e move from atomic.S to atomic.c