forked from torvalds/linux
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
kbuild: rewrite ld-version.sh in shell script
This script was written in awk in spite of the file extension '.sh'. Rewrite it as a shell script. The code was mostly copy-pasted from scripts/lld-version.sh. The two scripts can be merged, but I am keeping this as a separate file for now. I tested this script for some corner cases reported in the past: - GNU ld version 2.25-15.fc23 as reported by commit 8083013 ("ld-version: Fix it on Fedora") - GNU ld (GNU Binutils) 2.20.1.20100303 as reported by commit 0d61ed1 ("ld-version: Drop the 4th and 5th version components") I also cleaned up the macros in scripts/Kbuild.include. Remove ld-version, which has no direct user. You can use CONFIG_LD_VERSION if you need the version string in a Makefile. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
- Loading branch information
1 parent
ed4e8b2
commit 0eab60f5e1f804528a4d0dd9566cb30f62242d22
Showing
3 changed files
with
23 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,22 @@ | ||
| #!/usr/bin/awk -f | ||
| #!/bin/sh | ||
| # SPDX-License-Identifier: GPL-2.0 | ||
| # extract linker version number from stdin and turn into single number | ||
| { | ||
| gsub(".*\\)", ""); | ||
| gsub(".*version ", ""); | ||
| gsub("-.*", ""); | ||
| split($1,a, "."); | ||
| print a[1]*10000 + a[2]*100 + a[3]; | ||
| exit | ||
| } | ||
| # | ||
| # 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 |