
Since Kbuild runs in the objtree, __FILE__ can be a very long path depending of $(srctree).
If objtree is a child of srctree, the situation is a bit better. ($(srctree) is "..")
For other cases of out-of-tree build, filenames in WARN_ON() etc. are still an absolute path. It also means the U-Boot 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. Redefine __FILE__ only when possible.
Signed-off-by: Masahiro Yamada yamada.masahiro@socionext.com ---
Changes in v2: - Rephrase comments for clarification - Fix a typo
Makefile | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/Makefile b/Makefile index 888486b..1ff312a 100644 --- a/Makefile +++ b/Makefile @@ -1334,6 +1334,15 @@ prepare0: archprepare FORCE # All the preparing.. prepare: prepare0
+# If possible, redefine __FILE__ as relative path from $(srctree). +# $$ is needed to evaluate the variables in sub-directories. +ifeq ($(call cc-option-yn,-Wno-builtin-macro-redefined),y) +KBUILD_CFLAGS += -Wno-builtin-macro-redefined \ + -D__FILE__=$$(call stringify,$$(src)/$$(notdir $$<)) +endif +# CAUTION: Do not add any reference to KBUILD_CFLAGS below this line. +# $(call cc-option,...) etc. may return wrong result. + # Generate some files # ---------------------------------------------------------------------------