xref: /freebsd/tools/build/depend-cleanup.sh (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
1#!/bin/sh
2#
3#
4# Our current make(1)-based approach to dependency tracking cannot cope with
5# certain source tree changes, including:
6# - removing source files
7# - replacing generated files with files committed to the tree
8# - changing file extensions (e.g. a C source file rewritten in C++)
9#
10# We handle those cases here in an ad-hoc fashion by looking for the known-
11# bad case in the main .depend file, and if found deleting all of the related
12# .depend files (including for example the lib32 version).
13#
14# These tests increase the build time (albeit by a small amount), so they
15# should be removed once enough time has passed and it is extremely unlikely
16# anyone would try a NO_CLEAN build against an object tree from before the
17# related change.  One year should be sufficient.
18
19set -e
20set -u
21
22warn()
23{
24	echo "$(basename "$0"):" "$@" >&2
25}
26
27err()
28{
29	warn "$@"
30	exit 1
31}
32
33usage()
34{
35	echo "usage: $(basename $0) [-v] [-n] objtop" >&2
36}
37
38VERBOSE=
39PRETEND=
40while getopts vn o; do
41	case "$o" in
42	v)
43		VERBOSE=1
44		;;
45	n)
46		PRETEND=1
47		;;
48	*)
49		usage
50		exit 1
51		;;
52	esac
53done
54shift $((OPTIND-1))
55
56if [ $# -ne 1 ]; then
57	usage
58	exit 1
59fi
60
61OBJTOP=$1
62shift
63if [ ! -d "$OBJTOP" ]; then
64	err "$OBJTOP: Not a directory"
65fi
66
67if [ -z "${MACHINE+set}" ]; then
68	err "MACHINE not set"
69fi
70
71if [ -z "${MACHINE_ARCH+set}" ]; then
72	err "MACHINE_ARCH not set"
73fi
74
75if [ -z "${ALL_libcompats+set}" ]; then
76	err "ALL_libcompats not set"
77fi
78
79run()
80{
81	if [ "$VERBOSE" ]; then
82		echo "$@"
83	fi
84	if ! [ "$PRETEND" ]; then
85		"$@"
86	fi
87}
88
89# $1 directory
90# $2 source filename w/o extension
91# $3 source extension
92clean_dep()
93{
94	for libcompat in "" $ALL_libcompats; do
95		dirprfx=${libcompat:+obj-lib${libcompat}/}
96		if egrep -qw "$2\.$3" "$OBJTOP"/$dirprfx$1/.depend.$2.*o 2>/dev/null; then
97			echo "Removing stale ${libcompat:+lib${libcompat} }dependencies and objects for $2.$3"
98			run rm -f \
99			    "$OBJTOP"/$dirprfx$1/.depend.$2.* \
100			    "$OBJTOP"/$dirprfx$1/$2.*o
101		fi
102	done
103}
104
105# Date      Rev      Description
106# 20200310  r358851  rename of openmp's ittnotify_static.c to .cpp
107clean_dep lib/libomp ittnotify_static c
108# 20200414  r359930  closefrom
109clean_dep lib/libc   closefrom S
110
111# 20200826  r364746  OpenZFS merge, apply a big hammer (remove whole tree)
112if [ -e "$OBJTOP"/cddl/lib/libzfs/.depend.libzfs_changelist.o ] && \
113    egrep -qw "cddl/contrib/opensolaris/lib/libzfs/common/libzfs_changelist.c" \
114    "$OBJTOP"/cddl/lib/libzfs/.depend.libzfs_changelist.o; then
115	echo "Removing old ZFS tree"
116	for libcompat in "" $ALL_libcompats; do
117		dirprfx=${libcompat:+obj-lib${libcompat}/}
118		run rm -rf "$OBJTOP"/${dirprfx}cddl
119	done
120fi
121
122# 20200916  WARNS bumped, need bootstrapped crunchgen stubs
123if [ -e "$OBJTOP"/rescue/rescue/rescue.c ] && \
124    ! grep -q 'crunched_stub_t' "$OBJTOP"/rescue/rescue/rescue.c; then
125	echo "Removing old rescue(8) tree"
126	run rm -rf "$OBJTOP"/rescue/rescue
127fi
128
129# 20210105  fda7daf06301   pfctl gained its own version of pf_ruleset.c
130if [ -e "$OBJTOP"/sbin/pfctl/.depend.pf_ruleset.o ] && \
131    egrep -qw "sys/netpfil/pf/pf_ruleset.c" \
132    "$OBJTOP"/sbin/pfctl/.depend.pf_ruleset.o; then
133	echo "Removing old pf_ruleset dependecy file"
134	run rm -rf "$OBJTOP"/sbin/pfctl/.depend.pf_ruleset.o
135fi
136
137# 20210108  821aa63a0940   non-widechar version of ncurses removed
138if [ -e "$OBJTOP"/lib/ncurses/ncursesw ]; then
139	echo "Removing stale ncurses objects"
140	for libcompat in "" $ALL_libcompats; do
141		dirprfx=${libcompat:+obj-lib${libcompat}/}
142		run rm -rf "$OBJTOP"/${dirprfx}lib/ncurses
143	done
144fi
145
146# 20210608  f20893853e8e    move from atomic.S to atomic.c
147clean_dep   cddl/lib/libspl atomic S
148# 20211207  cbdec8db18b5    switch to libthr-friendly pdfork
149clean_dep   lib/libc        pdfork S
150
151# 20211230  5e6a2d6eb220    libc++.so.1 path changed in ldscript
152if [ -e "$OBJTOP"/lib/libc++/libc++.ld ] && \
153    fgrep -q "/usr/lib/libc++.so" "$OBJTOP"/lib/libc++/libc++.ld; then
154	echo "Removing old libc++ linker script"
155	run rm -f "$OBJTOP"/lib/libc++/libc++.ld
156fi
157
158# 20220326  fbc002cb72d2    move from bcmp.c to bcmp.S
159if [ "$MACHINE_ARCH" = "amd64" ]; then
160	clean_dep lib/libc bcmp c
161fi
162
163# 20220524  68fe988a40ca    kqueue_test binary replaced shell script
164if stat "$OBJTOP"/tests/sys/kqueue/libkqueue/*kqtest* \
165    "$OBJTOP"/tests/sys/kqueue/libkqueue/.depend.kqtest* >/dev/null 2>&1; then
166	echo "Removing old kqtest"
167	run rm -f "$OBJTOP"/tests/sys/kqueue/libkqueue/.depend.* \
168	   "$OBJTOP"/tests/sys/kqueue/libkqueue/*
169fi
170
171# 20221115  42d10b1b56f2    move from rs.c to rs.cc
172clean_dep   usr.bin/rs      rs c
173
174# 20230110  bc42155199b5    usr.sbin/zic/zic -> usr.sbin/zic
175if [ -d "$OBJTOP"/usr.sbin/zic/zic ] ; then
176	echo "Removing old zic directory"
177	run rm -rf "$OBJTOP"/usr.sbin/zic/zic
178fi
179
180# 20230208  29c5f8bf9a01    move from mkmakefile.c to mkmakefile.cc
181clean_dep   usr.sbin/config  mkmakefile c
182# 20230209  83d7ed8af3d9    convert to main.cc and mkoptions.cc
183clean_dep   usr.sbin/config  main c
184clean_dep   usr.sbin/config  mkoptions c
185
186# 20230401  54579376c05e    kqueue1 from syscall to C wrapper
187clean_dep   lib/libc        kqueue1 S
188
189# 20230623  b077aed33b7b    OpenSSL 3.0 update
190if [ -f "$OBJTOP"/secure/lib/libcrypto/aria.o ]; then
191	echo "Removing old OpenSSL 1.1.1 tree"
192	for libcompat in "" $ALL_libcompats; do
193		dirprfx=${libcompat:+obj-lib${libcompat}/}
194		run rm -rf "$OBJTOP"/${dirprfx}secure/lib/libcrypto \
195		    "$OBJTOP"/${dirprfx}secure/lib/libssl
196	done
197fi
198
199# 20230714  ee8b0c436d72    replace ffs/fls implementations with clang builtins
200clean_dep   lib/libc        ffs   S
201clean_dep   lib/libc        ffsl  S
202clean_dep   lib/libc        ffsll S
203clean_dep   lib/libc        fls   S
204clean_dep   lib/libc        flsl  S
205clean_dep   lib/libc        flsll S
206
207# 20230815  28f6c2f29280    GoogleTest update
208if [ -e "$OBJTOP"/tests/sys/fs/fusefs/mockfs.o ] && \
209    grep -q '_ZN7testing8internal18g_linked_ptr_mutexE' "$OBJTOP"/tests/sys/fs/fusefs/mockfs.o; then
210	echo "Removing stale fusefs GoogleTest objects"
211	run rm -rf "$OBJTOP"/tests/sys/fs/fusefs
212fi
213
214# 20231031  0527c9bdc718    Remove forward compat ino64 stuff
215clean_dep   lib/libc        fstat         c
216clean_dep   lib/libc        fstatat       c
217clean_dep   lib/libc        fstatfs       c
218clean_dep   lib/libc        getdirentries c
219clean_dep   lib/libc        getfsstat     c
220clean_dep   lib/libc        statfs        c
221
222# 20240308  e6ffc7669a56    Remove pointless MD syscall(2)
223# 20240308  0ee0ae237324    Remove pointless MD syscall(2)
224# 20240308  7b3836c28188    Remove pointless MD syscall(2)
225if [ ${MACHINE} != i386 -a -f "$OBJTOP"/lib/libsys/.depend.syscall.o ] && \
226    grep -q -e 'libsys/[^ /]*/syscall.S' "$OBJTOP"/lib/libsys/.depend.syscall.*; then
227	echo "Removing stale <arch>/syscall.S depends"
228	clean_dep   lib/libsys  syscall S
229	clean_dep   lib/libc    syscall S
230fi
231
232# 20240416  2fda3ab0ac19    WITH_NVME: Remove from broken
233if [ -f "$OBJTOP"/rescue/rescue/rescue.mk ] && \
234    grep -q -v 'nvme_util.o' "$OBJTOP"/rescue/rescue/rescue.mk; then
235	echo "removing rescue.mk without nvme_util.o"
236	rm -f "$OBJTOP"/rescue/rescue/rescue.mk
237fi
238