^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #!/bin/sh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) # Staring v4.18, Kconfig evaluates compiler capabilities, and hides CONFIG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) # options your compiler does not support. This works well if you configure and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) # build the kernel on the same host machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) # It is inconvenient if you prepare the .config that is carried to a different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) # build environment (typically this happens when you package the kernel for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) # distros) because using a different compiler potentially produces different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) # CONFIG options than the real build environment. So, you probably want to make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) # as many options visible as possible. In other words, you need to create a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) # super-set of CONFIG options that cover any build environment. If some of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) # CONFIG options turned out to be unsupported on the build machine, they are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) # automatically disabled by the nature of Kconfig.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) # However, it is not feasible to get a full-featured compiler for every arch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) # Hence these dummy toolchains to make all compiler tests pass.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) # Usage:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) # From the top directory of the source tree, run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) # $ make CROSS_COMPILE=scripts/dummy-tools/ oldconfig
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) # Most of compiler features are tested by cc-option, which simply checks the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) # exit code of $(CC). This script does nothing and just exits with 0 in most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) # cases. So, $(cc-option, ...) is evaluated as 'y'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) # This scripts caters to more checks; handle --version and pre-process __GNUC__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) # etc. to pretend to be GCC, and also do right things to satisfy some scripts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) # Check if the first parameter appears in the rest. Succeeds if found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) # This helper is useful if a particular option was passed to this script.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) # Typically used like this:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) # arg_contain <word-you-are-searching-for> "$@"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) arg_contain ()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) search="$1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) while [ $# -gt 0 ]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if [ "$search" = "$1" ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) # To set CONFIG_CC_IS_GCC=y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if arg_contain --version "$@"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) echo "gcc (scripts/dummy-tools/gcc)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) exit 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if arg_contain -E "$@"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) # For scripts/gcc-version.sh; This emulates GCC 20.0.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if arg_contain - "$@"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) sed 's/^__GNUC__$/20/; s/^__GNUC_MINOR__$/0/; s/^__GNUC_PATCHLEVEL__$/0/'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) exit 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) echo "no input files" >&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if arg_contain -S "$@"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) # For scripts/gcc-x86-*-has-stack-protector.sh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if arg_contain -fstack-protector "$@"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) echo "%gs"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) exit 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) # To set GCC_PLUGINS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if arg_contain -print-file-name=plugin "$@"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) plugin_dir=$(mktemp -d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) mkdir -p $plugin_dir/include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) touch $plugin_dir/include/plugin-version.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) echo $plugin_dir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) exit 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) # inverted return value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if arg_contain -D__SIZEOF_INT128__=0 "$@"; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) fi