Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1943364pxu; Sun, 13 Dec 2020 08:19:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJyiPzH2WdjUdcZ7BdYoxotLWoRNhCCiU4FIEDcURbZPfwzaPIkoKRsu20Uof3xXIGhaLjgP X-Received: by 2002:aa7:c749:: with SMTP id c9mr6849156eds.3.1607876380741; Sun, 13 Dec 2020 08:19:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607876380; cv=none; d=google.com; s=arc-20160816; b=tlvyZ/98YUQGTi69/4EVi8tFKlA/XdsONoTU6fdLkY5SHhG4XaEDBkS3s1Rqopr7et mMcAIeMyMUINXU+QwL9ut305PvxPV55/RoKzM4yd+Ap9ioLX+MieAIzZ/wdFmScWObFU IA8swTQwNWIaPNW94Xu6qYz8lKKscA+tag++3cKDJvEzB90t4quq04mA6bR26lU4b6J7 5vq7pXuh7HbCTglyF9enDG9U/e7lT4aIbgx78rnhafJF22pXqPBVa81JMMVQaba7GU0k el++EjUrhw7pobFU9jAKRvZ6O682AMpJnfArY1OEKB/6SojKYPJVAqLOBe5oCDvNuOoy G12A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=dpgq5RZvPfHgfloxAHMCr/hKbK6506wPMQVyOXg27a0=; b=CO/5hdv+JI8B6f6XZwdeBCLYh4vTzyA2yMHfgi135R7qljPjBmzLP/EwZeL1hKR95G atGBpD/RYzPKoZMXpR5FfRb9BxQWODvDf9BntAzsl35F5OP3NgLIukOnJuIhmTfcQyDh xPaV7glYOpunqs81STIeA6Q7pRCBiqdFeOBG/EXR8RhxPsfDnz5kIROJNWbxwVTOkVT3 o8FdqYb09o5bN38LecvQodgPaNNfNvigz+r8qOnvyug7Aai3Ljx1Ilzby/a8ojmmmYgR 0V0uicRIiNaOqi5CAkoiKFARLzELisWJ80FNXhOpldRP9OnWb45pS1yJBGlaRJ1cchl0 y7jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=eLWAba1x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mf27si8359105ejb.129.2020.12.13.08.19.16; Sun, 13 Dec 2020 08:19:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=eLWAba1x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404268AbgLLQzo (ORCPT + 99 others); Sat, 12 Dec 2020 11:55:44 -0500 Received: from conuserg-10.nifty.com ([210.131.2.77]:45143 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395531AbgLLQzo (ORCPT ); Sat, 12 Dec 2020 11:55:44 -0500 Received: from grover.flets-west.jp (softbank126090211135.bbtec.net [126.90.211.135]) (authenticated) by conuserg-10.nifty.com with ESMTP id 0BCGsX0Q010674; Sun, 13 Dec 2020 01:54:36 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com 0BCGsX0Q010674 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1607792077; bh=dpgq5RZvPfHgfloxAHMCr/hKbK6506wPMQVyOXg27a0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eLWAba1xRxtIa7MFfcp2kJuxBE5U0DAYaZ9omDn9VY0Lkc6ytCRVNmtS7NI7RBZoz UyFDx7+CBvaw69rlFWbbG9QjazZ3eSLO5lUHTYhG26QsIdw91o6bLg08GGM7n2KbZ4 BAxIb6YfnDgaBQj1lRs+T9TyyBdTrf81eCl2WV+uHY5ABzzzZYJrrlI6IdMu+xWaKs H27OiuWwE/9gFqP0DjLE033cAe95m/Pc34EqELipwyhMB09JYxduapwA9g3Wc+tIzW 5xmTXSAd2G9LNVSHgPvuWQd6j0gBLzLLXJ5dAkhkLlbndk9gNiI9PgguhvRiiY0T9d 6HQ97R3ogK6aA== X-Nifty-SrcIP: [126.90.211.135] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Dominique Martinet , Masahiro Yamada , Michal Marek , 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 Message-Id: <20201212165431.150750-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201212165431.150750-1-masahiroy@kernel.org> References: <20201212165431.150750-1-masahiroy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.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 --- 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