xref: /freebsd/tools/build/depend-cleanup.sh (revision 1d69498623c0eced2de0f97cd553aff81a936911)
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
92# $4 optional regex for egrep -w
93clean_dep()
94{
95	for libcompat in "" $ALL_libcompats; do
96		dirprfx=${libcompat:+obj-lib${libcompat}/}
97		if egrep -qw "${4:-$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
108# 20220326  fbc002cb72d2    move from bcmp.c to bcmp.S
109if [ "$MACHINE_ARCH" = "amd64" ]; then
110	clean_dep lib/libc bcmp c
111fi
112
113# 20220524  68fe988a40ca    kqueue_test binary replaced shell script
114if stat "$OBJTOP"/tests/sys/kqueue/libkqueue/*kqtest* \
115    "$OBJTOP"/tests/sys/kqueue/libkqueue/.depend.kqtest* >/dev/null 2>&1; then
116	echo "Removing old kqtest"
117	run rm -f "$OBJTOP"/tests/sys/kqueue/libkqueue/.depend.* \
118	   "$OBJTOP"/tests/sys/kqueue/libkqueue/*
119fi
120
121# 20221115  42d10b1b56f2    move from rs.c to rs.cc
122clean_dep   usr.bin/rs      rs c
123
124# 20230110  bc42155199b5    usr.sbin/zic/zic -> usr.sbin/zic
125if [ -d "$OBJTOP"/usr.sbin/zic/zic ] ; then
126	echo "Removing old zic directory"
127	run rm -rf "$OBJTOP"/usr.sbin/zic/zic
128fi
129
130# 20230208  29c5f8bf9a01    move from mkmakefile.c to mkmakefile.cc
131clean_dep   usr.sbin/config  mkmakefile c
132# 20230209  83d7ed8af3d9    convert to main.cc and mkoptions.cc
133clean_dep   usr.sbin/config  main c
134clean_dep   usr.sbin/config  mkoptions c
135
136# 20230401  54579376c05e    kqueue1 from syscall to C wrapper
137clean_dep   lib/libc        kqueue1 S
138
139# 20230623  b077aed33b7b    OpenSSL 3.0 update
140if [ -f "$OBJTOP"/secure/lib/libcrypto/aria.o ]; then
141	echo "Removing old OpenSSL 1.1.1 tree"
142	for libcompat in "" $ALL_libcompats; do
143		dirprfx=${libcompat:+obj-lib${libcompat}/}
144		run rm -rf "$OBJTOP"/${dirprfx}secure/lib/libcrypto \
145		    "$OBJTOP"/${dirprfx}secure/lib/libssl
146	done
147fi
148
149# 20230714  ee8b0c436d72    replace ffs/fls implementations with clang builtins
150clean_dep   lib/libc        ffs   S
151clean_dep   lib/libc        ffsl  S
152clean_dep   lib/libc        ffsll S
153clean_dep   lib/libc        fls   S
154clean_dep   lib/libc        flsl  S
155clean_dep   lib/libc        flsll S
156
157# 20230815  28f6c2f29280    GoogleTest update
158if [ -e "$OBJTOP"/tests/sys/fs/fusefs/mockfs.o ] && \
159    grep -q '_ZN7testing8internal18g_linked_ptr_mutexE' "$OBJTOP"/tests/sys/fs/fusefs/mockfs.o; then
160	echo "Removing stale fusefs GoogleTest objects"
161	run rm -rf "$OBJTOP"/tests/sys/fs/fusefs
162fi
163
164# 20231031  0527c9bdc718    Remove forward compat ino64 stuff
165clean_dep   lib/libc        fstat         c
166clean_dep   lib/libc        fstatat       c
167clean_dep   lib/libc        fstatfs       c
168clean_dep   lib/libc        getdirentries c
169clean_dep   lib/libc        getfsstat     c
170clean_dep   lib/libc        statfs        c
171
172# 20240308  e6ffc7669a56    Remove pointless MD syscall(2)
173# 20240308  0ee0ae237324    Remove pointless MD syscall(2)
174# 20240308  7b3836c28188    Remove pointless MD syscall(2)
175if [ ${MACHINE} != i386 ]; then
176	libcompats=
177	for libcompat in $ALL_libcompats; do
178		if [ $MACHINE = amd64 ] && [ $libcompat = 32 ]; then
179			continue
180		fi
181		libcompats="${libcompats+$libcompats }$libcompat"
182	done
183	ALL_libcompats="$libcompats" clean_dep   lib/libsys  syscall S ".*/syscall\.S"
184	ALL_libcompats="$libcompats" clean_dep   lib/libc    syscall S ".*/syscall\.S"
185fi
186
187# 20240416  2fda3ab0ac19    WITH_NVME: Remove from broken
188if [ -f "$OBJTOP"/rescue/rescue/rescue.mk ] && \
189    ! grep -q 'nvme_util.o' "$OBJTOP"/rescue/rescue/rescue.mk; then
190	echo "removing rescue.mk without nvme_util.o"
191	run rm -f "$OBJTOP"/rescue/rescue/rescue.mk
192fi
193
194# 20240910  e2df9bb44109
195clean_dep   cddl/lib/libzpool abd_os c "linux/zfs/abd_os\.c"
196
197# 20241007
198clean_dep   cddl/lib/libzpool zfs_debug c "linux/zfs/zfs_debug\.c"
199
200# 20241011
201clean_dep   cddl/lib/libzpool arc_os c "linux/zfs/arc_os\.c"
202
203# 20241018  1363acbf25de    libc/csu: Support IFUNCs on riscv
204if [ ${MACHINE} = riscv ]; then
205	for f in "$OBJTOP"/lib/libc/.depend.libc_start1.*o; do
206		if [ ! -f "$f" ]; then
207			continue
208		fi
209		if ! grep -q 'lib/libc/csu/riscv/reloc\.c' "$f"; then
210			echo "Removing stale dependencies and objects for libc_start1.c"
211			run rm -f \
212			    "$OBJTOP"/lib/libc/.depend.libc_start1.* \
213			    "$OBJTOP"/lib/libc/libc_start1.*o
214			break
215		fi
216	done
217fi
218
219# 20241018  5deeebd8c6ca   Merge llvm-project release/19.x llvmorg-19.1.2-0-g7ba7d8e2f7b6
220p="$OBJTOP"/lib/clang/libclang/clang/Basic
221f="$p"/arm_mve_builtin_sema.inc
222if [ -e "$f" ]; then
223	if grep -q SemaBuiltinConstantArgRange "$f"; then
224		echo "Removing pre-llvm19 clang-tblgen output"
225		run rm -f "$p"/*.inc
226	fi
227fi
228
229# 20241025  cb5e41b16083  Unbundle hash functions fom lib/libcrypt
230clean_dep   lib/libcrypt crypt-md5    c
231clean_dep   lib/libcrypt crypt-nthash c
232clean_dep   lib/libcrypt crypt-sha256 c
233clean_dep   lib/libcrypt crypt-sha512 c
234
235# 20241213  b55f5e1c4ae3  jemalloc: Move generated jemalloc.3 into lib/libc tree
236if [ -h "$OBJTOP"/lib/libc/jemalloc.3 ]; then
237	# Have to cleanup the jemalloc.3 in the obj tree since make gets
238	# confused and won't use the one in lib/libc/malloc/jemalloc/jemalloc.3
239	echo "Removing stale jemalloc.3 object"
240	run rm -f "$OBJTOP"/lib/libc/jemalloc.3
241fi
242