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 107# 20220326 fbc002cb72d2 move from bcmp.c to bcmp.S 108if [ "$MACHINE_ARCH" = "amd64" ]; then 109 clean_dep lib/libc bcmp c 110fi 111 112# 20220524 68fe988a40ca kqueue_test binary replaced shell script 113if stat "$OBJTOP"/tests/sys/kqueue/libkqueue/*kqtest* \ 114 "$OBJTOP"/tests/sys/kqueue/libkqueue/.depend.kqtest* >/dev/null 2>&1; then 115 echo "Removing old kqtest" 116 run rm -f "$OBJTOP"/tests/sys/kqueue/libkqueue/.depend.* \ 117 "$OBJTOP"/tests/sys/kqueue/libkqueue/* 118fi 119 120# 20221115 42d10b1b56f2 move from rs.c to rs.cc 121clean_dep usr.bin/rs rs c 122 123# 20230110 bc42155199b5 usr.sbin/zic/zic -> usr.sbin/zic 124if [ -d "$OBJTOP"/usr.sbin/zic/zic ] ; then 125 echo "Removing old zic directory" 126 run rm -rf "$OBJTOP"/usr.sbin/zic/zic 127fi 128 129# 20230208 29c5f8bf9a01 move from mkmakefile.c to mkmakefile.cc 130clean_dep usr.sbin/config mkmakefile c 131# 20230209 83d7ed8af3d9 convert to main.cc and mkoptions.cc 132clean_dep usr.sbin/config main c 133clean_dep usr.sbin/config mkoptions c 134 135# 20230401 54579376c05e kqueue1 from syscall to C wrapper 136clean_dep lib/libc kqueue1 S 137 138# 20230623 b077aed33b7b OpenSSL 3.0 update 139if [ -f "$OBJTOP"/secure/lib/libcrypto/aria.o ]; then 140 echo "Removing old OpenSSL 1.1.1 tree" 141 for libcompat in "" $ALL_libcompats; do 142 dirprfx=${libcompat:+obj-lib${libcompat}/} 143 run rm -rf "$OBJTOP"/${dirprfx}secure/lib/libcrypto \ 144 "$OBJTOP"/${dirprfx}secure/lib/libssl 145 done 146fi 147 148# 20230714 ee8b0c436d72 replace ffs/fls implementations with clang builtins 149clean_dep lib/libc ffs S 150clean_dep lib/libc ffsl S 151clean_dep lib/libc ffsll S 152clean_dep lib/libc fls S 153clean_dep lib/libc flsl S 154clean_dep lib/libc flsll S 155 156# 20230815 28f6c2f29280 GoogleTest update 157if [ -e "$OBJTOP"/tests/sys/fs/fusefs/mockfs.o ] && \ 158 grep -q '_ZN7testing8internal18g_linked_ptr_mutexE' "$OBJTOP"/tests/sys/fs/fusefs/mockfs.o; then 159 echo "Removing stale fusefs GoogleTest objects" 160 run rm -rf "$OBJTOP"/tests/sys/fs/fusefs 161fi 162 163# 20231031 0527c9bdc718 Remove forward compat ino64 stuff 164clean_dep lib/libc fstat c 165clean_dep lib/libc fstatat c 166clean_dep lib/libc fstatfs c 167clean_dep lib/libc getdirentries c 168clean_dep lib/libc getfsstat c 169clean_dep lib/libc statfs c 170 171# 20240308 e6ffc7669a56 Remove pointless MD syscall(2) 172# 20240308 0ee0ae237324 Remove pointless MD syscall(2) 173# 20240308 7b3836c28188 Remove pointless MD syscall(2) 174if [ ${MACHINE} != i386 -a -f "$OBJTOP"/lib/libsys/.depend.syscall.o ] && \ 175 grep -q -e 'libsys/[^ /]*/syscall.S' "$OBJTOP"/lib/libsys/.depend.syscall.*; then 176 echo "Removing stale <arch>/syscall.S depends" 177 clean_dep lib/libsys syscall S 178 clean_dep lib/libc syscall S 179fi 180 181# 20240416 2fda3ab0ac19 WITH_NVME: Remove from broken 182if [ -f "$OBJTOP"/rescue/rescue/rescue.mk ] && \ 183 grep -q -v 'nvme_util.o' "$OBJTOP"/rescue/rescue/rescue.mk; then 184 echo "removing rescue.mk without nvme_util.o" 185 rm -f "$OBJTOP"/rescue/rescue/rescue.mk 186fi 187