mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 21:38:32 +08:00
4d0831e8a0
cc-option and as-option are almost the same; both pass the flag to
$(CC). The main difference is the cc-option stops before the assemble
stage (-S option) whereas as-option stops after (-c option).
I chose -S because it is slightly faster, but $(cc-option,-gz=zlib)
returns a wrong result (https://lkml.org/lkml/2020/6/9/1529).
It has been fixed by commit 7b16994437
("Makefile: Improve compressed
debug info support detection"), but the assembler should always be
invoked for more reliable compiler option tests.
However, you cannot simply replace -S with -c because the following
code in lib/Kconfig.debug would break:
depends on $(cc-option,-gsplit-dwarf)
The combination of -c and -gsplit-dwarf does not accept /dev/null as
output.
$ cat /dev/null | gcc -gsplit-dwarf -S -x c - -o /dev/null
$ echo $?
0
$ cat /dev/null | gcc -gsplit-dwarf -c -x c - -o /dev/null
objcopy: Warning: '/dev/null' is not an ordinary file
$ echo $?
1
$ cat /dev/null | gcc -gsplit-dwarf -c -x c - -o tmp.o
$ echo $?
0
There is another flag that creates an separate file based on the
object file path:
$ cat /dev/null | gcc -ftest-coverage -c -x c - -o /dev/null
<stdin>:1: error: cannot open /dev/null.gcno
So, we cannot use /dev/null to sink the output.
Align the cc-option implementation with scripts/Kbuild.include.
With -c option used in cc-option, as-option is unneeded.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Acked-by: Will Deacon <will@kernel.org>
51 lines
1.8 KiB
Plaintext
51 lines
1.8 KiB
Plaintext
# SPDX-License-Identifier: GPL-2.0-only
|
|
# Kconfig helper macros
|
|
|
|
# Convenient variables
|
|
comma := ,
|
|
quote := "
|
|
squote := '
|
|
empty :=
|
|
space := $(empty) $(empty)
|
|
dollar := $
|
|
right_paren := )
|
|
left_paren := (
|
|
|
|
# $(if-success,<command>,<then>,<else>)
|
|
# Return <then> if <command> exits with 0, <else> otherwise.
|
|
if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)")
|
|
|
|
# $(success,<command>)
|
|
# Return y if <command> exits with 0, n otherwise
|
|
success = $(if-success,$(1),y,n)
|
|
|
|
# $(failure,<command>)
|
|
# Return n if <command> exits with 0, y otherwise
|
|
failure = $(if-success,$(1),n,y)
|
|
|
|
# $(cc-option,<flag>)
|
|
# Return y if the compiler supports <flag>, n otherwise
|
|
cc-option = $(success,mkdir .tmp_$$$$; trap "rm -rf .tmp_$$$$" EXIT; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$$$/tmp.o)
|
|
|
|
# $(ld-option,<flag>)
|
|
# Return y if the linker supports <flag>, n otherwise
|
|
ld-option = $(success,$(LD) -v $(1))
|
|
|
|
# $(as-instr,<instr>)
|
|
# Return y if the assembler supports <instr>, n otherwise
|
|
as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -)
|
|
|
|
# check if $(CC) and $(LD) exist
|
|
$(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found)
|
|
$(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
|
|
|
|
# Fail if the linker is gold as it's not capable of linking the kernel proper
|
|
$(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supported)
|
|
|
|
# machine bit flags
|
|
# $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
|
|
# $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
|
|
cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
|
|
m32-flag := $(cc-option-bit,-m32)
|
|
m64-flag := $(cc-option-bit,-m64)
|