blob: ae353432539bf5a58bf24c21ea6c3b20b460c501 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#!/bin/sh
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01002# SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07003#
Masahiro Yamadafa7295a2019-03-01 16:10:22 +09004# gcc-version gcc-command
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#
Masahiro Yamadafa7295a2019-03-01 16:10:22 +09006# Print the gcc version of `gcc-command' in a 5 or 6-digit form
7# such as `29503' for gcc-2.95.3, `30301' for gcc-3.3.1, etc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9compiler="$*"
10
Jesper Juhlde470622007-08-04 20:30:42 +020011if [ ${#compiler} -eq 0 ]; then
Masahiro Yamadafa7295a2019-03-01 16:10:22 +090012 echo "Error: No compiler specified." >&2
13 printf "Usage:\n\t$0 <gcc-command>\n" >&2
Jesper Juhlde470622007-08-04 20:30:42 +020014 exit 1
15fi
16
Jean Delvareb1e0d8b2012-10-02 16:42:36 +020017MAJOR=$(echo __GNUC__ | $compiler -E -x c - | tail -n 1)
18MINOR=$(echo __GNUC_MINOR__ | $compiler -E -x c - | tail -n 1)
Masahiro Yamadafa7295a2019-03-01 16:10:22 +090019PATCHLEVEL=$(echo __GNUC_PATCHLEVEL__ | $compiler -E -x c - | tail -n 1)
20printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL