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