tree-wide: Makefile: use -MP CFLAG to produce .d files

Let's use -MP gcc flag when generating dependency (.d) files.
According to the manual:

       -MP This option instructs CPP to add a phony target for each
           dependency other than the main file, causing each to depend on
           nothing.  These dummy rules work around errors make gives if
           you remove header files without updating the Makefile to
           match.

This fixes incremental rebuild failures like:
make[2]: 'compel/compel-host-bin' is up to date.
  DEP      criu/arch/x86/crtools.d
  CC       criu/arch/x86/crtools.o
  LINK     criu/arch/x86/crtools.built-in.o
make[3]: Nothing to be done for 'all'.
make[3]: *** No rule to make target 'criu/include/linux/rseq.h', needed by 'criu/pie/parasite.o'.  Stop.
make[2]: *** [criu/Makefile:59: pie] Error 2

Usually, after header files renames or source directory tree reorganization.

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
This commit is contained in:
Alexander Mikhalitsyn 2026-07-19 18:54:05 +02:00
parent 3c7d4fa013
commit b34e0b2e68
No known key found for this signature in database
GPG key ID: B1F47F5CB05B4FA3
2 changed files with 4 additions and 4 deletions

View file

@ -118,7 +118,7 @@ ifeq ($(PROTOUFIX),y)
endif
$(obj)/$(1).pb-c.d: $(obj)/$(1).pb-c.c $(addsuffix .pb-c.d,$(addprefix $(obj)/,$(2))) $(makefile-deps)
$$(E) " DEP " $$@
$$(Q) $$(CC) -M -MT $$@ -MT $$(patsubst %.d,%.o,$$@) $$(CFLAGS) $$< -o $$@
$$(Q) $$(CC) -M -MP -MT $$@ -MT $$(patsubst %.d,%.o,$$@) $$(CFLAGS) $$< -o $$@
endef
$(foreach file, $(proto-obj-y), \

View file

@ -76,7 +76,7 @@ $(1).s: $(2).c $(__nmk-makefile-deps)
$$(Q) $$(CC) -S -fverbose-asm $$(strip $$(nmk-ccflags)) $$< -o $$@
$(1).d: $(2).c $(__nmk-makefile-deps)
$$(call msg-dep, $$@)
$$(Q) $$(CC) -M -MT $$@ -MT $$(patsubst %.d,%.o,$$@) $$(strip $$(nmk-ccflags)) $$< -o $$@
$$(Q) $$(CC) -M -MP -MT $$@ -MT $$(patsubst %.d,%.o,$$@) $$(strip $$(nmk-ccflags)) $$< -o $$@
$(1).o: $(2).S $(__nmk-makefile-deps)
$$(call msg-cc, $$@)
$$(Q) $$(CC) -c $$(strip $$(nmk-asflags)) $$< -o $$@
@ -85,7 +85,7 @@ $(1).i: $(2).S $(__nmk-makefile-deps)
$$(Q) $$(CC) -E $$(strip $$(nmk-asflags)) $$< -o $$@
$(1).d: $(2).S $(__nmk-makefile-deps)
$$(call msg-dep, $$@)
$$(Q) $$(CC) -M -MT $$@ -MT $$(patsubst %.d,%.o,$$@) $$(strip $$(nmk-asflags)) $$< -o $$@
$$(Q) $$(CC) -M -MP -MT $$@ -MT $$(patsubst %.d,%.o,$$@) $$(strip $$(nmk-asflags)) $$< -o $$@
endef
include $(src-makefile)
@ -227,7 +227,7 @@ $(patsubst %.o,%.s,$(addprefix $(obj)/,$(1))): $(obj)/%.s: $(obj)/%.c $(__nmk-ma
$$(Q) $$(HOSTCC) -S -fverbose-asm $$(strip $$(nmk-host-ccflags)) $$< -o $$@
$(patsubst %.o,%.d,$(addprefix $(obj)/,$(1))): $(obj)/%.d: $(obj)/%.c $(__nmk-makefile-deps)
$$(call msg-host-dep, $$@)
$$(Q) $$(HOSTCC) -M -MT $$@ -MT $$(patsubst %.d,%.o,$$@) $$(strip $$(nmk-host-ccflags)) $$< -o $$@
$$(Q) $$(HOSTCC) -M -MP -MT $$@ -MT $$(patsubst %.d,%.o,$$@) $$(strip $$(nmk-host-ccflags)) $$< -o $$@
endef
define gen-host-rules