5050# - Replacing generated files with files committed to the tree. This is special
5151# case of moving from one directory to another. The stale generated file also
5252# needs to be deleted, so that it isn't found in make's .PATH. Note the
53- # unconditional `rm -f `: there's no need for an extra call to first check for
53+ # unconditional `rm -fv `: there's no need for an extra call to first check for
5454# the file's existence.
5555#
5656# # 20250110 3863fec1ce2d add strlen SIMD implementation
5757# clean_dep lib/libc strlen S arm-optimized-routines
58- # run rm -f "$OBJTOP"/lib/libc/strlen.S
58+ # run rm -fv "$OBJTOP"/lib/libc/strlen.S
5959#
6060# A rule may be required for only one architecture:
6161#
@@ -152,6 +152,11 @@ run()
152152 fi
153153}
154154
155+ # Clean the depend and object files for a given source file if the
156+ # depend file matches a regex (which defaults to the source file
157+ # name). This is typically used if a file was renamed, especially if
158+ # only its extension was changed (e.g. from .c to .cc).
159+ #
155160# $1 directory
156161# $2 source filename w/o extension
157162# $3 source extension
@@ -162,13 +167,34 @@ clean_dep()
162167 dirprfx=${libcompat: +obj-lib${libcompat} / }
163168 if egrep -qw " ${4:- $2 \. $3 } " " $OBJTOP " /$dirprfx $1 /.depend.$2 .* o 2> /dev/null; then
164169 echo " Removing stale ${libcompat: +lib${libcompat} } dependencies and objects for $2 .$3 "
165- run rm -f \
170+ run rm -fv \
166171 " $OBJTOP " /$dirprfx $1 /.depend.$2 .* \
167172 " $OBJTOP " /$dirprfx $1 /$2 .* o
168173 fi
169174 done
170175}
171176
177+ # Clean the object file for a given source file if it exists and
178+ # matches a regex. This is typically used if a a change in CFLAGS or
179+ # similar caused a change in the generated code without a change in
180+ # the sources.
181+ #
182+ # $1 directory
183+ # $2 source filename w/o extension
184+ # $3 source extension
185+ # $4 regex for egrep -w
186+ clean_obj ()
187+ {
188+ for libcompat in " " $ALL_libcompats ; do
189+ dirprfx=${libcompat: +obj-lib${libcompat} / }
190+ if strings " $OBJTOP " /$dirprfx $1 /$2 .* o 2> /dev/null | egrep -qw " ${4} " ; then
191+ echo " Removing stale ${libcompat: +lib${libcompat} } objects for $2 .$3 "
192+ run rm -fv \
193+ " $OBJTOP " /$dirprfx $1 /$2 .* o
194+ fi
195+ done
196+ }
197+
172198extract_epoch ()
173199{
174200 [ -s " $1 " ] || return 0
243269if stat " $OBJTOP " /tests/sys/kqueue/libkqueue/* kqtest* \
244270 " $OBJTOP " /tests/sys/kqueue/libkqueue/.depend.kqtest* > /dev/null 2>&1 ; then
245271 echo " Removing old kqtest"
246- run rm -f " $OBJTOP " /tests/sys/kqueue/libkqueue/.depend.* \
272+ run rm -fv " $OBJTOP " /tests/sys/kqueue/libkqueue/.depend.* \
247273 " $OBJTOP " /tests/sys/kqueue/libkqueue/*
248274fi
249275
317343if [ -f " $OBJTOP " /rescue/rescue/rescue.mk ] && \
318344 ! grep -q ' nvme_util.o' " $OBJTOP " /rescue/rescue/rescue.mk; then
319345 echo " removing rescue.mk without nvme_util.o"
320- run rm -f " $OBJTOP " /rescue/rescue/rescue.mk
346+ run rm -fv " $OBJTOP " /rescue/rescue/rescue.mk
321347fi
322348
323349# 20240910 e2df9bb44109
@@ -337,7 +363,7 @@ if [ ${MACHINE} = riscv ]; then
337363 fi
338364 if ! grep -q ' lib/libc/csu/riscv/reloc\.c' " $f " ; then
339365 echo " Removing stale dependencies and objects for libc_start1.c"
340- run rm -f \
366+ run rm -fv \
341367 " $OBJTOP " /lib/libc/.depend.libc_start1.* \
342368 " $OBJTOP " /lib/libc/libc_start1.* o
343369 break
@@ -351,28 +377,28 @@ f="$p"/arm_mve_builtin_sema.inc
351377if [ -e " $f " ]; then
352378 if grep -q SemaBuiltinConstantArgRange " $f " ; then
353379 echo " Removing pre-llvm19 clang-tblgen output"
354- run rm -f " $p " /* .inc
380+ run rm -fv " $p " /* .inc
355381 fi
356382fi
357383
358384# 20241025 cb5e41b16083 Unbundle hash functions fom lib/libcrypt
359- clean_dep lib/libcrypt crypt-md5 c
360- clean_dep lib/libcrypt crypt-nthash c
361- clean_dep lib/libcrypt crypt-sha256 c
362- clean_dep lib/libcrypt crypt-sha512 c
385+ clean_obj lib/libcrypt crypt-md5 c __MD5Init
386+ clean_obj lib/libcrypt crypt-nthash c __MD4Init
387+ clean_obj lib/libcrypt crypt-sha256 c __SHA256Init
388+ clean_obj lib/libcrypt crypt-sha512 c __SHA512Init
363389
364390# 20241213 b55f5e1c4ae3 jemalloc: Move generated jemalloc.3 into lib/libc tree
365391if [ -h " $OBJTOP " /lib/libc/jemalloc.3 ]; then
366392 # Have to cleanup the jemalloc.3 in the obj tree since make gets
367393 # confused and won't use the one in lib/libc/malloc/jemalloc/jemalloc.3
368394 echo " Removing stale jemalloc.3 object"
369- run rm -f " $OBJTOP " /lib/libc/jemalloc.3
395+ run rm -fv " $OBJTOP " /lib/libc/jemalloc.3
370396fi
371397
372398if [ $MACHINE_ARCH = aarch64 ]; then
373399 # 20250110 5e7d93a60440 add strcmp SIMD implementation
374400 ALL_libcompats= clean_dep lib/libc strcmp S arm-optimized-routines
375- run rm -f " $OBJTOP " /lib/libc/strcmp.S
401+ run rm -fv " $OBJTOP " /lib/libc/strcmp.S
376402
377403 # 20250110 b91003acffe7 add strspn optimized implementation
378404 ALL_libcompats= clean_dep lib/libc strspn c
@@ -391,7 +417,7 @@ if [ $MACHINE_ARCH = aarch64 ]; then
391417
392418 # 20250110 25c485e14769 add strncmp SIMD implementation
393419 ALL_libcompats= clean_dep lib/libc strncmp S arm-optimized-routines
394- run rm -f " $OBJTOP " /lib/libc/strncmp.S
420+ run rm -fv " $OBJTOP " /lib/libc/strncmp.S
395421
396422 # 20250110 bad17991c06d add memccpy SIMD implementation
397423 ALL_libcompats= clean_dep lib/libc memccpy c
@@ -402,11 +428,11 @@ if [ $MACHINE_ARCH = aarch64 ]; then
402428 # 20250110 bea89d038ac5 add strlcat SIMD implementation, and move memchr
403429 ALL_libcompats= clean_dep lib/libc strlcat c " libc.string.strlcat.c"
404430 ALL_libcompats= clean_dep lib/libc memchr S " [[:space:]]memchr.S"
405- run rm -f " $OBJTOP " /lib/libc/memchr.S
431+ run rm -fv " $OBJTOP " /lib/libc/memchr.S
406432
407433 # 20250110 3863fec1ce2d add strlen SIMD implementation
408434 ALL_libcompats= clean_dep lib/libc strlen S arm-optimized-routines
409- run rm -f " $OBJTOP " /lib/libc/strlen.S
435+ run rm -fv " $OBJTOP " /lib/libc/strlen.S
410436
411437 # 20250110 79e01e7e643c add bcopy & bzero wrapper
412438 ALL_libcompats= clean_dep lib/libc bcopy c " libc.string.bcopy.c"
@@ -431,15 +457,15 @@ clean_dep usr.sbin/ctld uclparse c
431457# 20250425 2e47f35be5dc libllvm, libclang and liblldb became shared libraries
432458if [ -f " $OBJTOP " /lib/clang/libllvm/libllvm.a ]; then
433459 echo " Removing old static libllvm library"
434- run rm -f " $OBJTOP " /lib/clang/libllvm/libllvm.a
460+ run rm -fv " $OBJTOP " /lib/clang/libllvm/libllvm.a
435461fi
436462if [ -f " $OBJTOP " /lib/clang/libclang/libclang.a ]; then
437463 echo " Removing old static libclang library"
438- run rm -f " $OBJTOP " /lib/clang/libclang/libclang.a
464+ run rm -fv " $OBJTOP " /lib/clang/libclang/libclang.a
439465fi
440466if [ -f " $OBJTOP " /lib/clang/liblldb/liblldb.a ]; then
441467 echo " Removing old static liblldb library"
442- run rm -f " $OBJTOP " /lib/clang/liblldb/liblldb.a
468+ run rm -fv " $OBJTOP " /lib/clang/liblldb/liblldb.a
443469fi
444470
445471# 20250813 4f766afc1ca0 tcopy converted to C++
0 commit comments