From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: Dominique Martinet <asmadeus@codewreck.org>,
Masahiro Yamada <masahiroy@kernel.org>,
Michal Marek <michal.lkml@markovi.net>,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] kbuild: rewrite ld-version.sh in shell script
Date: Sun, 13 Dec 2020 01:54:31 +0900 [thread overview]
Message-ID: <20201212165431.150750-3-masahiroy@kernel.org> (raw)
In-Reply-To: <20201212165431.150750-1-masahiroy@kernel.org>
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 8083013fc320 ("ld-version: Fix it on Fedora")
- GNU ld (GNU Binutils) 2.20.1.20100303
as reported by commit 0d61ed17dd30 ("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>
---
init/Kconfig | 2 +-
scripts/Kbuild.include | 6 +-----
scripts/ld-version.sh | 31 +++++++++++++++++++++----------
3 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/init/Kconfig b/init/Kconfig
index 0872a5a2e759..a44a13a6b38d 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -35,7 +35,7 @@ config GCC_VERSION
config LD_VERSION
int
- default $(shell,$(LD) --version | $(srctree)/scripts/ld-version.sh)
+ default $(shell,$(srctree)/scripts/ld-version.sh $(LD))
config CC_IS_CLANG
def_bool $(success,echo "$(CC_VERSION_TEXT)" | grep -q clang)
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 08e011175b4c..167a68bbe7be 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -141,13 +141,9 @@ cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || e
# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y)
ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3))
-# ld-version
-# Note this is mainly for HJ Lu's 3 number binutil versions
-ld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh)
-
# ld-ifversion
# Usage: $(call ld-ifversion, -ge, 22252, y)
-ld-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4))
+ld-ifversion = $(shell [ $(CONFIG_LD_VERSION) $(1) $(2) ] && echo $(3) || echo $(4))
######
diff --git a/scripts/ld-version.sh b/scripts/ld-version.sh
index 0f8a2c0f9502..c214aeb3200d 100755
--- a/scripts/ld-version.sh
+++ b/scripts/ld-version.sh
@@ -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
--
2.27.0
next prev parent reply other threads:[~2020-12-12 16:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-12 16:54 [PATCH 1/3] kbuild: do not use scripts/ld-version.sh for checking spatch version Masahiro Yamada
2020-12-12 16:54 ` [PATCH 2/3] kbuild: LD_VERSION redenomination Masahiro Yamada
2020-12-14 23:05 ` Will Deacon
2020-12-15 13:48 ` Thomas Bogendoerfer
2021-01-28 6:38 ` Masahiro Yamada
2020-12-12 16:54 ` Masahiro Yamada [this message]
2020-12-12 17:48 ` [PATCH 3/3] kbuild: rewrite ld-version.sh in shell script Dominique Martinet
2020-12-21 14:23 ` Masahiro Yamada
2020-12-12 20:21 ` kernel test robot
2020-12-12 20:53 ` kernel test robot
2020-12-12 21:42 ` kernel test robot
2020-12-12 21:47 ` David Laight
2020-12-21 14:29 ` Masahiro Yamada
2020-12-21 14:51 ` David Laight
2020-12-12 17:30 ` [Cocci] [PATCH 1/3] kbuild: do not use scripts/ld-version.sh for checking spatch version Julia Lawall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201212165431.150750-3-masahiroy@kernel.org \
--to=masahiroy@kernel.org \
--cc=asmadeus@codewreck.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.lkml@markovi.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).