aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/Kbuild.include
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/Kbuild.include')
-rw-r--r--scripts/Kbuild.include65
1 files changed, 52 insertions, 13 deletions
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 0168d6c37075..59620b1554e0 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -44,6 +44,43 @@ define filechk
44 fi 44 fi
45endef 45endef
46 46
47######
48# gcc support functions
49# See documentation in Documentation/kbuild/makefiles.txt
50
51# as-option
52# Usage: cflags-y += $(call as-option, -Wa$(comma)-isa=foo,)
53
54as-option = $(shell if $(CC) $(CFLAGS) $(1) -Wa,-Z -c -o /dev/null \
55 -xassembler /dev/null > /dev/null 2>&1; then echo "$(1)"; \
56 else echo "$(2)"; fi ;)
57
58# cc-option
59# Usage: cflags-y += $(call cc-option, -march=winchip-c6, -march=i586)
60
61cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
62 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
63
64# cc-option-yn
65# Usage: flag := $(call cc-option-yn, -march=winchip-c6)
66cc-option-yn = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
67 > /dev/null 2>&1; then echo "y"; else echo "n"; fi;)
68
69# cc-option-align
70# Prefix align with either -falign or -malign
71cc-option-align = $(subst -functions=0,,\
72 $(call cc-option,-falign-functions=0,-malign-functions=0))
73
74# cc-version
75# Usage gcc-ver := $(call cc-version, $(CC))
76cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh \
77 $(if $(1), $(1), $(CC)))
78
79# cc-ifversion
80# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
81cc-ifversion = $(shell if [ $(call cc-version, $(CC)) $(1) $(2) ]; then \
82 echo $(3); fi;)
83
47### 84###
48# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= 85# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
49# Usage: 86# Usage:
@@ -51,8 +88,7 @@ endef
51build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj 88build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
52 89
53# If quiet is set, only print short version of command 90# If quiet is set, only print short version of command
54cmd = @$(if $($(quiet)cmd_$(1)),\ 91cmd = @$(echo-cmd) $(cmd_$(1))
55 echo ' $(call escsq,$($(quiet)cmd_$(1)))' &&) $(cmd_$(1))
56 92
57# Add $(obj)/ for paths that is not absolute 93# Add $(obj)/ for paths that is not absolute
58objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o))) 94objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
@@ -75,30 +111,33 @@ endif
75echo-cmd = $(if $($(quiet)cmd_$(1)), \ 111echo-cmd = $(if $($(quiet)cmd_$(1)), \
76 echo ' $(call escsq,$($(quiet)cmd_$(1)))';) 112 echo ' $(call escsq,$($(quiet)cmd_$(1)))';)
77 113
114make-cmd = $(subst \#,\\\#,$(subst $$,$$$$,$(call escsq,$(cmd_$(1)))))
115
78# function to only execute the passed command if necessary 116# function to only execute the passed command if necessary
79# >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file 117# >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file
80# note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars 118# note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars
81# 119#
82if_changed = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ 120if_changed = $(if $(strip $(filter-out $(PHONY),$?) \
121 $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \
83 @set -e; \ 122 @set -e; \
84 $(echo-cmd) \ 123 $(echo-cmd) $(cmd_$(1)); \
85 $(cmd_$(1)); \ 124 echo 'cmd_$@ := $(make-cmd)' > $(@D)/.$(@F).cmd)
86 echo 'cmd_$@ := $(subst $$,$$$$,$(call escsq,$(cmd_$(1))))' > $(@D)/.$(@F).cmd)
87 125
88# execute the command and also postprocess generated .d dependencies 126# execute the command and also postprocess generated .d dependencies
89# file 127# file
90if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\ 128if_changed_dep = $(if $(strip $(filter-out $(PHONY),$?) \
91 $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ 129 $(filter-out FORCE $(wildcard $^),$^) \
130 $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \
92 @set -e; \ 131 @set -e; \
93 $(echo-cmd) \ 132 $(echo-cmd) $(cmd_$(1)); \
94 $(cmd_$(1)); \ 133 scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(@D)/.$(@F).tmp; \
95 scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(call escsq,$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
96 rm -f $(depfile); \ 134 rm -f $(depfile); \
97 mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd) 135 mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)
98 136
99# Usage: $(call if_changed_rule,foo) 137# Usage: $(call if_changed_rule,foo)
100# will check if $(cmd_foo) changed, or any of the prequisites changed, 138# will check if $(cmd_foo) changed, or any of the prequisites changed,
101# and if so will execute $(rule_foo) 139# and if so will execute $(rule_foo)
102if_changed_rule = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\ 140if_changed_rule = $(if $(strip $(filter-out $(PHONY),$?) \
141 $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\
103 @set -e; \ 142 @set -e; \
104 $(rule_$(1))) 143 $(rule_$(1)))