tools build: Fix fixdep dependencies

The tools version of fixdep has broken dependencies.  It doesn't get
rebuilt if the host compiler or headers change.

Build fixdep with the tools kbuild infrastructure, so fixdep runs on
itself.  Due to the recursive dependency, its dependency file is
incomplete the very first time it gets built.  In that case build it a
second time to achieve fixdep inception.

Reported-by: Arthur Marsh <arthur.marsh@internode.on.net>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
This commit is contained in:
Josh Poimboeuf 2025-03-02 17:01:42 -08:00
parent 2e985fdb7e
commit a808a2b35f
2 changed files with 23 additions and 2 deletions

2
tools/build/Build Normal file
View File

@ -0,0 +1,2 @@
hostprogs := fixdep
fixdep-y := fixdep.o

View File

@ -37,5 +37,24 @@ ifneq ($(wildcard $(TMP_O)),)
$(Q)$(MAKE) -C feature OUTPUT=$(TMP_O) clean >/dev/null $(Q)$(MAKE) -C feature OUTPUT=$(TMP_O) clean >/dev/null
endif endif
$(OUTPUT)fixdep: $(srctree)/tools/build/fixdep.c include $(srctree)/tools/build/Makefile.include
$(QUIET_CC)$(HOSTCC) $(KBUILD_HOSTCFLAGS) $(KBUILD_HOSTLDFLAGS) -o $@ $<
FIXDEP := $(OUTPUT)fixdep
FIXDEP_IN := $(OUTPUT)fixdep-in.o
# To track fixdep's dependencies properly, fixdep needs to run on itself.
# Build it twice the first time.
$(FIXDEP_IN): FORCE
$(Q)if [ ! -f $(FIXDEP) ]; then \
$(MAKE) $(build)=fixdep HOSTCFLAGS="$(KBUILD_HOSTCFLAGS)"; \
rm -f $(FIXDEP).o; \
fi
$(Q)$(MAKE) $(build)=fixdep HOSTCFLAGS="$(KBUILD_HOSTCFLAGS)"
$(FIXDEP): $(FIXDEP_IN)
$(QUIET_LINK)$(HOSTCC) $(FIXDEP_IN) $(KBUILD_HOSTLDFLAGS) -o $@
FORCE:
.PHONY: FORCE