kbuild: add a flag to force absolute path for srctree
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Sat, 6 Jul 2019 03:07:13 +0000 (12:07 +0900)
committerMasahiro Yamada <yamada.masahiro@socionext.com>
Wed, 10 Jul 2019 15:05:09 +0000 (00:05 +0900)
In old days, Kbuild always used an absolute path for $(srctree).

Since commit 890676c65d69 ("kbuild: Use relative path when building in
the source tree"), $(srctree) is '.' when O= was not passed from the
command line.

Yet, using absolute paths is useful in some cases even without O=, for
instance, to create a cscope file with absolute path tags.

'O=.' was known to work as a workaround to force Kbuild to use absolute
paths even when you are building in the source tree.

Since commit 25b146c5b8ce ("kbuild: allow Kbuild to start from any
directory"), Kbuild is too clever to be tricked. Even if you pass 'O=.'
Kbuild notices you are building in the source tree, then use '.' for
$(srctree).

So, 'make O=. cscope' is no help to create absolute path tags.

We cannot force one or the other according to commit e93bc1a0cab3
("Revert "kbuild: specify absolute paths for cscope""). Both of
relative path and absolute path have pros and cons.

This commit adds a new flag KBUILD_ABS_SRCTREE to allow users to
choose the absolute path for $(srctree).

'make KBUILD_ABS_SRCTREE=1 cscope' will work as a replacement of
'make O=. cscope'.

Reported-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Documentation/kbuild/kbuild.txt
Makefile
scripts/tags.sh

index 9c230ea719634e762a230e1ab73bc4597d0d6a7a..dcfeb32e336035cdb4b5020d0089a0a885f15512 100644 (file)
@@ -183,6 +183,15 @@ The output directory is often set using "O=..." on the commandline.
 
 The value can be overridden in which case the default value is ignored.
 
+KBUILD_ABS_SRCTREE
+--------------------------------------------------
+Kbuild uses a relative path to point to the tree when possible. For instance,
+when building in the source tree, the source tree path is '.'
+
+Setting this flag requests Kbuild to use absolute path to the source tree.
+There are some useful cases to do so, like when generating tag files with
+absolute path entries etc.
+
 KBUILD_SIGN_PIN
 --------------------------------------------------
 This variable allows a passphrase or PIN to be passed to the sign-file
index 91ad737ff538809b02991bbae095ab8757a76da6..357fd3623144063aac2a602a6273a07b779e7f41 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -244,6 +244,10 @@ else
        building_out_of_srctree := 1
 endif
 
+ifneq ($(KBUILD_ABS_SRCTREE),)
+srctree := $(abs_srctree)
+endif
+
 objtree                := .
 VPATH          := $(srctree)
 
index 7fea4044749bf11fb1d95a45e446fd9de200100e..4e18ae5282a69d222523d3db7a774ab9a5857aca 100755 (executable)
@@ -17,8 +17,7 @@ ignore="$(echo "$RCS_FIND_IGNORE" | sed 's|\\||g' )"
 # tags and cscope files should also ignore MODVERSION *.mod.c files
 ignore="$ignore ( -name *.mod.c ) -prune -o"
 
-# Do not use full path if we do not use O=.. builds
-# Use make O=. {tags|cscope}
+# Use make KBUILD_ABS_SRCTREE=1 {tags|cscope}
 # to force full paths for a non-O= build
 if [ "${srctree}" = "." -o -z "${srctree}" ]; then
        tree=