176426e23SMasahiro Yamada#!/bin/sh 276426e23SMasahiro Yamada# SPDX-License-Identifier: GPL-2.0-only 376426e23SMasahiro Yamada# 476426e23SMasahiro Yamada# Staring v4.18, Kconfig evaluates compiler capabilities, and hides CONFIG 576426e23SMasahiro Yamada# options your compiler does not support. This works well if you configure and 676426e23SMasahiro Yamada# build the kernel on the same host machine. 776426e23SMasahiro Yamada# 876426e23SMasahiro Yamada# It is inconvenient if you prepare the .config that is carried to a different 976426e23SMasahiro Yamada# build environment (typically this happens when you package the kernel for 1076426e23SMasahiro Yamada# distros) because using a different compiler potentially produces different 1176426e23SMasahiro Yamada# CONFIG options than the real build environment. So, you probably want to make 1276426e23SMasahiro Yamada# as many options visible as possible. In other words, you need to create a 1376426e23SMasahiro Yamada# super-set of CONFIG options that cover any build environment. If some of the 1476426e23SMasahiro Yamada# CONFIG options turned out to be unsupported on the build machine, they are 1576426e23SMasahiro Yamada# automatically disabled by the nature of Kconfig. 1676426e23SMasahiro Yamada# 1776426e23SMasahiro Yamada# However, it is not feasible to get a full-featured compiler for every arch. 1876426e23SMasahiro Yamada# Hence these dummy toolchains to make all compiler tests pass. 1976426e23SMasahiro Yamada# 2076426e23SMasahiro Yamada# Usage: 2176426e23SMasahiro Yamada# 2276426e23SMasahiro Yamada# From the top directory of the source tree, run 2376426e23SMasahiro Yamada# 2476426e23SMasahiro Yamada# $ make CROSS_COMPILE=scripts/dummy-tools/ oldconfig 2576426e23SMasahiro Yamada# 2676426e23SMasahiro Yamada# Most of compiler features are tested by cc-option, which simply checks the 2776426e23SMasahiro Yamada# exit code of $(CC). This script does nothing and just exits with 0 in most 2876426e23SMasahiro Yamada# cases. So, $(cc-option, ...) is evaluated as 'y'. 2976426e23SMasahiro Yamada# 3076426e23SMasahiro Yamada# This scripts caters to more checks; handle --version and pre-process __GNUC__ 3176426e23SMasahiro Yamada# etc. to pretend to be GCC, and also do right things to satisfy some scripts. 3276426e23SMasahiro Yamada 3376426e23SMasahiro Yamada# Check if the first parameter appears in the rest. Succeeds if found. 3476426e23SMasahiro Yamada# This helper is useful if a particular option was passed to this script. 3576426e23SMasahiro Yamada# Typically used like this: 3676426e23SMasahiro Yamada# arg_contain <word-you-are-searching-for> "$@" 3776426e23SMasahiro Yamadaarg_contain () 3876426e23SMasahiro Yamada{ 3976426e23SMasahiro Yamada search="$1" 4076426e23SMasahiro Yamada shift 4176426e23SMasahiro Yamada 4276426e23SMasahiro Yamada while [ $# -gt 0 ] 4376426e23SMasahiro Yamada do 4476426e23SMasahiro Yamada if [ "$search" = "$1" ]; then 4576426e23SMasahiro Yamada return 0 4676426e23SMasahiro Yamada fi 4776426e23SMasahiro Yamada shift 4876426e23SMasahiro Yamada done 4976426e23SMasahiro Yamada 5076426e23SMasahiro Yamada return 1 5176426e23SMasahiro Yamada} 5276426e23SMasahiro Yamada 5376426e23SMasahiro Yamada# To set CONFIG_CC_IS_GCC=y 5476426e23SMasahiro Yamadaif arg_contain --version "$@"; then 5576426e23SMasahiro Yamada echo "gcc (scripts/dummy-tools/gcc)" 5676426e23SMasahiro Yamada exit 0 5776426e23SMasahiro Yamadafi 5876426e23SMasahiro Yamada 5976426e23SMasahiro Yamadaif arg_contain -E "$@"; then 60f9bc754bSMasahiro Yamada # For scripts/cc-version.sh; This emulates GCC 20.0.0 6176426e23SMasahiro Yamada if arg_contain - "$@"; then 62f9bc754bSMasahiro Yamada sed -n '/^GCC/{s/__GNUC__/20/; s/__GNUC_MINOR__/0/; s/__GNUC_PATCHLEVEL__/0/; p;}' 6376426e23SMasahiro Yamada exit 0 6476426e23SMasahiro Yamada else 6576426e23SMasahiro Yamada echo "no input files" >&2 6676426e23SMasahiro Yamada exit 1 6776426e23SMasahiro Yamada fi 6876426e23SMasahiro Yamadafi 6976426e23SMasahiro Yamada 70ba64beb1SMasahiro Yamada# To set CONFIG_AS_IS_GNU 71ba64beb1SMasahiro Yamadaif arg_contain -Wa,--version "$@"; then 72ba64beb1SMasahiro Yamada echo "GNU assembler (scripts/dummy-tools) 2.50" 73ba64beb1SMasahiro Yamada exit 0 74ba64beb1SMasahiro Yamadafi 75ba64beb1SMasahiro Yamada 7676426e23SMasahiro Yamadaif arg_contain -S "$@"; then 7776426e23SMasahiro Yamada # For scripts/gcc-x86-*-has-stack-protector.sh 7876426e23SMasahiro Yamada if arg_contain -fstack-protector "$@"; then 79c93db682SMichal Kubecek if arg_contain -mstack-protector-guard-reg=fs "$@"; then 80c93db682SMichal Kubecek echo "%fs" 81c93db682SMichal Kubecek else 8276426e23SMasahiro Yamada echo "%gs" 83c93db682SMichal Kubecek fi 8476426e23SMasahiro Yamada exit 0 8576426e23SMasahiro Yamada fi 862eab791fSJiri Slaby 872eab791fSJiri Slaby # For arch/powerpc/tools/gcc-check-mprofile-kernel.sh 882eab791fSJiri Slaby if arg_contain -m64 "$@" && arg_contain -mlittle-endian "$@" && 892eab791fSJiri Slaby arg_contain -mprofile-kernel "$@"; then 902eab791fSJiri Slaby if ! test -t 0 && ! grep -q notrace; then 912eab791fSJiri Slaby echo "_mcount" 922eab791fSJiri Slaby fi 932eab791fSJiri Slaby exit 0 942eab791fSJiri Slaby fi 9576426e23SMasahiro Yamadafi 9676426e23SMasahiro Yamada 97f4c3b83bSMasahiro Yamada# To set GCC_PLUGINS 9876426e23SMasahiro Yamadaif arg_contain -print-file-name=plugin "$@"; then 99*aac28965SOndrej Mosnacek # Use $0 to find the in-tree dummy directory 100*aac28965SOndrej Mosnacek echo "$(dirname "$(readlink -f "$0")")/dummy-plugin-dir" 10176426e23SMasahiro Yamada exit 0 10276426e23SMasahiro Yamadafi 103b3d9fc14SJiri Slaby 104b3d9fc14SJiri Slaby# inverted return value 105b3d9fc14SJiri Slabyif arg_contain -D__SIZEOF_INT128__=0 "$@"; then 106b3d9fc14SJiri Slaby exit 1 107b3d9fc14SJiri Slabyfi 108