aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scripts/Kbuild.include72
1 files changed, 36 insertions, 36 deletions
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index a1880e854dce..06c1a377c4c5 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -1,7 +1,7 @@
1#### 1####
2# kbuild: Generic definitions 2# kbuild: Generic definitions
3 3
4# Convenient constants 4# Convenient variables
5comma := , 5comma := ,
6squote := ' 6squote := '
7empty := 7empty :=
@@ -56,44 +56,48 @@ endef
56# gcc support functions 56# gcc support functions
57# See documentation in Documentation/kbuild/makefiles.txt 57# See documentation in Documentation/kbuild/makefiles.txt
58 58
59# checker-shell 59# output directory for tests below
60# Usage: option = $(call checker-shell,$(CC)...-o $$OUT,option-ok,otherwise) 60TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/)
61# Exit code chooses option. $$OUT is safe location for needless output. 61
62define checker-shell 62# try-run
63$(shell set -e; \ 63# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
64 DIR=$(KBUILD_EXTMOD); \ 64# Exit code chooses option. "$$TMP" is can be used as temporary file and
65 cd $${DIR:-$(objtree)}; \ 65# is automatically cleaned up.
66 OUT=$$PWD/.$$$$.null; \ 66try-run = $(shell set -e; \
67 if $(1) >/dev/null 2>&1; \ 67 TMP="$(TMPOUT).$$$$.tmp"; \
68 then echo "$(2)"; \ 68 if ($(1)) >/dev/null 2>&1; \
69 else echo "$(3)"; \ 69 then echo "$(2)"; \
70 fi; \ 70 else echo "$(3)"; \
71 rm -f $$OUT) 71 fi; \
72endef 72 rm -f "$$TMP")
73 73
74# as-option 74# as-option
75# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) 75# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
76as-option = $(call checker-shell,\ 76
77 $(CC) $(CFLAGS) $(1) -c -xassembler /dev/null -o $$OUT,$(1),$(2)) 77as-option = $(call try-run,\
78 $(CC) $(CFLAGS) $(1) -c -xassembler /dev/null -o "$$TMP",$(1),$(2))
78 79
79# as-instr 80# as-instr
80# Usage: cflags-y += $(call as-instr,instr,option1,option2) 81# Usage: cflags-y += $(call as-instr,instr,option1,option2)
81as-instr = $(call checker-shell,\ 82
82 printf "$(1)" | $(CC) $(AFLAGS) -c -xassembler -o $$OUT -,$(2),$(3)) 83as-instr = $(call try-run,\
84 echo -e "$(1)" | $(CC) $(AFLAGS) -c -xassembler -o "$$TMP" -,$(2),$(3))
83 85
84# cc-option 86# cc-option
85# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) 87# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
86cc-option = $(call checker-shell,\ 88
87 $(CC) $(CFLAGS) $(if $(3),$(3),$(1)) -S -xc /dev/null -o $$OUT,$(1),$(2)) 89cc-option = $(call try-run,\
90 $(CC) $(CFLAGS) $(1) -S -xc /dev/null -o "$$TMP",$(1),$(2))
88 91
89# cc-option-yn 92# cc-option-yn
90# Usage: flag := $(call cc-option-yn,-march=winchip-c6) 93# Usage: flag := $(call cc-option-yn,-march=winchip-c6)
91cc-option-yn = $(call cc-option,"y","n",$(1)) 94cc-option-yn = $(call try-run,\
95 $(CC) $(CFLAGS) $(1) -S -xc /dev/null -o "$$TMP",y,n)
92 96
93# cc-option-align 97# cc-option-align
94# Prefix align with either -falign or -malign 98# Prefix align with either -falign or -malign
95cc-option-align = $(subst -functions=0,,\ 99cc-option-align = $(subst -functions=0,,\
96 $(call cc-option,-falign-functions=0,-malign-functions=0)) 100 $(call cc-option,-falign-functions=0,-malign-functions=0))
97 101
98# cc-version 102# cc-version
99# Usage gcc-ver := $(call cc-version,$(CC)) 103# Usage gcc-ver := $(call cc-version,$(CC))
@@ -105,24 +109,22 @@ cc-ifversion = $(shell [ $(call cc-version, $(CC)) $(1) $(2) ] && echo $(3))
105 109
106# ld-option 110# ld-option
107# Usage: ldflags += $(call ld-option, -Wl$(comma)--hash-style=both) 111# Usage: ldflags += $(call ld-option, -Wl$(comma)--hash-style=both)
108ld-option = $(call checker-shell,\ 112ld-option = $(call try-run,\
109 $(CC) $(1) -nostdlib -xc /dev/null -o $$OUT,$(1),$(2)) 113 $(CC) $(1) -nostdlib -xc /dev/null -o "$$TMP",$(1),$(2))
110 114
111###### 115######
112 116
117###
113# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= 118# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
114# Usage: 119# Usage:
115# $(Q)$(MAKE) $(build)=dir 120# $(Q)$(MAKE) $(build)=dir
116build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj 121build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
117 122
118# Prefix -I with $(srctree) if it is not an absolute path, 123# Prefix -I with $(srctree) if it is not an absolute path.
119# add original to the end 124addtree = $(if $(filter-out -I/%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1))) $(1)
120addtree = $(if \
121 $(filter-out -I/%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1))) $(1)
122 125
123# Find all -I options and call addtree 126# Find all -I options and call addtree
124flags = $(foreach o,$($(1)),\ 127flags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o)))
125 $(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o)))
126 128
127# echo command. 129# echo command.
128# Short version is used, if $(quiet) equals `quiet_', otherwise full one. 130# Short version is used, if $(quiet) equals `quiet_', otherwise full one.
@@ -144,7 +146,7 @@ objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
144# See Documentation/kbuild/makefiles.txt for more info 146# See Documentation/kbuild/makefiles.txt for more info
145 147
146ifneq ($(KBUILD_NOCMDDEP),1) 148ifneq ($(KBUILD_NOCMDDEP),1)
147# Check if both arguments has same arguments. Result is empty string, if equal. 149# Check if both arguments has same arguments. Result is empty string if equal.
148# User may override this check using make KBUILD_NOCMDDEP=1 150# User may override this check using make KBUILD_NOCMDDEP=1
149arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \ 151arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \
150 $(filter-out $(cmd_$@), $(cmd_$(1))) ) 152 $(filter-out $(cmd_$@), $(cmd_$(1))) )
@@ -168,7 +170,6 @@ if_changed = $(if $(strip $(any-prereq) $(arg-check)), \
168 echo 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd) 170 echo 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd)
169 171
170# Execute the command and also postprocess generated .d dependencies file. 172# Execute the command and also postprocess generated .d dependencies file.
171#
172if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \ 173if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \
173 @set -e; \ 174 @set -e; \
174 $(echo-cmd) $(cmd_$(1)); \ 175 $(echo-cmd) $(cmd_$(1)); \
@@ -176,10 +177,9 @@ if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \
176 rm -f $(depfile); \ 177 rm -f $(depfile); \
177 mv -f $(dot-target).tmp $(dot-target).cmd) 178 mv -f $(dot-target).tmp $(dot-target).cmd)
178 179
179# Will check if $(cmd_foo) changed, or any of the prerequisites changed,
180# and if so will execute $(rule_foo).
181# Usage: $(call if_changed_rule,foo) 180# Usage: $(call if_changed_rule,foo)
182# 181# Will check if $(cmd_foo) or any of the prerequisites changed,
182# and if so will execute $(rule_foo).
183if_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ), \ 183if_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ), \
184 @set -e; \ 184 @set -e; \
185 $(rule_$(1))) 185 $(rule_$(1)))