From b34e0b2e6865b8b571976c19f35fde9865e137fa Mon Sep 17 00:00:00 2001 From: Alexander Mikhalitsyn Date: Sun, 19 Jul 2026 18:54:05 +0200 Subject: [PATCH] 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 --- images/Makefile | 2 +- scripts/nmk/scripts/build.mk | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/images/Makefile b/images/Makefile index 2c33152e9..4cc73676f 100644 --- a/images/Makefile +++ b/images/Makefile @@ -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), \ diff --git a/scripts/nmk/scripts/build.mk b/scripts/nmk/scripts/build.mk index d01d2b72c..cbf911418 100644 --- a/scripts/nmk/scripts/build.mk +++ b/scripts/nmk/scripts/build.mk @@ -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