All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Schier <nicolas@fjasle.eu>
To: Masahiro Yamada <masahiroy@kernel.org>
Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>
Subject: Re: [PATCH v2 3/5] kbuild: add read-file macro
Date: Wed, 23 Nov 2022 22:01:32 +0100	[thread overview]
Message-ID: <Y36KLFArg5etHRD8@bergen.fjasle.eu> (raw)
In-Reply-To: <20221123151828.509565-3-masahiroy@kernel.org>

[-- Attachment #1: Type: text/plain, Size: 3614 bytes --]

On Thu 24 Nov 2022 00:18:26 GMT, Masahiro Yamada wrote:
> Since GMU Make 4.2, $(file ...) supports the read operater '<', which is
> useful to read a file without forking any process. No warning is shown even
> if the input file is missing.
> 
> For older Make versions, it falls back to the cat command.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> 
> (no changes since v1)
> 
>  Makefile                  |  2 +-
>  scripts/Kbuild.include    | 12 ++++++++++++
>  scripts/Makefile.modfinal |  2 +-
>  scripts/Makefile.modinst  |  2 +-
>  4 files changed, 15 insertions(+), 3 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index eb80332f7b51..60ce9dcafc72 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -369,7 +369,7 @@ else # !mixed-build
>  include $(srctree)/scripts/Kbuild.include
>  
>  # Read KERNELRELEASE from include/config/kernel.release (if it exists)
> -KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
> +KERNELRELEASE = $(call read-file, include/config/kernel.release)
>  KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
>  export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
>  
> diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
> index 9996f34327cb..722846c23264 100644
> --- a/scripts/Kbuild.include
> +++ b/scripts/Kbuild.include
> @@ -10,6 +10,10 @@ empty   :=
>  space   := $(empty) $(empty)
>  space_escape := _-_SPACE_-_
>  pound := \#
> +define newline
> +
> +
> +endef
>  
>  ###
>  # Comparison macros.
> @@ -55,6 +59,14 @@ stringify = $(squote)$(quote)$1$(quote)$(squote)
>  kbuild-dir = $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
>  kbuild-file = $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile)
>  
> +###
> +# Read a file, replacing newlines with spaces
> +ifeq ($(call test-ge, $(MAKE_VERSION), 4.2),y)
> +read-file = $(subst $(newline),$(space),$(file < $1))
> +else
> +read-file = $(shell cat $1 2>/dev/null)
> +endif
> +

I like the implementation of read-file, but I am afraid that the 
MAKE_VERSION comparison breaks all make versions w/ a minor version 
number: 3.99.9x, 4.2.x, 4.3.x.

Not beautiful, but this might possibly work:
  ifneq ($(filter 3.% 4.0 4.0.% 4.1 4.1.%,$(MAKE_VERSION)),)
  read-file = ...


Kind regards,
Nicolas


>  ###
>  # Easy method for doing a status message
>         kecho := :
> diff --git a/scripts/Makefile.modfinal b/scripts/Makefile.modfinal
> index 25bedd83644b..7252f6cf7837 100644
> --- a/scripts/Makefile.modfinal
> +++ b/scripts/Makefile.modfinal
> @@ -13,7 +13,7 @@ include $(srctree)/scripts/Kbuild.include
>  include $(srctree)/scripts/Makefile.lib
>  
>  # find all modules listed in modules.order
> -modules := $(sort $(shell cat $(MODORDER)))
> +modules := $(sort $(call read-file, $(MODORDER)))
>  
>  __modfinal: $(modules)
>  	@:
> diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst
> index a4c987c23750..509d424dbbd2 100644
> --- a/scripts/Makefile.modinst
> +++ b/scripts/Makefile.modinst
> @@ -9,7 +9,7 @@ __modinst:
>  include include/config/auto.conf
>  include $(srctree)/scripts/Kbuild.include
>  
> -modules := $(sort $(shell cat $(MODORDER)))
> +modules := $(sort $(call read-file, $(MODORDER)))
>  
>  ifeq ($(KBUILD_EXTMOD),)
>  dst := $(MODLIB)/kernel
> -- 
> 2.34.1

-- 
epost|xmpp: nicolas@fjasle.eu          irc://oftc.net/nsc
↳ gpg: 18ed 52db e34f 860e e9fb  c82b 7d97 0932 55a0 ce7f
     -- frykten for herren er opphav til kunnskap --

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2022-11-23 21:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 15:18 [PATCH v2 1/5] kbuild: add test-{le,ge,lt,gt} macros Masahiro Yamada
2022-11-23 15:18 ` Masahiro Yamada
2022-11-23 15:18 ` [PATCH v2 2/5] kbuild: implement {gcc,clang}-min-version only with built-in functions Masahiro Yamada
2022-11-23 20:37   ` Nicolas Schier
2022-11-23 21:17     ` Masahiro Yamada
2022-11-23 15:18 ` [PATCH v2 3/5] kbuild: add read-file macro Masahiro Yamada
2022-11-23 21:01   ` Nicolas Schier [this message]
2022-11-23 21:52     ` Masahiro Yamada
2022-11-24  4:45       ` Nicolas Schier
2022-11-23 15:18 ` [PATCH v2 4/5] kconfig: refactor Makefile to reduce process forks Masahiro Yamada
2022-11-23 21:14   ` Nicolas Schier
2022-11-23 15:18 ` [PATCH v2 5/5] kbuild: check Make version Masahiro Yamada
2022-11-23 21:19   ` Nicolas Schier
2022-11-24  7:08     ` Nicolas Schier
2022-11-23 20:05 ` [PATCH v2 1/5] kbuild: add test-{le,ge,lt,gt} macros Nicolas Schier
2022-11-23 20:05   ` Nicolas Schier
2022-12-02 17:56 ` Palmer Dabbelt
2022-12-02 17:56   ` Palmer Dabbelt
2022-12-08  1:42 ` Masahiro Yamada
2022-12-08  1:42   ` Masahiro Yamada

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=Y36KLFArg5etHRD8@bergen.fjasle.eu \
    --to=nicolas@fjasle.eu \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.