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