xref: /freebsd/tools/build/depend-cleanup.sh (revision 66fd12cf4896eb08ad8e7a2627537f84ead84dd3)
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
76run()
77{
78	if [ "$VERBOSE" ]; then
79		echo "$@"
80	fi
81	if ! [ "$PRETEND" ]; then
82		"$@"
83	fi
84}
85
86# $1 directory
87# $2 source filename w/o extension
88# $3 source extension
89clean_dep()
90{
91	if egrep -qw "$2\.$3" "$OBJTOP"/$1/.depend.$2.*o 2>/dev/null; then
92		echo "Removing stale dependencies and objects for $2.$3"
93		run rm -f \
94		    "$OBJTOP"/$1/.depend.$2.* \
95		    "$OBJTOP"/$1/$2.*o
96	fi
97	if egrep -qw "$2\.$3" "$OBJTOP"/obj-lib32/$1/.depend.$2.*o 2>/dev/null; then
98		echo "Removing 32-bit stale dependencies and objects for $2.$3"
99		run rm -f \
100		    "$OBJTOP"/obj-lib32/$1/.depend.$2.* \
101		    "$OBJTOP"/obj-lib32/$1/$2.*o
102	fi
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	run rm -rf "$OBJTOP"/cddl "$OBJTOP"/obj-lib32/cddl
117fi
118
119# 20200916  WARNS bumped, need bootstrapped crunchgen stubs
120if [ -e "$OBJTOP"/rescue/rescue/rescue.c ] && \
121    ! grep -q 'crunched_stub_t' "$OBJTOP"/rescue/rescue/rescue.c; then
122	echo "Removing old rescue(8) tree"
123	run rm -rf "$OBJTOP"/rescue/rescue
124fi
125
126# 20210105  fda7daf06301   pfctl gained its own version of pf_ruleset.c
127if [ -e "$OBJTOP"/sbin/pfctl/.depend.pf_ruleset.o ] && \
128    egrep -qw "sys/netpfil/pf/pf_ruleset.c" \
129    "$OBJTOP"/sbin/pfctl/.depend.pf_ruleset.o; then
130	echo "Removing old pf_ruleset dependecy file"
131	run rm -rf "$OBJTOP"/sbin/pfctl/.depend.pf_ruleset.o
132fi
133
134# 20210108  821aa63a0940   non-widechar version of ncurses removed
135if [ -e "$OBJTOP"/lib/ncurses/ncursesw ]; then
136	echo "Removing stale ncurses objects"
137	run rm -rf "$OBJTOP"/lib/ncurses "$OBJTOP"/obj-lib32/lib/ncurses
138fi
139
140# 20210608  f20893853e8e    move from atomic.S to atomic.c
141clean_dep   cddl/lib/libspl atomic S
142# 20211207  cbdec8db18b5    switch to libthr-friendly pdfork
143clean_dep   lib/libc        pdfork S
144
145# 20211230  5e6a2d6eb220    libc++.so.1 path changed in ldscript
146if [ -e "$OBJTOP"/lib/libc++/libc++.ld ] && \
147    fgrep -q "/usr/lib/libc++.so" "$OBJTOP"/lib/libc++/libc++.ld; then
148	echo "Removing old libc++ linker script"
149	run rm -f "$OBJTOP"/lib/libc++/libc++.ld
150fi
151
152# 20220326  fbc002cb72d2    move from bcmp.c to bcmp.S
153if [ "$MACHINE_ARCH" = "amd64" ]; then
154	clean_dep lib/libc bcmp c
155fi
156
157# 20220524  68fe988a40ca    kqueue_test binary replaced shell script
158if stat "$OBJTOP"/tests/sys/kqueue/libkqueue/*kqtest* \
159    "$OBJTOP"/tests/sys/kqueue/libkqueue/.depend.kqtest* >/dev/null 2>&1; then
160	echo "Removing old kqtest"
161	run rm -f "$OBJTOP"/tests/sys/kqueue/libkqueue/.depend.* \
162	   "$OBJTOP"/tests/sys/kqueue/libkqueue/*
163fi
164
165# 20221115  42d10b1b56f2    move from rs.c to rs.cc
166clean_dep   usr.bin/rs      rs c
167
168# 20230110  bc42155199b5    usr.sbin/zic/zic -> usr.sbin/zic
169if [ -d "$OBJTOP"/usr.sbin/zic/zic ] ; then
170	echo "Removing old zic directory"
171	run rm -rf "$OBJTOP"/usr.sbin/zic/zic
172fi
173
174# 20230208  29c5f8bf9a01    move from mkmakefile.c to mkmakefile.cc
175clean_dep   usr.sbin/config  mkmakefile c
176# 20230209  83d7ed8af3d9    convert to main.cc and mkoptions.cc
177clean_dep   usr.sbin/config  main c
178clean_dep   usr.sbin/config  mkoptions c
179
180# 20230401  54579376c05e    kqueue1 from syscall to C wrapper
181clean_dep   lib/libc        kqueue1 S
182
183# 20230623  b077aed33b7b    OpenSSL 3.0 update
184if [ -f "$OBJTOP"/secure/lib/libcrypto/aria.o ]; then
185	echo "Removing old OpenSSL 1.1.1 tree"
186	run rm -rf "$OBJTOP"/secure/lib/libcrypto \
187	    "$OBJTOP"/secure/lib/libssl \
188	    "$OBJTOP"/obj-lib32/secure/lib/libcrypto \
189	    "$OBJTOP"/obj-lib32/secure/lib/libssl
190fi
191
192# 20230714  ee8b0c436d72    replace ffs/fls implementations with clang builtins
193clean_dep   lib/libc        ffs   S
194clean_dep   lib/libc        ffsl  S
195clean_dep   lib/libc        ffsll S
196clean_dep   lib/libc        fls   S
197clean_dep   lib/libc        flsl  S
198clean_dep   lib/libc        flsll S
199