2014-12-29 12:51:45 +00:00
|
|
|
###
|
|
|
|
# build: Generic definitions
|
|
|
|
#
|
|
|
|
# Lots of this code have been borrowed or heavily inspired from parts
|
|
|
|
# of kbuild code, which is not credited, but mostly developed by:
|
|
|
|
#
|
|
|
|
# Copyright (C) Sam Ravnborg <sam@mars.ravnborg.org>, 2015
|
|
|
|
# Copyright (C) Linus Torvalds <torvalds@linux-foundation.org>, 2015
|
|
|
|
#
|
|
|
|
|
|
|
|
###
|
|
|
|
# Convenient variables
|
|
|
|
comma := ,
|
|
|
|
squote := '
|
Kbuild: fix # escaping in .cmd files for future Make
I tried building using a freshly built Make (4.2.1-69-g8a731d1), but
already the objtool build broke with
orc_dump.c: In function ‘orc_dump’:
orc_dump.c:106:2: error: ‘elf_getshnum’ is deprecated [-Werror=deprecated-declarations]
if (elf_getshdrnum(elf, &nr_sections)) {
Turns out that with that new Make, the backslash was not removed, so cpp
didn't see a #include directive, grep found nothing, and
-DLIBELF_USE_DEPRECATED was wrongly put in CFLAGS.
Now, that new Make behaviour is documented in their NEWS file:
* WARNING: Backward-incompatibility!
Number signs (#) appearing inside a macro reference or function invocation
no longer introduce comments and should not be escaped with backslashes:
thus a call such as:
foo := $(shell echo '#')
is legal. Previously the number sign needed to be escaped, for example:
foo := $(shell echo '\#')
Now this latter will resolve to "\#". If you want to write makefiles
portable to both versions, assign the number sign to a variable:
C := \#
foo := $(shell echo '$C')
This was claimed to be fixed in 3.81, but wasn't, for some reason.
To detect this change search for 'nocomment' in the .FEATURES variable.
This also fixes up the two make-cmd instances to replace # with $(pound)
rather than with \#. There might very well be other places that need
similar fixup in preparation for whatever future Make release contains
the above change, but at least this builds an x86_64 defconfig with the
new make.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=197847
Cc: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-04-08 21:35:28 +00:00
|
|
|
pound := \#
|
2014-12-29 12:51:45 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
|
|
|
|
dot-target = $(dir $@).$(notdir $@)
|
|
|
|
|
|
|
|
###
|
|
|
|
# filename of target with directory and extension stripped
|
|
|
|
basetarget = $(basename $(notdir $@))
|
|
|
|
|
|
|
|
###
|
|
|
|
# The temporary file to save gcc -MD generated dependencies must not
|
|
|
|
# contain a comma
|
|
|
|
depfile = $(subst $(comma),_,$(dot-target).d)
|
|
|
|
|
|
|
|
###
|
|
|
|
# Check if both arguments has same arguments. Result is empty string if equal.
|
|
|
|
arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \
|
|
|
|
$(filter-out $(cmd_$@), $(cmd_$(1))) )
|
|
|
|
|
|
|
|
###
|
|
|
|
# Escape single quote for use in echo statements
|
|
|
|
escsq = $(subst $(squote),'\$(squote)',$1)
|
|
|
|
|
|
|
|
# Echo command
|
|
|
|
# Short version is used, if $(quiet) equals `quiet_', otherwise full one.
|
|
|
|
echo-cmd = $(if $($(quiet)cmd_$(1)),\
|
|
|
|
echo ' $(call escsq,$($(quiet)cmd_$(1)))';)
|
|
|
|
|
|
|
|
###
|
|
|
|
# Replace >$< with >$$< to preserve $ when reloading the .cmd file
|
|
|
|
# (needed for make)
|
Kbuild: fix # escaping in .cmd files for future Make
I tried building using a freshly built Make (4.2.1-69-g8a731d1), but
already the objtool build broke with
orc_dump.c: In function ‘orc_dump’:
orc_dump.c:106:2: error: ‘elf_getshnum’ is deprecated [-Werror=deprecated-declarations]
if (elf_getshdrnum(elf, &nr_sections)) {
Turns out that with that new Make, the backslash was not removed, so cpp
didn't see a #include directive, grep found nothing, and
-DLIBELF_USE_DEPRECATED was wrongly put in CFLAGS.
Now, that new Make behaviour is documented in their NEWS file:
* WARNING: Backward-incompatibility!
Number signs (#) appearing inside a macro reference or function invocation
no longer introduce comments and should not be escaped with backslashes:
thus a call such as:
foo := $(shell echo '#')
is legal. Previously the number sign needed to be escaped, for example:
foo := $(shell echo '\#')
Now this latter will resolve to "\#". If you want to write makefiles
portable to both versions, assign the number sign to a variable:
C := \#
foo := $(shell echo '$C')
This was claimed to be fixed in 3.81, but wasn't, for some reason.
To detect this change search for 'nocomment' in the .FEATURES variable.
This also fixes up the two make-cmd instances to replace # with $(pound)
rather than with \#. There might very well be other places that need
similar fixup in preparation for whatever future Make release contains
the above change, but at least this builds an x86_64 defconfig with the
new make.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=197847
Cc: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-04-08 21:35:28 +00:00
|
|
|
# Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file
|
2014-12-29 12:51:45 +00:00
|
|
|
# (needed for make)
|
|
|
|
# Replace >'< with >'\''< to be able to enclose the whole string in '...'
|
|
|
|
# (needed for the shell)
|
Kbuild: fix # escaping in .cmd files for future Make
I tried building using a freshly built Make (4.2.1-69-g8a731d1), but
already the objtool build broke with
orc_dump.c: In function ‘orc_dump’:
orc_dump.c:106:2: error: ‘elf_getshnum’ is deprecated [-Werror=deprecated-declarations]
if (elf_getshdrnum(elf, &nr_sections)) {
Turns out that with that new Make, the backslash was not removed, so cpp
didn't see a #include directive, grep found nothing, and
-DLIBELF_USE_DEPRECATED was wrongly put in CFLAGS.
Now, that new Make behaviour is documented in their NEWS file:
* WARNING: Backward-incompatibility!
Number signs (#) appearing inside a macro reference or function invocation
no longer introduce comments and should not be escaped with backslashes:
thus a call such as:
foo := $(shell echo '#')
is legal. Previously the number sign needed to be escaped, for example:
foo := $(shell echo '\#')
Now this latter will resolve to "\#". If you want to write makefiles
portable to both versions, assign the number sign to a variable:
C := \#
foo := $(shell echo '$C')
This was claimed to be fixed in 3.81, but wasn't, for some reason.
To detect this change search for 'nocomment' in the .FEATURES variable.
This also fixes up the two make-cmd instances to replace # with $(pound)
rather than with \#. There might very well be other places that need
similar fixup in preparation for whatever future Make release contains
the above change, but at least this builds an x86_64 defconfig with the
new make.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=197847
Cc: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2018-04-08 21:35:28 +00:00
|
|
|
make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))))
|
2014-12-29 12:51:45 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
# Find any prerequisites that is newer than target or that does not exist.
|
|
|
|
# PHONY targets skipped in both cases.
|
|
|
|
any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
|
|
|
|
|
2015-09-23 10:33:59 +00:00
|
|
|
###
|
|
|
|
# Copy dependency data into .cmd file
|
|
|
|
# - gcc -M dependency info
|
|
|
|
# - command line to create object 'cmd_object :='
|
2015-09-23 10:34:00 +00:00
|
|
|
dep-cmd = $(if $(wildcard $(fixdep)), \
|
|
|
|
$(fixdep) $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp; \
|
|
|
|
rm -f $(depfile); \
|
|
|
|
mv -f $(dot-target).tmp $(dot-target).cmd, \
|
2018-06-05 17:00:22 +00:00
|
|
|
printf '$(pound) cannot find fixdep (%s)\n' $(fixdep) > $(dot-target).cmd; \
|
|
|
|
printf '$(pound) using basic dep data\n\n' >> $(dot-target).cmd; \
|
2015-09-23 10:34:00 +00:00
|
|
|
cat $(depfile) >> $(dot-target).cmd; \
|
2016-12-04 20:42:52 +00:00
|
|
|
printf '\n%s\n' 'cmd_$@ := $(make-cmd)' >> $(dot-target).cmd)
|
2015-09-23 10:33:59 +00:00
|
|
|
|
2014-12-29 12:51:45 +00:00
|
|
|
###
|
|
|
|
# if_changed_dep - execute command if any prerequisite is newer than
|
|
|
|
# target, or command line has changed and update
|
|
|
|
# dependencies in the cmd file
|
|
|
|
if_changed_dep = $(if $(strip $(any-prereq) $(arg-check)), \
|
2016-12-04 20:42:53 +00:00
|
|
|
@set -e; \
|
2020-07-31 02:42:44 +00:00
|
|
|
$(echo-cmd) $(cmd_$(1)); \
|
|
|
|
$(dep-cmd))
|
2014-12-29 12:51:45 +00:00
|
|
|
|
|
|
|
# if_changed - execute command if any prerequisite is newer than
|
|
|
|
# target, or command line has changed
|
2016-12-04 20:42:53 +00:00
|
|
|
if_changed = $(if $(strip $(any-prereq) $(arg-check)), \
|
|
|
|
@set -e; \
|
|
|
|
$(echo-cmd) $(cmd_$(1)); \
|
|
|
|
printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd)
|
2014-12-29 12:51:45 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
# C flags to be used in rule definitions, includes:
|
|
|
|
# - depfile generation
|
|
|
|
# - global $(CFLAGS)
|
|
|
|
# - per target C flags
|
|
|
|
# - per object C flags
|
|
|
|
# - BUILD_STR macro to allow '-D"$(variable)"' constructs
|
2016-11-28 02:43:46 +00:00
|
|
|
c_flags_1 = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CFLAGS) -D"BUILD_STR(s)=\#s" $(CFLAGS_$(basetarget).o) $(CFLAGS_$(obj))
|
2016-11-02 13:35:47 +00:00
|
|
|
c_flags_2 = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(c_flags_1))
|
|
|
|
c_flags = $(filter-out $(CFLAGS_REMOVE_$(obj)), $(c_flags_2))
|
2016-11-28 02:43:46 +00:00
|
|
|
cxx_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(CXXFLAGS) -D"BUILD_STR(s)=\#s" $(CXXFLAGS_$(basetarget).o) $(CXXFLAGS_$(obj))
|
2016-09-27 14:18:46 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
## HOSTCC C flags
|
|
|
|
|
2018-07-10 00:45:58 +00:00
|
|
|
host_c_flags = -Wp,-MD,$(depfile) -Wp,-MT,$@ $(KBUILD_HOSTCFLAGS) -D"BUILD_STR(s)=\#s" $(HOSTCFLAGS_$(basetarget).o) $(HOSTCFLAGS_$(obj))
|
2021-04-16 13:00:51 +00:00
|
|
|
|
|
|
|
# output directory for tests below
|
|
|
|
TMPOUT = .tmp_$$$$
|
|
|
|
|
|
|
|
# try-run
|
|
|
|
# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
|
|
|
|
# Exit code chooses option. "$$TMP" serves as a temporary file and is
|
|
|
|
# automatically cleaned up.
|
|
|
|
try-run = $(shell set -e; \
|
|
|
|
TMP=$(TMPOUT)/tmp; \
|
|
|
|
mkdir -p $(TMPOUT); \
|
|
|
|
trap "rm -rf $(TMPOUT)" EXIT; \
|
|
|
|
if ($(1)) >/dev/null 2>&1; \
|
|
|
|
then echo "$(2)"; \
|
|
|
|
else echo "$(3)"; \
|
|
|
|
fi)
|
|
|
|
|
|
|
|
# cc-option
|
|
|
|
# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
|
|
|
|
cc-option = $(call try-run, \
|
|
|
|
$(CC) -Werror $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
|
|
|
|
|
|
|
|
# delete partially updated (i.e. corrupted) files on error
|
|
|
|
.DELETE_ON_ERROR:
|