Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #!/bin/sh |
Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | # |
Masahiro Yamada | fa7295a | 2019-03-01 16:10:22 +0900 | [diff] [blame] | 4 | # gcc-version gcc-command |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | # |
Masahiro Yamada | fa7295a | 2019-03-01 16:10:22 +0900 | [diff] [blame] | 6 | # 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
| 9 | compiler="$*" |
| 10 | |
Jesper Juhl | de47062 | 2007-08-04 20:30:42 +0200 | [diff] [blame] | 11 | if [ ${#compiler} -eq 0 ]; then |
Masahiro Yamada | fa7295a | 2019-03-01 16:10:22 +0900 | [diff] [blame] | 12 | echo "Error: No compiler specified." >&2 |
| 13 | printf "Usage:\n\t$0 <gcc-command>\n" >&2 |
Jesper Juhl | de47062 | 2007-08-04 20:30:42 +0200 | [diff] [blame] | 14 | exit 1 |
| 15 | fi |
| 16 | |
Jean Delvare | b1e0d8b | 2012-10-02 16:42:36 +0200 | [diff] [blame] | 17 | MAJOR=$(echo __GNUC__ | $compiler -E -x c - | tail -n 1) |
| 18 | MINOR=$(echo __GNUC_MINOR__ | $compiler -E -x c - | tail -n 1) |
Masahiro Yamada | fa7295a | 2019-03-01 16:10:22 +0900 | [diff] [blame] | 19 | PATCHLEVEL=$(echo __GNUC_PATCHLEVEL__ | $compiler -E -x c - | tail -n 1) |
| 20 | printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL |