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