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