kbuild: remove --include-dir MAKEFLAG from top Makefile
authorMasahiro Yamada <masahiroy@kernel.org>
Sat, 28 Jan 2023 09:24:23 +0000 (18:24 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Sun, 5 Feb 2023 09:51:22 +0000 (18:51 +0900)
I added $(srctree)/ to some included Makefiles in the following commits:

 - 3204a7fb98a3 ("kbuild: prefix $(srctree)/ to some included Makefiles")
 - d82856395505 ("kbuild: do not require sub-make for separate output tree builds")

They were a preparation for removing --include-dir flag.

I have never thought --include-dir useful. Rather, it _is_ harmful.

For example, run the following commands:

  $ make -s ARCH=x86 mrproper defconfig
  $ make ARCH=arm O=foo dtbs
  make[1]: Entering directory '/tmp/linux/foo'
    HOSTCC  scripts/basic/fixdep
  Error: kernelrelease not valid - run 'make prepare' to update it
    UPD     include/config/kernel.release
  make[1]: Leaving directory '/tmp/linux/foo'

The first command configures the source tree for x86. The next command
tries to build ARM device trees in the separate foo/ directory - this
must stop because the directory foo/ has not been configured yet.

However, due to --include-dir=$(abs_srctree), the top Makefile includes
the wrong include/config/auto.conf from the source tree and continues
building. Kbuild traverses the directory tree, but of course it does
not work correctly. The Error message is also pointless - 'make prepare'
does not help at all for fixing the issue.

This commit fixes more arch Makefile, and finally removes --include-dir
from the top Makefile.

There are more breakages under drivers/, but I do not volunteer to fix
them all. I just moved --include-dir to drivers/Makefile.

With this commit, the second command will stop with a sensible message.

  $ make -s ARCH=x86 mrproper defconfig
  $ make ARCH=arm O=foo dtbs
  make[1]: Entering directory '/tmp/linux/foo'
    SYNC    include/config/auto.conf.cmd
  ***
  *** The source tree is not clean, please run 'make ARCH=arm mrproper'
  *** in /tmp/linux
  ***
  make[2]: *** [../Makefile:646: outputmakefile] Error 1
  /tmp/linux/Makefile:770: include/config/auto.conf.cmd: No such file or directory
  make[1]: *** [/tmp/linux/Makefile:793: include/config/auto.conf.cmd] Error 2
  make[1]: Leaving directory '/tmp/linux/foo'
  make: *** [Makefile:226: __sub-make] Error 2

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
17 files changed:
Makefile
arch/arm/mach-s3c/Makefile
arch/ia64/kernel/Makefile
arch/mips/Kbuild
arch/mips/Makefile.postlink
arch/powerpc/Makefile.postlink
arch/um/drivers/Makefile
arch/um/kernel/Makefile
arch/um/kernel/skas/Makefile
arch/um/os-Linux/Makefile
arch/um/os-Linux/drivers/Makefile
arch/um/os-Linux/skas/Makefile
arch/x86/Makefile.um
arch/x86/um/Makefile
arch/x86/um/os-Linux/Makefile
drivers/Makefile
fs/hostfs/Makefile

index 93796ece1cba45b01d24935d964cbc0e703ee880..2faf872b680894e68c7e6b4dec7b6bb035ea7590 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -203,14 +203,6 @@ ifneq ($(words $(subst :, ,$(abs_srctree))), 1)
 $(error source directory cannot contain spaces or colons)
 endif
 
-ifneq ($(abs_srctree),$(abs_objtree))
-# Look for make include files relative to root of kernel src
-#
-# --included-dir is added for backward compatibility, but you should not rely on
-# it. Please add $(srctree)/ prefix to include Makefiles in the source tree.
-MAKEFLAGS += --include-dir=$(abs_srctree)
-endif
-
 ifneq ($(filter 3.%,$(MAKE_VERSION)),)
 # 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x
 # We need to invoke sub-make to avoid implicit rules in the top Makefile.
index 7c7d3318fd61365d61d698fa431d094797e8703b..deb44326b828620a288bab1762aa2677528bc372 100644 (file)
@@ -3,11 +3,11 @@
 # Copyright 2009 Simtec Electronics
 
 ifdef CONFIG_ARCH_S3C24XX
-include $(src)/Makefile.s3c24xx
+include $(srctree)/$(src)/Makefile.s3c24xx
 endif
 
 ifdef CONFIG_ARCH_S3C64XX
-include $(src)/Makefile.s3c64xx
+include $(srctree)/$(src)/Makefile.s3c64xx
 endif
 
 # Objects we always build independent of SoC choice
index ae9ff07de4abe419f3fdf8f740d148de1436332b..d7e1cabee2ec46bd8d3b74acde3bbb60832664fc 100644 (file)
@@ -43,4 +43,4 @@ obj-$(CONFIG_ELF_CORE)                += elfcore.o
 CFLAGS_traps.o  += -mfixed-range=f2-f5,f16-f31
 
 # The gate DSO image is built using a special linker script.
-include $(src)/Makefile.gate
+include $(srctree)/$(src)/Makefile.gate
index 9e8071f0e58ff1271c0bb118e12704838082aaba..af2967bffb73df2863c4f062abcc3f53d94b890c 100644 (file)
@@ -7,7 +7,7 @@ subdir-ccflags-y := -Werror
 endif
 
 # platform specific definitions
-include arch/mips/Kbuild.platforms
+include $(srctree)/arch/mips/Kbuild.platforms
 obj-y := $(platform-y)
 
 # make clean traverses $(obj-) without having included .config, so
index 4b1d3ba3a8a2830a03787860b51e3cbb6e21a313..34e3bd71f3b0e4184028ab99b620774ea0ea3728 100644 (file)
@@ -10,7 +10,7 @@ PHONY := __archpost
 __archpost:
 
 -include include/config/auto.conf
-include scripts/Kbuild.include
+include $(srctree)/scripts/Kbuild.include
 
 CMD_LS3_LLSC = arch/mips/tools/loongson3-llsc-check
 quiet_cmd_ls3_llsc = LLSCCHK $@
index a6c77f4d32b276e469da37c07c59f3a9a6940b36..1f860b3c9bec549f9fec6762199473871f9590fc 100644 (file)
@@ -9,7 +9,7 @@ PHONY := __archpost
 __archpost:
 
 -include include/config/auto.conf
-include scripts/Kbuild.include
+include $(srctree)/scripts/Kbuild.include
 
 quiet_cmd_head_check = CHKHEAD $@
       cmd_head_check = $(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/head_check.sh "$(NM)" "$@"
index e1dc4292bd22e67d617ebc1baad38fed8a8320cd..dee6f66353b334c6b55de0097409f2ce11cb7a26 100644 (file)
@@ -72,4 +72,4 @@ CFLAGS_null.o = -DDEV_NULL=$(DEV_NULL_PATH)
 
 CFLAGS_xterm.o += '-DCONFIG_XTERM_CHAN_DEFAULT_EMULATOR="$(CONFIG_XTERM_CHAN_DEFAULT_EMULATOR)"'
 
-include arch/um/scripts/Makefile.rules
+include $(srctree)/arch/um/scripts/Makefile.rules
index 1c2d4b29a3d4619e6591dde869eda4320efdc23c..811188be954cad1e2317df9fb21137f9dddfa95e 100644 (file)
@@ -29,7 +29,7 @@ obj-$(CONFIG_GENERIC_PCI_IOMAP) += ioport.o
 
 USER_OBJS := config.o
 
-include arch/um/scripts/Makefile.rules
+include $(srctree)/arch/um/scripts/Makefile.rules
 
 targets := config.c config.tmp capflags.c
 
index f3d494a4fd9ba2a627a6109b692d2e8f423de2a1..f93972a257653b7c7ccb2f09743f1e46add7c4fb 100644 (file)
@@ -14,4 +14,4 @@ UNPROFILE_OBJS := clone.o
 
 KCOV_INSTRUMENT := n
 
-include arch/um/scripts/Makefile.rules
+include $(srctree)/arch/um/scripts/Makefile.rules
index 77ac50baa3f82c0bb1532ee454d0af3b216260b6..544e0b344c754aedcf51b73e91dca8e74211a225 100644 (file)
@@ -18,4 +18,4 @@ USER_OBJS := $(user-objs-y) elf_aux.o execvp.o file.o helper.o irq.o \
        main.o mem.o process.o registers.o sigio.o signal.o start_up.o time.o \
        tty.o umid.o util.o
 
-include arch/um/scripts/Makefile.rules
+include $(srctree)/arch/um/scripts/Makefile.rules
index d79e75f1b69a2892f4cdf393f38a0b9abb1056a3..cf2d75bb188485dfe0a739d125466e796cb4f505 100644 (file)
@@ -10,4 +10,4 @@ obj-y =
 obj-$(CONFIG_UML_NET_ETHERTAP) += ethertap.o
 obj-$(CONFIG_UML_NET_TUNTAP) += tuntap.o
 
-include arch/um/scripts/Makefile.rules
+include $(srctree)/arch/um/scripts/Makefile.rules
index c4566e78881509e71603b6249253785785d31e1a..75f11989d2e90e246e4a68f4f7fcdd1b4ae49807 100644 (file)
@@ -7,4 +7,4 @@ obj-y := mem.o process.o
 
 USER_OBJS := $(obj-y)
 
-include arch/um/scripts/Makefile.rules
+include $(srctree)/arch/um/scripts/Makefile.rules
index b3c1ae084180dc6afab8cecc1fa319fe4a947524..b89e2e0024c574fbec4b17c5a226a7d5d4e4879e 100644 (file)
@@ -17,7 +17,7 @@ LDS_EXTRA             := -Ui386
 export LDS_EXTRA
 
 # First of all, tune CFLAGS for the specific CPU. This actually sets cflags-y.
-include arch/x86/Makefile_32.cpu
+include $(srctree)/arch/x86/Makefile_32.cpu
 
 # prevent gcc from keeping the stack 16 byte aligned. Taken from i386.
 cflags-y += $(call cc-option,-mpreferred-stack-boundary=2)
index 3d5cd2e578202ea8f2b3ac62585c43fc908b3d50..ee89f6bb9242636900dab80c31bdfc371896ee05 100644 (file)
@@ -48,4 +48,4 @@ include/generated/user_constants.h: $(obj)/user-offsets.s FORCE
 UNPROFILE_OBJS := stub_segv.o
 CFLAGS_stub_segv.o := $(CFLAGS_NO_HARDENING)
 
-include arch/um/scripts/Makefile.rules
+include $(srctree)/arch/um/scripts/Makefile.rules
index 253bfb8cb702da1d30e10b1c3e36ff5a7e90926c..ae169125d03fcc41ebd159dca6d58ee9ed964f55 100644 (file)
@@ -10,4 +10,4 @@ obj-$(CONFIG_64BIT) += prctl.o
 
 USER_OBJS := $(obj-y)
 
-include arch/um/scripts/Makefile.rules
+include $(srctree)/arch/um/scripts/Makefile.rules
index bdf1c66141c9bd5e8241a32233b768587e630504..62a9cb403a1a1309522a13ba4bb45575e565989c 100644 (file)
@@ -6,6 +6,11 @@
 # Rewritten to use lists instead of if-statements.
 #
 
+# Some driver Makefiles miss $(srctree)/ for include directive.
+ifdef building_out_of_srctree
+MAKEFLAGS += --include-dir=$(srctree)
+endif
+
 obj-y                          += irqchip/
 obj-y                          += bus/
 
index d5beaffad43b71ccb0090112d6fadc7ee27673d0..587bcd6e50a3a0170e3d34d948959755524df885 100644 (file)
@@ -8,4 +8,4 @@ hostfs-objs := hostfs_kern.o hostfs_user.o
 obj-y :=
 obj-$(CONFIG_HOSTFS) += hostfs.o
 
-include arch/um/scripts/Makefile.rules
+include $(srctree)/arch/um/scripts/Makefile.rules