Patchwork [U-Boot,v4,1/2] tools, config.mk: add binutils-version

login
register
mail settings
Submitter Allen Martin
Date July 18, 2012, 11:45 p.m.
Message ID <1342655153-9023-1-git-send-email-amartin@nvidia.com>
Download mbox | patch
Permalink /patch/171857/
State Superseded
Headers show

Comments

Allen Martin - July 18, 2012, 11:45 p.m.
Modeled after gcc-version, add function to get binutils version.

Signed-off-by: Allen Martin <amartin@nvidia.com>
---
 config.mk                 |    1 +
 tools/binutils-version.sh |   20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)
 create mode 100755 tools/binutils-version.sh
Mike Frysinger - July 19, 2012, 3:11 a.m.
On Wednesday 18 July 2012 19:45:52 Allen Martin wrote:
> +MAJOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 1)
> +MINOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 2)
> +
> +printf "%02d%02d\\n" $MAJOR $MINOR

can be replaced with a single awk script:

$gas --version | awk '{
	gsub(/[.]/, " ", $NF)
	$0 = $NF
	printf "%02d%02d\n", $1, $2
	exit
}'
-mike
Tom Rini - July 19, 2012, 3:08 p.m.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/18/2012 08:11 PM, Mike Frysinger wrote:
> On Wednesday 18 July 2012 19:45:52 Allen Martin wrote:
>> +MAJOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . 
>> -f 1) +MINOR=$($gas --version | head -1 | awk '{print $NF}' |
>> cut -d . -f 2) + +printf "%02d%02d\\n" $MAJOR $MINOR
> 
> can be replaced with a single awk script:
> 
> $gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF printf 
> "%02d%02d\n", $1, $2 exit }'

That looks much longer and we call this once so a few execs is noise.

- -- 
Tom

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJQCCLaAAoJENk4IS6UOR1Wag8P/0/s9VVHGj60Q2MqaJPWST1H
8SVj8SMNBbeG2WHadkY+iB815MoToK+8oz5WMXhDA8PLThXdljBaQgbIjur2xyo5
QXRPFwxk3oIQxiy/fKR9ubt1eg9jJSrnZM6tTdWpOANYeqZo5w9S4MKoUr+mT9cf
FzXIhKOoX9YRxKZsqhMYgTxO85sMg7FUn8OEK3q1GJdbqVF5lSSAKSG/WHDbv3wV
/VIbgskp2OjtOlq1GHtmEQw77d1aYhHkwSKaRiYnFKimez+GeIq++ap9bdt2x7Dn
87THqKfeB62xdID9kCIDf9tUPKeFBf/mN606Vreg6s00DxZOmtn20CW/WErxIdxx
7b6r49KXPKqA553e08BChbopvQEYM9F/5MIkPqEX71ilR8p9WJ56IuJNJNbSMFMZ
YP96niRroVEV8KBk9FAPIqgNVZ40Fz0TCJSurs2ESHBaVlH9ZF9b6YjOXjIulFwa
WImS4xwXcsfV0PzryVxsptX2TEq8t0p9gXt7oKCAjvER8nnGjLz+B7VuNl1avBrC
6xXyBSpXhOMgpTTPleC7ymo9D8NUJFfetDwi2jNVxcnVIT/tiN3eqFWbapdqWeds
pfocE+E2VIZF2g1BizMuUYuPkw/9NJBqp42vS8lr/FVdaePzIOZo/DSDl95/Vlr6
U6BFALNyEJK0WmnXaOIV
=6YIv
-----END PGP SIGNATURE-----
Mike Frysinger - July 19, 2012, 3:21 p.m.
On Thursday 19 July 2012 11:08:10 Tom Rini wrote:
> On 07/18/2012 08:11 PM, Mike Frysinger wrote:
> > On Wednesday 18 July 2012 19:45:52 Allen Martin wrote:
> >> +MAJOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 1)
> >> +MINOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 2)
> >> +
> >> +printf "%02d%02d\\n" $MAJOR $MINOR
> > 
> > can be replaced with a single awk script:
> > 
> > $gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF printf
> > "%02d%02d\n", $1, $2 exit }'
> 
> That looks much longer and we call this once so a few execs is noise.

here's a shorter version:
$gas --version | awk '{ gsub(/[.]/, " ", $NF); $0 = $NF; printf "%02d%02d\n", $1, $2; exit }'
-mike
Tom Rini - July 19, 2012, 3:38 p.m.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/19/2012 08:21 AM, Mike Frysinger wrote:
> On Thursday 19 July 2012 11:08:10 Tom Rini wrote:
>> On 07/18/2012 08:11 PM, Mike Frysinger wrote:
>>> On Wednesday 18 July 2012 19:45:52 Allen Martin wrote:
>>>> +MAJOR=$($gas --version | head -1 | awk '{print $NF}' | cut
>>>> -d . -f 1) +MINOR=$($gas --version | head -1 | awk '{print
>>>> $NF}' | cut -d . -f 2) + +printf "%02d%02d\\n" $MAJOR $MINOR
>>> 
>>> can be replaced with a single awk script:
>>> 
>>> $gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF printf 
>>> "%02d%02d\n", $1, $2 exit }'
>> 
>> That looks much longer and we call this once so a few execs is
>> noise.
> 
> here's a shorter version: $gas --version | awk '{ gsub(/[.]/, " ",
> $NF); $0 = $NF; printf "%02d%02d\n", $1, $2; exit }'

And still over 80 chars before we assign it to a variable.  I could
get it to 77 chars with all whitespace removed.

- -- 
Tom


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJQCCn/AAoJENk4IS6UOR1WFJwP/2pv0lUXUJVJZk1Wb1w2ln2G
MtjUg1ntwrgQmKCb5D67VNCHN2sjtiWi0HGNZDCvHqRz9AGN7BX/Dz8Jx0hKoqf3
S92J7VpKJ+MGpBVpWxlZMNY5FlBnkiVpUCkIQefhz5sUqq1fA2PjCs82MRadr9WP
KmpfDXZ6OBRl7hKqeHVaYaqfCjxaaXqmPLrXh1VXUjA6oYKv0kZcvW9H2kMPyaTd
+shYx0z/TI6UXHmw0CmcoDvPsy9cIBAtqtuqOeP/YP1sIHq1UQBIehfD4ji4JZAl
wWKymSJwtcIl6hCV+IV3/wGczIdvRfyraa8mN5/MrVWLbgiytW/OOnix7mYlw4ov
ysXz/5pg7dPkaHxczvANpVO7PkzRJZKMQhjyuZmVDSDdEzPks9QHWt3miRErXjMc
kkD2LaKkV9hBBSqD6+/vfd45zLI125UDfkkRLLwr67bHcrGkdBbojOXE357vQx7N
ELp2FPOwfXkBOw//P0KhlVtc9T1Li+LqqfjqzbYQkPYbHzcAal7SPERzxION+pFO
00M+uYwtxPDm/wvmk033VTZNaLdvLHU6Zg1wkKwj484MZ/x+ptFwDvTwppRw/Kme
4JuhjxWGwQFu9tkV0gWFd2D2uYZzbDt5VnZkntp1BxyXEHJ3FvvUvMryr8ZqEAIS
Ss/IDqUlIsctLDiDziSD
=9xj8
-----END PGP SIGNATURE-----
Mike Frysinger - July 19, 2012, 4:43 p.m.
On Thursday 19 July 2012 11:38:39 Tom Rini wrote:
> On 07/19/2012 08:21 AM, Mike Frysinger wrote:
> > On Thursday 19 July 2012 11:08:10 Tom Rini wrote:
> >> On 07/18/2012 08:11 PM, Mike Frysinger wrote:
> >>> On Wednesday 18 July 2012 19:45:52 Allen Martin wrote:
> >>>> +MAJOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 1)
> >>>> +MINOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 2)
> >>>> +
> >>>> +printf "%02d%02d\\n" $MAJOR $MINOR
> >>> 
> >>> can be replaced with a single awk script:
> >>> 
> >>> $gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF printf
> >>> "%02d%02d\n", $1, $2 exit }'
> >> 
> >> That looks much longer and we call this once so a few execs is
> >> noise.
> > 
> > here's a shorter version: $gas --version | awk '{ gsub(/[.]/, " ",
> > $NF); $0 = $NF; printf "%02d%02d\n", $1, $2; exit }'
> 
> And still over 80 chars before we assign it to a variable.  I could
> get it to 77 chars with all whitespace removed.

