xref: /OK3568_Linux_fs/device/rockchip/common/linux-kbuild/aarch64/linux-kbuild-4.19/scripts/gcc-version.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/sh
2*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0
3*4882a593Smuzhiyun#
4*4882a593Smuzhiyun# gcc-version [-p] gcc-command
5*4882a593Smuzhiyun#
6*4882a593Smuzhiyun# Prints the gcc version of `gcc-command' in a canonical 4-digit form
7*4882a593Smuzhiyun# such as `0295' for gcc-2.95, `0303' for gcc-3.3, etc.
8*4882a593Smuzhiyun#
9*4882a593Smuzhiyun# With the -p option, prints the patchlevel as well, for example `029503' for
10*4882a593Smuzhiyun# gcc-2.95.3, `030301' for gcc-3.3.1, etc.
11*4882a593Smuzhiyun#
12*4882a593Smuzhiyun
13*4882a593Smuzhiyunif [ "$1" = "-p" ] ; then
14*4882a593Smuzhiyun	with_patchlevel=1;
15*4882a593Smuzhiyun	shift;
16*4882a593Smuzhiyunfi
17*4882a593Smuzhiyun
18*4882a593Smuzhiyuncompiler="$*"
19*4882a593Smuzhiyun
20*4882a593Smuzhiyunif [ ${#compiler} -eq 0 ]; then
21*4882a593Smuzhiyun	echo "Error: No compiler specified."
22*4882a593Smuzhiyun	printf "Usage:\n\t$0 <gcc-command>\n"
23*4882a593Smuzhiyun	exit 1
24*4882a593Smuzhiyunfi
25*4882a593Smuzhiyun
26*4882a593SmuzhiyunMAJOR=$(echo __GNUC__ | $compiler -E -x c - | tail -n 1)
27*4882a593SmuzhiyunMINOR=$(echo __GNUC_MINOR__ | $compiler -E -x c - | tail -n 1)
28*4882a593Smuzhiyunif [ "x$with_patchlevel" != "x" ] ; then
29*4882a593Smuzhiyun	PATCHLEVEL=$(echo __GNUC_PATCHLEVEL__ | $compiler -E -x c - | tail -n 1)
30*4882a593Smuzhiyun	printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL
31*4882a593Smuzhiyunelse
32*4882a593Smuzhiyun	printf "%02d%02d\\n" $MAJOR $MINOR
33*4882a593Smuzhiyunfi
34