git: aea2a658ef8b - main - Don't delete hack.c - causes perpetual 'out of date' kernel

From: David E. O'Brien <obrien_at_FreeBSD.org>
Date: Thu, 17 Feb 2022 04:03:32 UTC
The branch main has been updated by obrien:

URL: https://cgit.FreeBSD.org/src/commit/?id=aea2a658ef8b75a2246bf0d44f80ba8d6c6d344e

commit aea2a658ef8b75a2246bf0d44f80ba8d6c6d344e
Author:     David E. O'Brien <obrien@FreeBSD.org>
AuthorDate: 2022-02-14 02:24:36 +0000
Commit:     David E. O'Brien <obrien@FreeBSD.org>
CommitDate: 2022-02-17 04:02:50 +0000

    Don't delete hack.c - causes perpetual 'out of date' kernel
    
    Deleting hack.c cause the kernel to always be out of date:
    
       $ make kernel
       make: /usr/src/sys/amd64/compile/GENERIC/.depend.hack.pico, 1:
                 ignoring stale .depend for hack.c
       :> hack.c
       cc -shared -O2 -pipe ... -nostdlib hack.c -o hack.pico
       rm -f hack.c
       MAKE="make" sh ../../../conf/newvers.sh "-R" GENERIC
       cc -c -O2 -pipe ...  -std=iso9899:1999 -Werror  vers.c
       ctfconvert -L VERSION -g vers.o
       linking kernel.full
    
    Keeping hack.c in the compile directory causes no harm,
    so there's no reason to delete it.
    
    Also rename the file to "force-dyamic-hack.c" so it is
    clear what the hack is aboug.
    
    Reviewed by: sjg
    Differential Revision: https://reviews.freebsd.org/D34281
---
 sys/conf/kern.post.mk | 12 +++++++-----
 sys/conf/kern.pre.mk  |  2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/sys/conf/kern.post.mk b/sys/conf/kern.post.mk
index 087beb73f9ae..4fcae712e974 100644
--- a/sys/conf/kern.post.mk
+++ b/sys/conf/kern.post.mk
@@ -230,10 +230,12 @@ kernel-clean:
 # This is a hack.  BFD "optimizes" away dynamic mode if there are no
 # dynamic references.  We could probably do a '-Bforcedynamic' mode like
 # in the a.out ld.  For now, this works.
-hack.pico: Makefile
-	:> hack.c
-	${CC} ${CCLDFLAGS} -shared ${CFLAGS} -nostdlib hack.c -o hack.pico
-	rm -f hack.c
+force-dynamic-hack.c:
+	:> ${.TARGET}
+
+force-dynamic-hack.pico: force-dynamic-hack.c Makefile
+	${CC} ${CCLDFLAGS} -shared ${CFLAGS} -nostdlib \
+	    force-dynamic-hack.c -o ${.TARGET}
 
 offset.inc: $S/kern/genoffset.sh genoffset.o
 	NM='${NM}' NMFLAGS='${NMFLAGS}' sh $S/kern/genoffset.sh genoffset.o > ${.TARGET}
@@ -444,7 +446,7 @@ config.o env.o hints.o vers.o vnode_if.o:
 .if ${MK_REPRODUCIBLE_BUILD} != "no"
 REPRO_FLAG="-R"
 .endif
-vers.c: $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP}
+vers.c: .NOMETA_CMP $S/conf/newvers.sh $S/sys/param.h ${SYSTEM_DEP:Nvers.*}
 	MAKE="${MAKE}" sh $S/conf/newvers.sh ${REPRO_FLAG} ${KERN_IDENT}
 
 vnode_if.c: $S/tools/vnode_if.awk $S/kern/vnode_if.src
diff --git a/sys/conf/kern.pre.mk b/sys/conf/kern.pre.mk
index 8c753783b527..5a786c81324d 100644
--- a/sys/conf/kern.pre.mk
+++ b/sys/conf/kern.pre.mk
@@ -314,7 +314,7 @@ SYSTEM_CFILES= config.c env.c hints.c vnode_if.c
 SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
 SYSTEM_OBJS= locore.o ${MDOBJS} ${OBJS}
 SYSTEM_OBJS+= ${SYSTEM_CFILES:.c=.o}
-SYSTEM_OBJS+= hack.pico
+SYSTEM_OBJS+= force-dynamic-hack.pico
 
 KEYMAP=kbdcontrol -P ${SRCTOP}/share/vt/keymaps -P ${SRCTOP}/share/syscons/keymaps
 KEYMAP_FIX=sed -e 's/^static keymap_t.* = /static keymap_t key_map = /' -e 's/^static accentmap_t.* = /static accentmap_t accent_map = /'