Skip to content

Commit bca7b25

Browse files
masahir0yflakeforever
authored andcommitted
UPSTREAM: kbuild: split cc-option and friends to scripts/Makefile.compiler
scripts/Kbuild.include is included everywhere, but macros such as cc-option are needed by build targets only. For example, when 'make clean' traverses the tree, it does not need to evaluate $(call cc-option,). Split cc-option, ld-option, etc. to scripts/Makefile.compiler, which is only included from the top Makefile and scripts/Makefile.build. Signed-off-by: Masahiro Yamada <[email protected]> Bug: 209655537 (cherry picked from commit 57fd251c789647552d32d2fc51bedd4f90d70f9f) Signed-off-by: Nick Desaulniers <[email protected]> Change-Id: I7cef781922a192a9bcd21152a74ff2cec0527ab0
1 parent 9e821c6 commit bca7b25

File tree

4 files changed

+80
-84
lines changed

4 files changed

+80
-84
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,10 @@ ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
606606
include $(srctree)/scripts/Makefile.clang
607607
endif
608608

609+
# Include this also for config targets because some architectures need
610+
# cc-cross-prefix to determine CROSS_COMPILE.
611+
include $(srctree)/scripts/Makefile.compiler
612+
609613
ifdef config-build
610614
# ===========================================================================
611615
# *config targets only - make sure prerequisites are updated, and descend

scripts/Kbuild.include

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -67,90 +67,6 @@ define filechk
6767
fi
6868
endef
6969

70-
######
71-
# gcc support functions
72-
# See documentation in Documentation/kbuild/makefiles.rst
73-
74-
# cc-cross-prefix
75-
# Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-)
76-
# Return first <prefix> where a <prefix>gcc is found in PATH.
77-
# If no gcc found in PATH with listed prefixes return nothing
78-
#
79-
# Note: '2>/dev/null' is here to force Make to invoke a shell. Otherwise, it
80-
# would try to directly execute the shell builtin 'command'. This workaround
81-
# should be kept for a long time since this issue was fixed only after the
82-
# GNU Make 4.2.1 release.
83-
cc-cross-prefix = $(firstword $(foreach c, $(1), \
84-
$(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c))))
85-
86-
# output directory for tests below
87-
TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$
88-
89-
# try-run
90-
# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
91-
# Exit code chooses option. "$$TMP" serves as a temporary file and is
92-
# automatically cleaned up.
93-
try-run = $(shell set -e; \
94-
TMP=$(TMPOUT)/tmp; \
95-
TMPO=$(TMPOUT)/tmp.o; \
96-
mkdir -p $(TMPOUT); \
97-
trap "rm -rf $(TMPOUT)" EXIT; \
98-
if ($(1)) >/dev/null 2>&1; \
99-
then echo "$(2)"; \
100-
else echo "$(3)"; \
101-
fi)
102-
103-
# as-option
104-
# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
105-
106-
as-option = $(call try-run,\
107-
$(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
108-
109-
# as-instr
110-
# Usage: cflags-y += $(call as-instr,instr,option1,option2)
111-
112-
as-instr = $(call try-run,\
113-
printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
114-
115-
# __cc-option
116-
# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
117-
__cc-option = $(call try-run,\
118-
$(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4))
119-
120-
# cc-option
121-
# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
122-
123-
cc-option = $(call __cc-option, $(CC),\
124-
$(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS),$(1),$(2))
125-
126-
# cc-option-yn
127-
# Usage: flag := $(call cc-option-yn,-march=winchip-c6)
128-
cc-option-yn = $(call try-run,\
129-
$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
130-
131-
# cc-disable-warning
132-
# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
133-
cc-disable-warning = $(call try-run,\
134-
$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
135-
136-
# cc-ifversion
137-
# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
138-
cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4))
139-
140-
# ld-option
141-
# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
142-
ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))
143-
144-
# ld-version
145-
# Note this is mainly for HJ Lu's 3 number binutil versions
146-
ld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh)
147-
148-
# ld-ifversion
149-
# Usage: $(call ld-ifversion, -ge, 22252, y)
150-
ld-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4))
151-
152-
######
153-
15470
###
15571
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
15672
# Usage:

scripts/Makefile.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ subdir-ccflags-y :=
3737
-include include/config/auto.conf
3838

3939
include scripts/Kbuild.include
40+
include scripts/Makefile.compiler
4041

4142
# The filename Kbuild has precedence over Makefile
4243
kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))

scripts/Makefile.compiler

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
3+
# cc-cross-prefix
4+
# Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-)
5+
# Return first <prefix> where a <prefix>gcc is found in PATH.
6+
# If no gcc found in PATH with listed prefixes return nothing
7+
#
8+
# Note: '2>/dev/null' is here to force Make to invoke a shell. Otherwise, it
9+
# would try to directly execute the shell builtin 'command'. This workaround
10+
# should be kept for a long time since this issue was fixed only after the
11+
# GNU Make 4.2.1 release.
12+
cc-cross-prefix = $(firstword $(foreach c, $(1), \
13+
$(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c))))
14+
15+
# output directory for tests below
16+
TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$
17+
18+
# try-run
19+
# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
20+
# Exit code chooses option. "$$TMP" serves as a temporary file and is
21+
# automatically cleaned up.
22+
try-run = $(shell set -e; \
23+
TMP=$(TMPOUT)/tmp; \
24+
TMPO=$(TMPOUT)/tmp.o; \
25+
mkdir -p $(TMPOUT); \
26+
trap "rm -rf $(TMPOUT)" EXIT; \
27+
if ($(1)) >/dev/null 2>&1; \
28+
then echo "$(2)"; \
29+
else echo "$(3)"; \
30+
fi)
31+
32+
# as-option
33+
# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
34+
35+
as-option = $(call try-run,\
36+
$(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
37+
38+
# as-instr
39+
# Usage: cflags-y += $(call as-instr,instr,option1,option2)
40+
41+
as-instr = $(call try-run,\
42+
printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
43+
44+
# __cc-option
45+
# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
46+
__cc-option = $(call try-run,\
47+
$(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4))
48+
49+
# cc-option
50+
# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)
51+
52+
cc-option = $(call __cc-option, $(CC),\
53+
$(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS),$(1),$(2))
54+
55+
# cc-option-yn
56+
# Usage: flag := $(call cc-option-yn,-march=winchip-c6)
57+
cc-option-yn = $(call try-run,\
58+
$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
59+
60+
# cc-disable-warning
61+
# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
62+
cc-disable-warning = $(call try-run,\
63+
$(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
64+
65+
# cc-ifversion
66+
# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
67+
cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4))
68+
69+
# ld-option
70+
# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
71+
ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))
72+
73+
# ld-ifversion
74+
# Usage: $(call ld-ifversion, -ge, 22252, y)
75+
ld-ifversion = $(shell [ $(CONFIG_LD_VERSION)0 $(1) $(2)0 ] && echo $(3) || echo $(4))

0 commit comments

Comments
 (0)