summaryrefslogtreecommitdiff
path: root/scripts/dummy-tools/gcc
blob: 33487e99d83e5c0fe076c317f218a93fae3ada01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only
#
# Staring v4.18, Kconfig evaluates compiler capabilities, and hides CONFIG
# options your compiler does not support. This works well if you configure and
# build the kernel on the same host machine.
#
# It is inconvenient if you prepare the .config that is carried to a different
# build environment (typically this happens when you package the kernel for
# distros) because using a different compiler potentially produces different
# CONFIG options than the real build environment. So, you probably want to make
# as many options visible as possible. In other words, you need to create a
# super-set of CONFIG options that cover any build environment. If some of the
# CONFIG options turned out to be unsupported on the build machine, they are
# automatically disabled by the nature of Kconfig.
#
# However, it is not feasible to get a full-featured compiler for every arch.
# Hence these dummy toolchains to make all compiler tests pass.
#
# Usage:
#
# From the top directory of the source tree, run
#
#   $ make CROSS_COMPILE=scripts/dummy-tools/ oldconfig
#
# Most of compiler features are tested by cc-option, which simply checks the
# exit code of $(CC). This script does nothing and just exits with 0 in most
# cases. So, $(cc-option, ...) is evaluated as 'y'.
#
# This scripts caters to more checks; handle --version and pre-process __GNUC__
# etc. to pretend to be GCC, and also do right things to satisfy some scripts.

# Check if the first parameter appears in the rest. Succeeds if found.
# This helper is useful if a particular option was passed to this script.
# Typically used like this:
#   arg_contain <word-you-are-searching-for> "$@"
arg_contain ()
{
	search="$1"
	shift

	while [ $# -gt 0 ]
	do
		if [ "$search" = "$1" ]; then
			return 0
		fi
		shift
	done

	return 1
}

# To set CONFIG_CC_IS_GCC=y
if arg_contain --version "$@"; then
	echo "gcc (scripts/dummy-tools/gcc)"
	exit 0
fi

if arg_contain -E "$@"; then
	# For scripts/gcc-version.sh; This emulates GCC 20.0.0
	if arg_contain - "$@"; then
		sed 's/^__GNUC__$/20/; s/^__GNUC_MINOR__$/0/; s/^__GNUC_PATCHLEVEL__$/0/'
		exit 0
	else
		echo "no input files" >&2
		exit 1
	fi
fi

if arg_contain -S "$@"; then
	# For scripts/gcc-x86-*-has-stack-protector.sh
	if arg_contain -fstack-protector "$@"; then
		echo "%gs"
		exit 0
	fi
fi

# For scripts/gcc-plugin.sh
if arg_contain -print-file-name=plugin "$@"; then
	plugin_dir=$(mktemp -d)

	sed -n 's/.*#include "\(.*\)"/\1/p' $(dirname $0)/../gcc-plugins/gcc-common.h |
	while read header
	do
		mkdir -p $plugin_dir/include/$(dirname $header)
		touch $plugin_dir/include/$header
	done

	echo $plugin_dir
	exit 0
fi