Back to home page

LXR

 
 

    


0001 #!/bin/sh
0002 #
0003 # gcc-version [-p] gcc-command
0004 #
0005 # Prints the gcc version of `gcc-command' in a canonical 4-digit form
0006 # such as `0295' for gcc-2.95, `0303' for gcc-3.3, etc.
0007 #
0008 # With the -p option, prints the patchlevel as well, for example `029503' for
0009 # gcc-2.95.3, `030301' for gcc-3.3.1, etc.
0010 #
0011 
0012 if [ "$1" = "-p" ] ; then
0013         with_patchlevel=1;
0014         shift;
0015 fi
0016 
0017 compiler="$*"
0018 
0019 if [ ${#compiler} -eq 0 ]; then
0020         echo "Error: No compiler specified."
0021         printf "Usage:\n\t$0 <gcc-command>\n"
0022         exit 1
0023 fi
0024 
0025 MAJOR=$(echo __GNUC__ | $compiler -E -x c - | tail -n 1)
0026 MINOR=$(echo __GNUC_MINOR__ | $compiler -E -x c - | tail -n 1)
0027 if [ "x$with_patchlevel" != "x" ] ; then
0028         PATCHLEVEL=$(echo __GNUC_PATCHLEVEL__ | $compiler -E -x c - | tail -n 1)
0029         printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL
0030 else
0031         printf "%02d%02d\\n" $MAJOR $MINOR
0032 fi