blob: 11bb909845e78b623c393e11c39c2077eb2f194c [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#
Segher Boessenkool0ab2a272007-05-19 18:49:07 +02004# gcc-version [-p] gcc-command
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#
6# Prints the gcc version of `gcc-command' in a canonical 4-digit form
7# such as `0295' for gcc-2.95, `0303' for gcc-3.3, etc.
8#
Segher Boessenkool0ab2a272007-05-19 18:49:07 +02009# With the -p option, prints the patchlevel as well, for example `029503' for
10# gcc-2.95.3, `030301' for gcc-3.3.1, etc.
11#
12
Sam Ravnborg0484f122007-12-31 14:22:55 +010013if [ "$1" = "-p" ] ; then
14 with_patchlevel=1;
15 shift;
16fi
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18compiler="$*"
19
Jesper Juhlde470622007-08-04 20:30:42 +020020if [ ${#compiler} -eq 0 ]; then
21 echo "Error: No compiler specified."
dann frazierbdefe352009-06-05 15:02:49 -070022 printf "Usage:\n\t$0 <gcc-command>\n"
Jesper Juhlde470622007-08-04 20:30:42 +020023 exit 1
24fi
25
Jean Delvareb1e0d8b2012-10-02 16:42:36 +020026MAJOR=$(echo __GNUC__ | $compiler -E -x c - | tail -n 1)
27MINOR=$(echo __GNUC_MINOR__ | $compiler -E -x c - | tail -n 1)
Segher Boessenkool0ab2a272007-05-19 18:49:07 +020028if [ "x$with_patchlevel" != "x" ] ; then
Jean Delvareb1e0d8b2012-10-02 16:42:36 +020029 PATCHLEVEL=$(echo __GNUC_PATCHLEVEL__ | $compiler -E -x c - | tail -n 1)
Segher Boessenkool0ab2a272007-05-19 18:49:07 +020030 printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL
31else
32 printf "%02d%02d\\n" $MAJOR $MINOR
33fi