which is why i unrolled it to make it readable.  i don't know what metrics 
you're using here, but i don't think the awk version is "longer" by really any 
of them.
-mike
Tom Rini - July 19, 2012, 4:54 p.m.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/19/2012 09:43 AM, Mike Frysinger wrote:
> On Thursday 19 July 2012 11:38:39 Tom Rini wrote:
>> On 07/19/2012 08:21 AM, Mike Frysinger wrote:
>>> On Thursday 19 July 2012 11:08:10 Tom Rini wrote:
>>>> On 07/18/2012 08:11 PM, Mike Frysinger wrote:
>>>>> On Wednesday 18 July 2012 19:45:52 Allen Martin wrote:
>>>>>> +MAJOR=$($gas --version | head -1 | awk '{print $NF}' |
>>>>>> cut -d . -f 1) +MINOR=$($gas --version | head -1 | awk
>>>>>> '{print $NF}' | cut -d . -f 2) + +printf "%02d%02d\\n"
>>>>>> $MAJOR $MINOR
>>>>> 
>>>>> can be replaced with a single awk script:
>>>>> 
>>>>> $gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF
>>>>> printf "%02d%02d\n", $1, $2 exit }'
>>>> 
>>>> That looks much longer and we call this once so a few execs
>>>> is noise.
>>> 
>>> here's a shorter version: $gas --version | awk '{ gsub(/[.]/, "
>>> ", $NF); $0 = $NF; printf "%02d%02d\n", $1, $2; exit }'
>> 
>> And still over 80 chars before we assign it to a variable.  I
>> could get it to 77 chars with all whitespace removed.
> 
> which is why i unrolled it to make it readable.  i don't know what
> metrics you're using here, but i don't think the awk version is
> "longer" by really any of them.

The metric of 'wc -c' and "what fits in a single line, unwrapped on an
80x24 terminal."  awk is great and awesome, don't get me wrong, but
it's not doing the job as compactly as the original.

- -- 
Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQIcBAEBAgAGBQJQCDvNAAoJENk4IS6UOR1WzRsP/ikEjUCPX593aZxLqHh7oGZO
novK94mu/ThO8pApYs17Lhh77wh9Bn/lbRrqwjRrFZAKqGN6gPYpknvvmxD31AkV
K72xz19ut7S/zBAVZIgMcnuHDvz5LEEBZBRjinmKM+7nMRMvaqi2rEhs+PUj00xP
IPeQvqttfAB1iblVhU+07at6vhsKRM2fXS45crXztGXYfeYzT90hMM4NrGXuiJ+G
4aav8FK4nHM+DgOAjzwYlZ7Ty1okm0F7mAwM9+nJE5WiUPI8G9nPzcWt3IeVa6JF
XmRkaZH7cTAz/qrWjbVKd7rLnZ75jqoez1Wv4FVescrJ6Mu5oH7QUXfciYJrGwQ8
VHBBvI+Hf1W2YICBHTeO9wdfMOuVl7Jj6K7+CunczJ7qA5VjUHyr0Q3gCnr3UoTW
9tUblOT39zRLIs57IWN7cio2RdIPdzd1N5sGh3S1UxGhM+dnUTeM3faVxoI8LJyU
/Fb+kmv1LhMPPMjqxyzbFROjGZVXx0T4K5ERqrZ+k4jP/r3t6QOAMsJhvypZHkQf
WeMyldYIwlbeflMYKjxA729C/CdN0MJttYMbnBRhcmWM/VJR41Cuh2GSOhN635Z3
N3IYxb9V8txAfq308rEp9Hwj1oJ9DjnEw3xBvjBLYCcFncJSER6dMajuFK6qXqay
PR+q3ZquMwPWcYlWQRyk
=sxrC
-----END PGP SIGNATURE-----
Mike Frysinger - Aug. 1, 2012, 10:31 p.m.
On Thursday 19 July 2012 12:54:37 Tom Rini wrote:
> On 07/19/2012 09:43 AM, Mike Frysinger wrote:
> > On Thursday 19 July 2012 11:38:39 Tom Rini wrote:
> >> On 07/19/2012 08:21 AM, Mike Frysinger wrote:
> >>> On Thursday 19 July 2012 11:08:10 Tom Rini wrote:
> >>>> On 07/18/2012 08:11 PM, Mike Frysinger wrote:
> >>>>> On Wednesday 18 July 2012 19:45:52 Allen Martin wrote:
> >>>>>> +MAJOR=$($gas --version | head -1 | awk '{print $NF}' |
> >>>>>> cut -d . -f 1) +MINOR=$($gas --version | head -1 | awk
> >>>>>> '{print $NF}' | cut -d . -f 2) + +printf "%02d%02d\\n"
> >>>>>> $MAJOR $MINOR
> >>>>> 
> >>>>> can be replaced with a single awk script:
> >>>>> 
> >>>>> $gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF
> >>>>> printf "%02d%02d\n", $1, $2 exit }'
> >>>> 
> >>>> That looks much longer and we call this once so a few execs
> >>>> is noise.
> >>> 
> >>> here's a shorter version: $gas --version | awk '{ gsub(/[.]/, "
> >>> ", $NF); $0 = $NF; printf "%02d%02d\n", $1, $2; exit }'
> >> 
> >> And still over 80 chars before we assign it to a variable.  I
> >> could get it to 77 chars with all whitespace removed.
> > 
> > which is why i unrolled it to make it readable.  i don't know what
> > metrics you're using here, but i don't think the awk version is
> > "longer" by really any of them.
> 
> The metric of 'wc -c' and "what fits in a single line, unwrapped on an
> 80x24 terminal."  awk is great and awesome, don't get me wrong, but
> it's not doing the job as compactly as the original.

obviously i disagree.  i find the awk version "better" in just about every way.  
maybe someone else will jump in with their favorite bike.
-mike
Allen Martin - Aug. 1, 2012, 10:46 p.m.
On Wed, Aug 01, 2012 at 03:31:37PM -0700, Mike Frysinger wrote:
> On Thursday 19 July 2012 12:54:37 Tom Rini wrote:
> > On 07/19/2012 09:43 AM, Mike Frysinger wrote:
> > > On Thursday 19 July 2012 11:38:39 Tom Rini wrote:
> > >> On 07/19/2012 08:21 AM, Mike Frysinger wrote:
> > >>> On Thursday 19 July 2012 11:08:10 Tom Rini wrote:
> > >>>> On 07/18/2012 08:11 PM, Mike Frysinger wrote:
> > >>>>> On Wednesday 18 July 2012 19:45:52 Allen Martin wrote:
> > >>>>>> +MAJOR=$($gas --version | head -1 | awk '{print $NF}' |
> > >>>>>> cut -d . -f 1) +MINOR=$($gas --version | head -1 | awk
> > >>>>>> '{print $NF}' | cut -d . -f 2) + +printf "%02d%02d\\n"
> > >>>>>> $MAJOR $MINOR
> > >>>>> 
> > >>>>> can be replaced with a single awk script:
> > >>>>> 
> > >>>>> $gas --version | awk '{ gsub(/[.]/, " ", $NF) $0 = $NF
> > >>>>> printf "%02d%02d\n", $1, $2 exit }'
> > >>>> 
> > >>>> That looks much longer and we call this once so a few execs
> > >>>> is noise.
> > >>> 
> > >>> here's a shorter version: $gas --version | awk '{ gsub(/[.]/, "
> > >>> ", $NF); $0 = $NF; printf "%02d%02d\n", $1, $2; exit }'
> > >> 
> > >> And still over 80 chars before we assign it to a variable.  I
> > >> could get it to 77 chars with all whitespace removed.
> > > 
> > > which is why i unrolled it to make it readable.  i don't know what
> > > metrics you're using here, but i don't think the awk version is
> > > "longer" by really any of them.
> > 
> > The metric of 'wc -c' and "what fits in a single line, unwrapped on an
> > 80x24 terminal."  awk is great and awesome, don't get me wrong, but
> > it's not doing the job as compactly as the original.
> 
> obviously i disagree.  i find the awk version "better" in just about every way.  
> maybe someone else will jump in with their favorite bike.

As the original author I don't really care either way, I only care
about working around the assembler bug so I can turn on thumb for
tegra.  But maybe I'll rewrite it in prolog just to mess with you guys
:^)

-Allen
Graeme Russ - Aug. 1, 2012, 10:55 p.m.
Hi Allen,

On Thu, Aug 2, 2012 at 8:46 AM, Allen Martin <amartin@nvidia.com> wrote:

[snip]

> As the original author I don't really care either way, I only care
> about working around the assembler bug so I can turn on thumb for
> tegra.  But maybe I'll rewrite it in prolog just to mess with you guys
> :^)

Honestly, I prefer the original version - It clearly shows what the code
is doing. I'm not an awk god, and I find it really difficult to figure
out what half of the fancy scripts littered about the Makefiles actually
do. If it doesn't impact on performance, I prefer clarity (to non awk
god-like creatures) the compactness.

Just my $0.02 worth

Regards,

Graeme
Mike Frysinger - Aug. 1, 2012, 11:01 p.m.
On Wednesday 01 August 2012 18:46:18 Allen Martin wrote:
> But maybe I'll rewrite it in prolog just to mess with you guys

i'd ack it if it were written in bf
-mike
Allen Martin - Aug. 2, 2012, 5:12 p.m.
On Wed, Aug 01, 2012 at 04:01:41PM -0700, Mike Frysinger wrote:
> On Wednesday 01 August 2012 18:46:18 Allen Martin wrote:
> > But maybe I'll rewrite it in prolog just to mess with you guys
> 
> i'd ack it if it were written in bf
> -mike
> 

Challenge accepted

#!/bin/sh
#
# binutils-version [-p] gas-command
#
# Prints the binutils version of `gas-command' in a canonical 4-digit
#form
# such as `0222' for binutils 2.22
#

gas="$*"

if [ ${#gas} -eq 0 ]; then
        echo "Error: No assembler specified."
        printf "Usage:\n\t$0 <gas-command>\n"
        exit 1
fi

tmp=$(mktemp)
echo '>>++++[<++++++++>-]>>+++++[>+++++++++<-]>+>,[>>++++[<++++++++>-]>>+++++[>\
+++++++++<-]>+>,]<<<<<<[<<<<<<]>>>>>>[<[<+>-]>[<<-<+>>>-]<<<[>>>+<<<-]>[>+<[-]]\
>>>>>>>>]<<<<<<[<<<<<<]>>>>>[>>>>>>]><<<<<<<<<<<<[-]<[-]++++++[>++++++++<-]>.>>\
>>>>.>>>>>>>>>>>>.>>>>>>.' > $tmp
$gas --version | bf -n $tmp
rm $tmp

-Allen
Wolfgang Denk - Aug. 2, 2012, 7:30 p.m.
Dear Allen Martin,

In message <20120802171230.GC7791@nvidia.com> you wrote:
>
> Challenge accepted
...
> tmp=$(mktemp)
> echo '>>++++[<++++++++>-]>>+++++[>+++++++++<-]>+>,[>>++++[<++++++++>-]>>+++++[>\
> +++++++++<-]>+>,]<<<<<<[<<<<<<]>>>>>>[<[<+>-]>[<<-<+>>>-]<<<[>>>+<<<-]>[>+<[-]]\
> >>>>>>>>]<<<<<<[<<<<<<]>>>>>[>>>>>>]><<<<<<<<<<<<[-]<[-]++++++[>++++++++<-]>.>>\
> >>>>.>>>>>>>>>>>>.>>>>>>.' > $tmp

Thanks.  Registered as entry # 1 for the IOUCC.

Best regards,

Wolfgang Denk

Patch

diff --git a/config.mk b/config.mk
index 3dcea6a..919b77d 100644
--- a/config.mk
+++ b/config.mk
@@ -128,6 +128,7 @@  endif
 # cc-version
 # Usage gcc-ver := $(call cc-version)
 cc-version = $(shell $(SHELL) $(SRCTREE)/tools/gcc-version.sh $(CC))
+binutils-version = $(shell $(SHELL) $(SRCTREE)/tools/binutils-version.sh $(AS))
 
 #
 # Include the make variables (CC, etc...)
diff --git a/tools/binutils-version.sh b/tools/binutils-version.sh
new file mode 100755
index 0000000..d4d9eb4
--- /dev/null
+++ b/tools/binutils-version.sh
@@ -0,0 +1,20 @@ 
+#!/bin/sh
+#
+# binutils-version [-p] gas-command
+#
+# Prints the binutils version of `gas-command' in a canonical 4-digit form
+# such as `0222' for binutils 2.22
+#
+
+gas="$*"
+
+if [ ${#gas} -eq 0 ]; then
+	echo "Error: No assembler specified."
+	printf "Usage:\n\t$0 <gas-command>\n"
+	exit 1
+fi
+
+MAJOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 1)
+MINOR=$($gas --version | head -1 | awk '{print $NF}' | cut -d . -f 2)
+
+printf "%02d%02d\\n" $MAJOR $MINOR