Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0-only
0003 #
0004 # Staring v4.18, Kconfig evaluates compiler capabilities, and hides CONFIG
0005 # options your compiler does not support. This works well if you configure and
0006 # build the kernel on the same host machine.
0007 #
0008 # It is inconvenient if you prepare the .config that is carried to a different
0009 # build environment (typically this happens when you package the kernel for
0010 # distros) because using a different compiler potentially produces different
0011 # CONFIG options than the real build environment. So, you probably want to make
0012 # as many options visible as possible. In other words, you need to create a
0013 # super-set of CONFIG options that cover any build environment. If some of the
0014 # CONFIG options turned out to be unsupported on the build machine, they are
0015 # automatically disabled by the nature of Kconfig.
0016 #
0017 # However, it is not feasible to get a full-featured compiler for every arch.
0018 # Hence these dummy toolchains to make all compiler tests pass.
0019 #
0020 # Usage:
0021 #
0022 # From the top directory of the source tree, run
0023 #
0024 #   $ make CROSS_COMPILE=scripts/dummy-tools/ oldconfig
0025 #
0026 # Most of compiler features are tested by cc-option, which simply checks the
0027 # exit code of $(CC). This script does nothing and just exits with 0 in most
0028 # cases. So, $(cc-option, ...) is evaluated as 'y'.
0029 #
0030 # This scripts caters to more checks; handle --version and pre-process __GNUC__
0031 # etc. to pretend to be GCC, and also do right things to satisfy some scripts.
0032 
0033 # Check if the first parameter appears in the rest. Succeeds if found.
0034 # This helper is useful if a particular option was passed to this script.
0035 # Typically used like this:
0036 #   arg_contain <word-you-are-searching-for> "$@"
0037 arg_contain ()
0038 {
0039         search="$1"
0040         shift
0041 
0042         while [ $# -gt 0 ]
0043         do
0044                 if [ "$search" = "$1" ]; then
0045                         return 0
0046                 fi
0047                 shift
0048         done
0049 
0050         return 1
0051 }
0052 
0053 # To set CONFIG_CC_IS_GCC=y
0054 if arg_contain --version "$@"; then
0055         echo "gcc (scripts/dummy-tools/gcc)"
0056         exit 0
0057 fi
0058 
0059 if arg_contain -E "$@"; then
0060         # For scripts/cc-version.sh; This emulates GCC 20.0.0
0061         if arg_contain - "$@"; then
0062                 sed -n '/^GCC/{s/__GNUC__/20/; s/__GNUC_MINOR__/0/; s/__GNUC_PATCHLEVEL__/0/; p;}; s/__LONG_DOUBLE_128__/1/ p'
0063                 exit 0
0064         else
0065                 echo "no input files" >&2
0066                 exit 1
0067         fi
0068 fi
0069 
0070 # To set CONFIG_AS_IS_GNU
0071 if arg_contain -Wa,--version "$@"; then
0072         echo "GNU assembler (scripts/dummy-tools) 2.50"
0073         exit 0
0074 fi
0075 
0076 if arg_contain -S "$@"; then
0077         # For scripts/gcc-x86-*-has-stack-protector.sh
0078         if arg_contain -fstack-protector "$@"; then
0079                 if arg_contain -mstack-protector-guard-reg=fs "$@"; then
0080                         echo "%fs"
0081                 else
0082                         echo "%gs"
0083                 fi
0084                 exit 0
0085         fi
0086 
0087         # For arch/powerpc/tools/gcc-check-mprofile-kernel.sh
0088         if arg_contain -m64 "$@" && arg_contain -mlittle-endian "$@" &&
0089                 arg_contain -mprofile-kernel "$@"; then
0090                 if ! test -t 0 && ! grep -q notrace; then
0091                         echo "_mcount"
0092                 fi
0093                 exit 0
0094         fi
0095 fi
0096 
0097 # To set GCC_PLUGINS
0098 if arg_contain -print-file-name=plugin "$@"; then
0099         # Use $0 to find the in-tree dummy directory
0100         echo "$(dirname "$(readlink -f "$0")")/dummy-plugin-dir"
0101         exit 0
0102 fi
0103 
0104 # inverted return value
0105 if arg_contain -D__SIZEOF_INT128__=0 "$@"; then
0106         exit 1
0107 fi