Re: [PATCH 3/3] kbuild: rewrite ld-version.sh in shell script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Dec 13, 2020 at 6:47 AM David Laight <David.Laight@xxxxxxxxxx> wrote:
>
> From: Masahiro Yamada
> > Sent: 12 December 2020 16:55
> >
> > This script was written in awk in spite of the file extension '.sh'.
> > Rewrite it as a shell script.
> ...
> > +#
> > +# Usage: $ ./scripts/ld-version.sh ld
> > +#
> > +# Print the linker version of `ld' in a 5 or 6-digit form
> > +# such as `23501' for GNU ld 2.35.1 etc.
> > +
> > +first_line="$($* --version | head -n 1)"
> > +
> > +if ! ( echo $first_line | grep -q "GNU ld"); then
> > +     echo 0
> > +     exit 1
> > +fi
> > +
> > +# Distributions may append an extra string like 2.35-15.fc33
> > +# Take the part that consists of numbers and dots.
> > +VERSION=$(echo $first_line | sed 's/.* \([^ ]*\)$/\1/' | sed 's/^\(^[0-9.]*\).*/\1/')
> > +MAJOR=$(echo $VERSION | cut -d . -f 1)
> > +MINOR=$(echo $VERSION | cut -d . -f 2)
> > +PATCHLEVEL=$(echo $VERSION | cut -d . -f 3)
> > +printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL
>
>
> Hmmmm.....
> You've managed to convert an awk script into something that requires
> sh, head, grep, sed (twice), and cut (thrice).
> Plus (probably) a few sub-shells.
>
> It is quite ease to do it all in all in the shell.
>
>         David
>

OK, please rewrite the code.



-- 
Best Regards
Masahiro Yamada



[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux