Message ID | 20240819160309.2218114-3-vegard.nossum@oracle.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | output a valid shell script when running 'make -n' | expand |
On Mon, Aug 19, 2024 at 06:02:59PM +0200 Vegard Nossum wrote: > When running 'make --dry-run', make will invoke itself recursively for > recipes using $(MAKE), but otherwise not execute the other commands in > a recipe. > > However, if a prerequisite is missing and 'make' does not how to create it > (which will be the case when running 'make -n'), it will complain with an > error message like this: > > $ make -n > ... > make -f ./scripts/Makefile.modpost > make[1]: *** No rule to make target 'modules.order', needed by 'modules-only.symvers'. Stop. > make: *** [Makefile:1868: modpost] Error 2 > > In this case, the top-level makefile has reached a recipe that ran 'make' > recursively on scripts/Makefile.modpost, which itself has a rule with > modules.order as a prerequisite. Since the file doesn't exist, and make > doesn't know how to create it, it errors out. > > We can document such prerequisites (which are expected to be created by > the parent Makefile) by adding them to the PHONY list of each respective > Makefile. > > Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com> > --- > arch/x86/boot/compressed/Makefile | 6 ++++++ > scripts/Makefile.modfinal | 5 +++++ > scripts/Makefile.modpost | 4 ++++ > scripts/Makefile.vmlinux | 7 +++++++ > scripts/Makefile.vmlinux_o | 3 +++ > 5 files changed, 25 insertions(+) > > diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile > index f2051644de943..ccef6f0e04bc7 100644 > --- a/arch/x86/boot/compressed/Makefile > +++ b/arch/x86/boot/compressed/Makefile > @@ -80,6 +80,9 @@ quiet_cmd_voffset = VOFFSET $@ > > targets += ../voffset.h > > +# We don't know how to build this A comment for documentation is a good idea, but I think this one is not very helpful to those who don't know the patch description. What about something like this? # Provided by a recursive-make predecessor Kind regards Nicolas
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index f2051644de943..ccef6f0e04bc7 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -80,6 +80,9 @@ quiet_cmd_voffset = VOFFSET $@ targets += ../voffset.h +# We don't know how to build this +PHONY += vmlinux + $(obj)/../voffset.h: vmlinux FORCE $(call if_changed,voffset) @@ -107,6 +110,9 @@ vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o vmlinux-libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a +# We don't know how to build this +PHONY += $(objtree)/drivers/firmware/efi/libstub/lib.a + $(obj)/vmlinux: $(vmlinux-objs-y) $(vmlinux-libs-y) FORCE $(call if_changed,ld) diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal index 1fa98b5e952b4..696888f0a0bde 100644 --- a/scripts/Makefile.modfinal +++ b/scripts/Makefile.modfinal @@ -15,6 +15,11 @@ include $(srctree)/scripts/Makefile.lib # find all modules listed in modules.order modules := $(call read-file, $(MODORDER)) +# We don't know how to build these +PHONY += $(modules) +PHONY += $(modules:%.o=%.mod.c) +PHONY += scripts/module.lds + __modfinal: $(modules:%.o=%.ko) @: diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 44936ebad161e..65f2bdc702369 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -140,6 +140,10 @@ quiet_cmd_modpost = MODPOST $@ echo >&2 " if you want to proceed at your own risk.";) \ $(MODPOST) $(modpost-args) +# We don't know how to build these +PHONY += vmlinux.o +PHONY += $(MODORDER) + targets += $(output-symdump) $(output-symdump): $(modpost-deps) FORCE $(call if_changed,modpost) diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux index 49946cb968440..10d80e07f945c 100644 --- a/scripts/Makefile.vmlinux +++ b/scripts/Makefile.vmlinux @@ -18,6 +18,9 @@ quiet_cmd_cc_o_c = CC $@ $(call if_changed_dep,cc_o_c) ifdef CONFIG_MODULES +# We don't know how to build this +PHONY += .vmlinux.export.c + targets += .vmlinux.export.o vmlinux: .vmlinux.export.o endif @@ -29,6 +32,10 @@ cmd_link_vmlinux = \ $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)"; \ $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) +# We don't know how to build these +PHONY += vmlinux.o +PHONY += $(KBUILD_LDS) + targets += vmlinux vmlinux: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE +$(call if_changed_dep,link_vmlinux) diff --git a/scripts/Makefile.vmlinux_o b/scripts/Makefile.vmlinux_o index 6de297916ce68..7af841eb1ce5b 100644 --- a/scripts/Makefile.vmlinux_o +++ b/scripts/Makefile.vmlinux_o @@ -58,6 +58,9 @@ define rule_ld_vmlinux.o $(call cmd,gen_objtooldep) endef +# We don't know how to build this +PHONY += vmlinux.a + vmlinux.o: $(initcalls-lds) vmlinux.a $(KBUILD_VMLINUX_LIBS) FORCE $(call if_changed_rule,ld_vmlinux.o)
When running 'make --dry-run', make will invoke itself recursively for recipes using $(MAKE), but otherwise not execute the other commands in a recipe. However, if a prerequisite is missing and 'make' does not how to create it (which will be the case when running 'make -n'), it will complain with an error message like this: $ make -n ... make -f ./scripts/Makefile.modpost make[1]: *** No rule to make target 'modules.order', needed by 'modules-only.symvers'. Stop. make: *** [Makefile:1868: modpost] Error 2 In this case, the top-level makefile has reached a recipe that ran 'make' recursively on scripts/Makefile.modpost, which itself has a rule with modules.order as a prerequisite. Since the file doesn't exist, and make doesn't know how to create it, it errors out. We can document such prerequisites (which are expected to be created by the parent Makefile) by adding them to the PHONY list of each respective Makefile. Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com> --- arch/x86/boot/compressed/Makefile | 6 ++++++ scripts/Makefile.modfinal | 5 +++++ scripts/Makefile.modpost | 4 ++++ scripts/Makefile.vmlinux | 7 +++++++ scripts/Makefile.vmlinux_o | 3 +++ 5 files changed, 25 insertions(+)