162306a36Sopenharmony_ci#!/bin/sh 262306a36Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only 362306a36Sopenharmony_ci# 462306a36Sopenharmony_ci# Staring v4.18, Kconfig evaluates compiler capabilities, and hides CONFIG 562306a36Sopenharmony_ci# options your compiler does not support. This works well if you configure and 662306a36Sopenharmony_ci# build the kernel on the same host machine. 762306a36Sopenharmony_ci# 862306a36Sopenharmony_ci# It is inconvenient if you prepare the .config that is carried to a different 962306a36Sopenharmony_ci# build environment (typically this happens when you package the kernel for 1062306a36Sopenharmony_ci# distros) because using a different compiler potentially produces different 1162306a36Sopenharmony_ci# CONFIG options than the real build environment. So, you probably want to make 1262306a36Sopenharmony_ci# as many options visible as possible. In other words, you need to create a 1362306a36Sopenharmony_ci# super-set of CONFIG options that cover any build environment. If some of the 1462306a36Sopenharmony_ci# CONFIG options turned out to be unsupported on the build machine, they are 1562306a36Sopenharmony_ci# automatically disabled by the nature of Kconfig. 1662306a36Sopenharmony_ci# 1762306a36Sopenharmony_ci# However, it is not feasible to get a full-featured compiler for every arch. 1862306a36Sopenharmony_ci# Hence these dummy toolchains to make all compiler tests pass. 1962306a36Sopenharmony_ci# 2062306a36Sopenharmony_ci# Usage: 2162306a36Sopenharmony_ci# 2262306a36Sopenharmony_ci# From the top directory of the source tree, run 2362306a36Sopenharmony_ci# 2462306a36Sopenharmony_ci# $ make CROSS_COMPILE=scripts/dummy-tools/ oldconfig 2562306a36Sopenharmony_ci# 2662306a36Sopenharmony_ci# Most of compiler features are tested by cc-option, which simply checks the 2762306a36Sopenharmony_ci# exit code of $(CC). This script does nothing and just exits with 0 in most 2862306a36Sopenharmony_ci# cases. So, $(cc-option, ...) is evaluated as 'y'. 2962306a36Sopenharmony_ci# 3062306a36Sopenharmony_ci# This scripts caters to more checks; handle --version and pre-process __GNUC__ 3162306a36Sopenharmony_ci# etc. to pretend to be GCC, and also do right things to satisfy some scripts. 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci# Check if the first parameter appears in the rest. Succeeds if found. 3462306a36Sopenharmony_ci# This helper is useful if a particular option was passed to this script. 3562306a36Sopenharmony_ci# Typically used like this: 3662306a36Sopenharmony_ci# arg_contain <word-you-are-searching-for> "$@" 3762306a36Sopenharmony_ciarg_contain () 3862306a36Sopenharmony_ci{ 3962306a36Sopenharmony_ci search="$1" 4062306a36Sopenharmony_ci shift 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci while [ $# -gt 0 ] 4362306a36Sopenharmony_ci do 4462306a36Sopenharmony_ci if [ "$search" = "$1" ]; then 4562306a36Sopenharmony_ci return 0 4662306a36Sopenharmony_ci fi 4762306a36Sopenharmony_ci shift 4862306a36Sopenharmony_ci done 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci return 1 5162306a36Sopenharmony_ci} 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci# To set CONFIG_CC_IS_GCC=y 5462306a36Sopenharmony_ciif arg_contain --version "$@"; then 5562306a36Sopenharmony_ci echo "gcc (scripts/dummy-tools/gcc)" 5662306a36Sopenharmony_ci exit 0 5762306a36Sopenharmony_cifi 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ciif arg_contain -E "$@"; then 6062306a36Sopenharmony_ci # For scripts/cc-version.sh; This emulates GCC 20.0.0 6162306a36Sopenharmony_ci if arg_contain - "$@"; then 6262306a36Sopenharmony_ci sed -n '/^GCC/{s/__GNUC__/20/; s/__GNUC_MINOR__/0/; s/__GNUC_PATCHLEVEL__/0/; p;}; s/__LONG_DOUBLE_128__/1/ p' 6362306a36Sopenharmony_ci exit 0 6462306a36Sopenharmony_ci else 6562306a36Sopenharmony_ci echo "no input files" >&2 6662306a36Sopenharmony_ci exit 1 6762306a36Sopenharmony_ci fi 6862306a36Sopenharmony_cifi 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci# To set CONFIG_AS_IS_GNU 7162306a36Sopenharmony_ciif arg_contain -Wa,--version "$@"; then 7262306a36Sopenharmony_ci echo "GNU assembler (scripts/dummy-tools) 2.50" 7362306a36Sopenharmony_ci exit 0 7462306a36Sopenharmony_cifi 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ciif arg_contain -S "$@"; then 7762306a36Sopenharmony_ci # For scripts/gcc-x86-*-has-stack-protector.sh 7862306a36Sopenharmony_ci if arg_contain -fstack-protector "$@"; then 7962306a36Sopenharmony_ci if arg_contain -mstack-protector-guard-reg=fs "$@"; then 8062306a36Sopenharmony_ci echo "%fs" 8162306a36Sopenharmony_ci else 8262306a36Sopenharmony_ci echo "%gs" 8362306a36Sopenharmony_ci fi 8462306a36Sopenharmony_ci exit 0 8562306a36Sopenharmony_ci fi 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci # For arch/powerpc/tools/gcc-check-mprofile-kernel.sh 8862306a36Sopenharmony_ci if arg_contain -m64 "$@" && arg_contain -mprofile-kernel "$@"; then 8962306a36Sopenharmony_ci if ! test -t 0 && ! grep -q notrace; then 9062306a36Sopenharmony_ci echo "_mcount" 9162306a36Sopenharmony_ci fi 9262306a36Sopenharmony_ci exit 0 9362306a36Sopenharmony_ci fi 9462306a36Sopenharmony_cifi 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci# To set GCC_PLUGINS 9762306a36Sopenharmony_ciif arg_contain -print-file-name=plugin "$@"; then 9862306a36Sopenharmony_ci # Use $0 to find the in-tree dummy directory 9962306a36Sopenharmony_ci echo "$(dirname "$(readlink -f "$0")")/dummy-plugin-dir" 10062306a36Sopenharmony_ci exit 0 10162306a36Sopenharmony_cifi 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci# inverted return value 10462306a36Sopenharmony_ciif arg_contain -D__SIZEOF_INT128__=0 "$@"; then 10562306a36Sopenharmony_ci exit 1 10662306a36Sopenharmony_cifi 107