[lkml]   [2017]   [Oct]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH 2/2] kbuild: redefine __FILE__ as relative path from $(srctree) if possible
Since Kbuild runs in the objtree, __FILE__ can be a very long path
depending of $(srctree).

Commit 9da0763bdd82 ("kbuild: Use relative path when building in a
subdir of the source tree") made the situation better for cases where
objtree is a child of srctree. ($(srctree) is "..")

For other cases of out-of-tree build, filenames in WARN_ON() etc. are
still an absolute path. It also means the kernel image depends on
where it was built.

Here, the idea is to redefine __FILE__ as the relative path from
$(srctree), but doing so causes a compiler warning:
warning: "__FILE__" redefined [-Wbuiltin-macro-redefined]

The option -Wno-builtin-macro-redefined can suppress it, but it is
only recognized by GCC 4.4 or newer. Re-define __FILE__ only when

Please note __FILE__ is always an absolute path for external modules.

Signed-off-by: Masahiro Yamada <>

Makefile | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/Makefile b/Makefile
index 2c4a238..a3e8931 100644
--- a/Makefile
+++ b/Makefile
@@ -1091,6 +1091,15 @@ ifdef stackp-check

+# If possible, redefne __FILE__ as relative path from $(srctree).
+# $$ is needed to expand the following in submake
+ifeq ($(call cc-option-yn,-Wno-builtin-macro-redefined),y)
+KBUILD_CFLAGS += -Wno-builtin-macro-redefined \
+ -D__FILE__=$$(call stringify,$$(src)/$$(notdir $$<))
+# CAUTION: Do not add any reference to KBUILD_CFLAGS below this line.
+# Any call of cc-option, etc. will fail.
# Generate some files
# ---------------------------------------------------------------------------

 \ /
  Last update: 2017-10-12 11:57    [W:0.035 / U:11.412 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site