#!/bin/sh # # gcc-version [-p] gcc-command # # Prints the gcc version of `gcc-command' in a canonical 4-digit form # such as `0295' for gcc-2.95, `0303' for gcc-3.3, etc. # # With the -p option, prints the patchlevel as well, for example `029503' for # gcc-2.95.3, `030301' for gcc-3.3.1, etc. # if test $1 = "-p" { global with_patchlevel := '1'; shift; } global compiler := "$ifsjoin(Argv)" if test $(#compiler) -eq 0 { echo "Error: No compiler specified." printf "Usage:\n\t$0 \n" exit 1 } global MAJOR := $[echo __GNUC__ | $compiler -E -x c - | tail -n 1] global MINOR := $[echo __GNUC_MINOR__ | $compiler -E -x c - | tail -n 1] if test "x$with_patchlevel" != "x" { global PATCHLEVEL := $[echo __GNUC_PATCHLEVEL__ | $compiler -E -x c - | tail -n 1] printf "%02d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL } else { printf "%02d%02d\\n" $MAJOR $MINOR } (CommandList children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Number "$1"))} {(Lit_Other "=")} {(DQ (-p))} {(Lit_Other "]")} ) terminator: ) ] action: [ (Sentence child: (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:with_patchlevel) op: Equal rhs: {(1)} spids: [52] ) ] spids: [52] ) terminator: ) (Sentence child:(C {(shift)}) terminator:) ] spids: [-1 49] ) ] spids: [-1 60] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:compiler) op: Equal rhs: {(DQ ($ VSub_Star "$*"))} spids: [63] ) ] spids: [63] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(BracedVarSub token: prefix_op:VSub_Pound spids:[7376])} {(-eq)} {(0)} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Error: No compiler specified."))}) (C {(printf)} { (DQ ("Usage:") (EscapedLiteralPart token:) (EscapedLiteralPart token:) ($ VSub_Number "$0") (" ") (EscapedLiteralPart token:) ) } ) (C {(exit)} {(1)}) ] spids: [-1 85] ) ] spids: [-1 111] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:MAJOR) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(__GNUC__)}) (C {($ VSub_Name "$compiler")} {(-E)} {(-x)} {(c)} {(-)}) (C {(tail)} {(-n)} {(1)}) ] negated: False ) ] ) left_token: spids: [115 139] ) } spids: [114] ) ] spids: [114] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:MINOR) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(__GNUC_MINOR__)}) (C {($ VSub_Name "$compiler")} {(-E)} {(-x)} {(c)} {(-)}) (C {(tail)} {(-n)} {(1)}) ] negated: False ) ] ) left_token: spids: [142 166] ) } spids: [141] ) ] spids: [141] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ (x) ($ VSub_Name "$with_patchlevel"))} {(KW_Bang "!") (Lit_Other "=")} {(DQ (x))} {(Lit_Other "]")} ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PATCHLEVEL) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(echo)} {(__GNUC_PATCHLEVEL__)}) (C {($ VSub_Name "$compiler")} {(-E)} {(-x)} {(c)} {(-)}) (C {(tail)} {(-n)} {(1)}) ] negated: False ) ] ) left_token: spids: [192 216] ) } spids: [191] ) ] spids: [191] ) (C {(printf)} {(DQ ("%02d%02d%02d") (EscapedLiteralPart token:) (n))} {($ VSub_Name "$MAJOR")} {($ VSub_Name "$MINOR")} {($ VSub_Name "$PATCHLEVEL")} ) ] spids: [-1 188] ) ] else_action: [ (C {(printf)} {(DQ ("%02d%02d") (EscapedLiteralPart token:) (n))} {($ VSub_Name "$MAJOR")} {($ VSub_Name "$MINOR")} ) ] spids: [233 248] ) ] )