hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/scripts/Kconfig.include
....@@ -1,3 +1,4 @@
1
+# SPDX-License-Identifier: GPL-2.0-only
12 # Kconfig helper macros
23
34 # Convenient variables
....@@ -18,13 +19,38 @@
1819 # Return y if <command> exits with 0, n otherwise
1920 success = $(if-success,$(1),y,n)
2021
22
+# $(failure,<command>)
23
+# Return n if <command> exits with 0, y otherwise
24
+failure = $(if-success,$(1),n,y)
25
+
2126 # $(cc-option,<flag>)
2227 # Return y if the compiler supports <flag>, n otherwise
23
-cc-option = $(success,$(CC) -Werror $(CLANG_FLAGS) $(1) -S -x c /dev/null -o /dev/null)
28
+cc-option = $(success,mkdir .tmp_$$$$; trap "rm -rf .tmp_$$$$" EXIT; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$$$/tmp.o)
2429
2530 # $(ld-option,<flag>)
2631 # Return y if the linker supports <flag>, n otherwise
2732 ld-option = $(success,$(LD) -v $(1))
2833
29
-# gcc version including patch level
30
-gcc-version := $(shell,$(srctree)/scripts/gcc-version.sh -p $(CC) | sed 's/^0*//')
34
+# $(as-instr,<instr>)
35
+# Return y if the assembler supports <instr>, n otherwise
36
+as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -c -x assembler -o /dev/null -)
37
+
38
+# check if $(CC) and $(LD) exist
39
+$(error-if,$(failure,command -v $(CC)),compiler '$(CC)' not found)
40
+$(error-if,$(failure,command -v $(LD)),linker '$(LD)' not found)
41
+
42
+# Fail if the linker is gold as it's not capable of linking the kernel proper
43
+$(error-if,$(success, $(LD) -v | grep -q gold), gold linker '$(LD)' not supported)
44
+
45
+# Get the assembler name, version, and error out if it is not supported.
46
+as-info := $(shell,$(srctree)/scripts/as-version.sh $(CC) $(CLANG_FLAGS))
47
+$(error-if,$(success,test -z "$(as-info)"),Sorry$(comma) this assembler is not supported.)
48
+as-name := $(shell,set -- $(as-info) && echo $1)
49
+as-version := $(shell,set -- $(as-info) && echo $2)
50
+
51
+# machine bit flags
52
+# $(m32-flag): -m32 if the compiler supports it, or an empty string otherwise.
53
+# $(m64-flag): -m64 if the compiler supports it, or an empty string otherwise.
54
+cc-option-bit = $(if-success,$(CC) -Werror $(1) -E -x c /dev/null -o /dev/null,$(1))
55
+m32-flag := $(cc-option-bit,-m32)
56
+m64-flag := $(cc-option-bit,-m64)