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
Unified · Split
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | #### |
| 2 | 2 | # kbuild: Generic definitions |
| 3 | 3 | |
| 4 | −# Convenient constants | |
| 4 | +# Convenient variables | |
| 5 | 5 | comma := , |
| 6 | 6 | squote := ' |
| 7 | 7 | empty := |
| @@ -56,44 +56,48 @@ endef · 48 unmodified lines | ||
| 56 | 56 | # gcc support functions |
| 57 | 57 | # See documentation in Documentation/kbuild/makefiles.txt |
| 58 | 58 | |
| 59 | −# checker-shell | |
| 60 | −# Usage: option = $(call checker-shell,$(CC)...-o $$OUT,option-ok,otherwise) | |
| 61 | −# Exit code chooses option. $$OUT is safe location for needless output. | |
| 62 | −define checker-shell | |
| 63 | −$(shell set -e; \ | |
| 64 | − DIR=$(KBUILD_EXTMOD); \ | |
| 65 | − cd $${DIR:-$(objtree)}; \ | |
| 66 | − OUT=$$PWD/.$$$$.null; \ | |
| 67 | − if $(1) >/dev/null 2>&1; \ | |
| 68 | − then echo "$(2)"; \ | |
| 69 | − else echo "$(3)"; \ | |
| 70 | − fi; \ | |
| 71 | − rm -f $$OUT) | |
| 72 | −endef | |
| 59 | +# output directory for tests below | |
| 60 | +TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/) | |
| 61 | + | |
| 62 | +# try-run | |
| 63 | +# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) | |
| 64 | +# Exit code chooses option. "$$TMP" is can be used as temporary file and | |
| 65 | +# is automatically cleaned up. | |
| 66 | +try-run = $(shell set -e; \ | |
| 67 | + TMP="$(TMPOUT).$$$$.tmp"; \ | |
| 68 | + if ($(1)) >/dev/null 2>&1; \ | |
| 69 | + then echo "$(2)"; \ | |
| 70 | + else echo "$(3)"; \ | |
| 71 | + fi; \ | |
| 72 | + rm -f "$$TMP") | |
| 73 | 73 | |
| 74 | 74 | # as-option |
| 75 | 75 | # Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) |
| 76 | −as-option = $(call checker-shell,\ | |
| 77 | − $(CC) $(CFLAGS) $(1) -c -xassembler /dev/null -o $$OUT,$(1),$(2)) | |
| 76 | + | |
| 77 | +as-option = $(call try-run,\ | |
| 78 | + $(CC) $(CFLAGS) $(1) -c -xassembler /dev/null -o "$$TMP",$(1),$(2)) | |
| 78 | 79 | |
| 79 | 80 | # as-instr |
| 80 | 81 | # Usage: cflags-y += $(call as-instr,instr,option1,option2) |
| 81 | −as-instr = $(call checker-shell,\ | |
| 82 | − printf "$(1)" | $(CC) $(AFLAGS) -c -xassembler -o $$OUT -,$(2),$(3)) | |
| 82 | + | |
| 83 | +as-instr = $(call try-run,\ | |
| 84 | + echo -e "$(1)" | $(CC) $(AFLAGS) -c -xassembler -o "$$TMP" -,$(2),$(3)) | |
| 83 | 85 | |
| 84 | 86 | # cc-option |
| 85 | 87 | # Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) |
| 86 | −cc-option = $(call checker-shell,\ | |
| 87 | − $(CC) $(CFLAGS) $(if $(3),$(3),$(1)) -S -xc /dev/null -o $$OUT,$(1),$(2)) | |
| 88 | + | |
| 89 | +cc-option = $(call try-run,\ | |
| 90 | + $(CC) $(CFLAGS) $(1) -S -xc /dev/null -o "$$TMP",$(1),$(2)) | |
| 88 | 91 | |
| 89 | 92 | # cc-option-yn |
| 90 | 93 | # Usage: flag := $(call cc-option-yn,-march=winchip-c6) |
| 91 | −cc-option-yn = $(call cc-option,"y","n",$(1)) | |
| 94 | +cc-option-yn = $(call try-run,\ | |
| 95 | + $(CC) $(CFLAGS) $(1) -S -xc /dev/null -o "$$TMP",y,n) | |
| 92 | 96 | |
| 93 | 97 | # cc-option-align |
| 94 | 98 | # Prefix align with either -falign or -malign |
| 95 | 99 | cc-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 | 102 | # cc-version |
| 99 | 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 | 110 | # ld-option |
| 107 | 111 | # Usage: ldflags += $(call ld-option, -Wl$(comma)--hash-style=both) |
| 108 | −ld-option = $(call checker-shell,\ | |
| 109 | − $(CC) $(1) -nostdlib -xc /dev/null -o $$OUT,$(1),$(2)) | |
| 112 | +ld-option = $(call try-run,\ | |
| 113 | + $(CC) $(1) -nostdlib -xc /dev/null -o "$$TMP",$(1),$(2)) | |
| 110 | 114 | |
| 111 | 115 | ###### |
| 112 | 116 | |
| 117 | +### | |
| 113 | 118 | # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= |
| 114 | 119 | # Usage: |
| 115 | 120 | # $(Q)$(MAKE) $(build)=dir |
| 116 | 121 | build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj |
| 117 | 122 | |
| 118 | −# Prefix -I with $(srctree) if it is not an absolute path, | |
| 119 | −# add original to the end | |
| 120 | −addtree = $(if \ | |
| 121 | − $(filter-out -I/%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1))) $(1) | |
| 123 | +# Prefix -I with $(srctree) if it is not an absolute path. | |
| 124 | +addtree = $(if $(filter-out -I/%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1))) $(1) | |
| 122 | 125 | |
| 123 | 126 | # Find all -I options and call addtree |
| 124 | −flags = $(foreach o,$($(1)),\ | |
| 125 | − $(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o))) | |
| 127 | +flags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o))) | |
| 126 | 128 | |
| 127 | 129 | # echo command. |
| 128 | 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 | 146 | # See Documentation/kbuild/makefiles.txt for more info |
| 145 | 147 | |
| 146 | 148 | ifneq ($(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 | 150 | # User may override this check using make KBUILD_NOCMDDEP=1 |
| 149 | 151 | arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \ |
| 150 | 152 | $(filter-out $(cmd_$@), $(cmd_$(1))) ) |
| @@ -168,7 +170,6 @@ if_changed = $(if $(strip $(any-prereq) $(arg-check)), \ · 17 unmodified lines | ||
| 168 | 170 | echo 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd) |
| 169 | 171 | |
| 170 | 172 | # Execute the command and also postprocess generated .d dependencies file. |
| 171 | −# | |
| 172 | 173 | if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \ |
| 173 | 174 | @set -e; \ |
| 174 | 175 | $(echo-cmd) $(cmd_$(1)); \ |
| @@ -176,10 +177,9 @@ if_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \ · 1 unmodified line | ||
| 176 | 177 | rm -f $(depfile); \ |
| 177 | 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 | 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). | |
| 183 | 183 | if_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ), \ |
| 184 | 184 | @set -e; \ |
| 185 | 185 | $(rule_$(1))) |