History

[PATCH] kbuild: more Makefile cleanups

This adds the remaining changes which should have been part of the review process. - the define command is inappropriate (it's primarily for rule definitions) - execute commands in the current dir as all other commands - .*.tmp (but not .*.null) files are also removed up by "make clean" - printf has other side effects, just use "echo -e" - proper quoting - proper indentation

Roman Zippel committed 19 years ago

Commit beda9f31 parent 2fd592e1 file · +36 −36Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/Kbuild.include+36−36
@@ -1,7 +1,7 @@
1####1####
2# kbuild: Generic definitions2# kbuild: Generic definitions
3 3
4# Convenient constants4# Convenient variables
5comma := ,5comma := ,
6squote := '6squote := '
7empty :=7empty :=
@@ -56,44 +56,48 @@ endef · 48 unmodified lines
56# gcc support functions56# gcc support functions
57# See documentation in Documentation/kbuild/makefiles.txt57# See documentation in Documentation/kbuild/makefiles.txt
58 58
59# checker-shell59# 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-shell62# 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; \
72endef72 rm -f "$$TMP")
73 73
74# as-option74# 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-instr80# 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-option86# 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-yn92# 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-align97# cc-option-align
94# Prefix align with either -falign or -malign98# 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-version102# 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)) · 5 unmodified lines
105 109
106# ld-option110# 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)=dir120# $(Q)$(MAKE) $(build)=dir
116build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj121build := -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 end124addtree = $(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 addtree126# 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))) · 15 unmodified lines
144# See Documentation/kbuild/makefiles.txt for more info146# 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=1150# 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)), \ · 17 unmodified lines
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) ), \ · 1 unmodified line
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)))