xref: /openbmc/linux/scripts/dummy-tools/gcc (revision 76426e23)
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
6076426e23SMasahiro Yamada	# For scripts/gcc-version.sh; This emulates GCC 20.0.0
6176426e23SMasahiro Yamada	if arg_contain - "$@"; then
6276426e23SMasahiro Yamada		sed 's/^__GNUC__$/20/; s/^__GNUC_MINOR__$/0/; s/^__GNUC_PATCHLEVEL__$/0/'
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
7076426e23SMasahiro Yamadaif arg_contain -S "$@"; then
7176426e23SMasahiro Yamada	# For scripts/gcc-x86-*-has-stack-protector.sh
7276426e23SMasahiro Yamada	if arg_contain -fstack-protector "$@"; then
7376426e23SMasahiro Yamada		echo "%gs"
7476426e23SMasahiro Yamada		exit 0
7576426e23SMasahiro Yamada	fi
7676426e23SMasahiro Yamadafi
7776426e23SMasahiro Yamada
7876426e23SMasahiro Yamada# For scripts/gcc-plugin.sh
7976426e23SMasahiro Yamadaif arg_contain -print-file-name=plugin "$@"; then
8076426e23SMasahiro Yamada	plugin_dir=$(mktemp -d)
8176426e23SMasahiro Yamada
8276426e23SMasahiro Yamada	sed -n 's/.*#include "\(.*\)"/\1/p' $(dirname $0)/../gcc-plugins/gcc-common.h |
8376426e23SMasahiro Yamada	while read header
8476426e23SMasahiro Yamada	do
8576426e23SMasahiro Yamada		mkdir -p $plugin_dir/include/$(dirname $header)
8676426e23SMasahiro Yamada		touch $plugin_dir/include/$header
8776426e23SMasahiro Yamada	done
8876426e23SMasahiro Yamada
8976426e23SMasahiro Yamada	echo $plugin_dir
9076426e23SMasahiro Yamada	exit 0
9176426e23SMasahiro Yamadafi
92