diff mbox series

[L/unstable,06/13] UBUNTU: [Packaging] simplify custom_override

Message ID 20221205085619.257813-7-masahiro.yamada@canonical.com
State New
Headers show
Series [L/unstable,01/13] UBUNTU: [Packaging] mark phony targets | expand

Commit Message

Masahiro Yamada Dec. 5, 2022, 8:56 a.m. UTC
You do not need to invoke the shell for if/else choice.

You can do it by using the $(if ...) built-in function.

  $(if $($(1)_$(2)),$($(1)_$(2)),$($(1)))

GNU Make >= 3.81 supports $(or ...), so the code can be even simpler:

  $(or $($(1)_$(2)),$($(1)))

No functional change is intended.

Signed-off-by: Masahiro Yamada <masahiro.yamada@canonical.com>
---
 debian/rules.d/0-common-vars.mk | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Juerg Haefliger Dec. 7, 2022, 6:54 a.m. UTC | #1
On Mon,  5 Dec 2022 17:56:12 +0900
Masahiro Yamada <masahiro.yamada@canonical.com> wrote:

> You do not need to invoke the shell for if/else choice.
> 
> You can do it by using the $(if ...) built-in function.
> 
>   $(if $($(1)_$(2)),$($(1)_$(2)),$($(1)))
> 
> GNU Make >= 3.81 supports $(or ...), so the code can be even simpler:
> 
>   $(or $($(1)_$(2)),$($(1)))
> 
> No functional change is intended.
> 
> Signed-off-by: Masahiro Yamada <masahiro.yamada@canonical.com>
> ---
>  debian/rules.d/0-common-vars.mk | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/debian/rules.d/0-common-vars.mk b/debian/rules.d/0-common-vars.mk
> index a54b83dd943b..ec9c5680493b 100644
> --- a/debian/rules.d/0-common-vars.mk
> +++ b/debian/rules.d/0-common-vars.mk
> @@ -278,8 +278,7 @@ LN = ln -sf
>  
>  # Checks if a var is overriden by the custom rules. Called with var and
>  # flavour as arguments.
> -custom_override = \
> - $(shell if [ -n "$($(1)_$(2))" ]; then echo "$($(1)_$(2))"; else echo "$($(1))"; fi)
> +custom_override = $(or $($(1)_$(2)),$($(1)))

Maybe add a note/comment what this is doing.

...Juerg

  
>  # selftests that Ubuntu cares about
>  ubuntu_selftests = breakpoints cpu-hotplug efivarfs memfd memory-hotplug mount net ptrace seccomp timers powerpc user ftrace
Masahiro Yamada Dec. 7, 2022, 9:10 a.m. UTC | #2
On Wed, Dec 7, 2022 at 3:54 PM Juerg Haefliger
<juerg.haefliger@canonical.com> wrote:
>
> On Mon,  5 Dec 2022 17:56:12 +0900
> Masahiro Yamada <masahiro.yamada@canonical.com> wrote:
>
> > You do not need to invoke the shell for if/else choice.
> >
> > You can do it by using the $(if ...) built-in function.
> >
> >   $(if $($(1)_$(2)),$($(1)_$(2)),$($(1)))
> >
> > GNU Make >= 3.81 supports $(or ...), so the code can be even simpler:
> >
> >   $(or $($(1)_$(2)),$($(1)))
> >
> > No functional change is intended.
> >
> > Signed-off-by: Masahiro Yamada <masahiro.yamada@canonical.com>
> > ---
> >  debian/rules.d/0-common-vars.mk | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/debian/rules.d/0-common-vars.mk b/debian/rules.d/0-common-vars.mk
> > index a54b83dd943b..ec9c5680493b 100644
> > --- a/debian/rules.d/0-common-vars.mk
> > +++ b/debian/rules.d/0-common-vars.mk
> > @@ -278,8 +278,7 @@ LN = ln -sf
> >
> >  # Checks if a var is overriden by the custom rules. Called with var and
> >  # flavour as arguments.
> > -custom_override = \
> > - $(shell if [ -n "$($(1)_$(2))" ]; then echo "$($(1)_$(2))"; else echo "$($(1))"; fi)
> > +custom_override = $(or $($(1)_$(2)),$($(1)))
>
> Maybe add a note/comment what this is doing.




I do not know your expectations.


It is already commented as

# Checks if a var is overriden by the custom rules. Called with var and
# flavour as arguments.






> ...Juerg
>
>
> >  # selftests that Ubuntu cares about
> >  ubuntu_selftests = breakpoints cpu-hotplug efivarfs memfd memory-hotplug mount net ptrace seccomp timers powerpc user ftrace
>
Juerg Haefliger Dec. 7, 2022, 1:50 p.m. UTC | #3
On Wed, 7 Dec 2022 18:10:41 +0900
Masahiro Yamada <masahiro.yamada@canonical.com> wrote:

> On Wed, Dec 7, 2022 at 3:54 PM Juerg Haefliger
> <juerg.haefliger@canonical.com> wrote:
> >
> > On Mon,  5 Dec 2022 17:56:12 +0900
> > Masahiro Yamada <masahiro.yamada@canonical.com> wrote:
> >  
> > > You do not need to invoke the shell for if/else choice.
> > >
> > > You can do it by using the $(if ...) built-in function.
> > >
> > >   $(if $($(1)_$(2)),$($(1)_$(2)),$($(1)))
> > >
> > > GNU Make >= 3.81 supports $(or ...), so the code can be even simpler:
> > >
> > >   $(or $($(1)_$(2)),$($(1)))
> > >
> > > No functional change is intended.
> > >
> > > Signed-off-by: Masahiro Yamada <masahiro.yamada@canonical.com>
> > > ---
> > >  debian/rules.d/0-common-vars.mk | 3 +--
> > >  1 file changed, 1 insertion(+), 2 deletions(-)
> > >
> > > diff --git a/debian/rules.d/0-common-vars.mk b/debian/rules.d/0-common-vars.mk
> > > index a54b83dd943b..ec9c5680493b 100644
> > > --- a/debian/rules.d/0-common-vars.mk
> > > +++ b/debian/rules.d/0-common-vars.mk
> > > @@ -278,8 +278,7 @@ LN = ln -sf
> > >
> > >  # Checks if a var is overriden by the custom rules. Called with var and
> > >  # flavour as arguments.
> > > -custom_override = \
> > > - $(shell if [ -n "$($(1)_$(2))" ]; then echo "$($(1)_$(2))"; else echo "$($(1))"; fi)
> > > +custom_override = $(or $($(1)_$(2)),$($(1)))  
> >
> > Maybe add a note/comment what this is doing.  
> 
> 
> 
> 
> I do not know your expectations.

That this $(or ...) is equivalent to an if..then..else. It's not obvious to
me, but maybe that's just me. Just a suggestion.

...Juerg

 
> 
> It is already commented as
> 
> # Checks if a var is overriden by the custom rules. Called with var and
> # flavour as arguments.
> 
> 
> 
> 
> 
> 
> > ...Juerg
> >
> >  
> > >  # selftests that Ubuntu cares about
> > >  ubuntu_selftests = breakpoints cpu-hotplug efivarfs memfd memory-hotplug mount net ptrace seccomp timers powerpc user ftrace  
> >
Masahiro Yamada Dec. 8, 2022, 1:01 a.m. UTC | #4
On Wed, Dec 7, 2022 at 10:50 PM Juerg Haefliger
<juerg.haefliger@canonical.com> wrote:
>
> On Wed, 7 Dec 2022 18:10:41 +0900
> Masahiro Yamada <masahiro.yamada@canonical.com> wrote:
>
> > On Wed, Dec 7, 2022 at 3:54 PM Juerg Haefliger
> > <juerg.haefliger@canonical.com> wrote:
> > >
> > > On Mon,  5 Dec 2022 17:56:12 +0900
> > > Masahiro Yamada <masahiro.yamada@canonical.com> wrote:
> > >
> > > > You do not need to invoke the shell for if/else choice.
> > > >
> > > > You can do it by using the $(if ...) built-in function.
> > > >
> > > >   $(if $($(1)_$(2)),$($(1)_$(2)),$($(1)))
> > > >
> > > > GNU Make >= 3.81 supports $(or ...), so the code can be even simpler:
> > > >
> > > >   $(or $($(1)_$(2)),$($(1)))
> > > >
> > > > No functional change is intended.
> > > >
> > > > Signed-off-by: Masahiro Yamada <masahiro.yamada@canonical.com>
> > > > ---
> > > >  debian/rules.d/0-common-vars.mk | 3 +--
> > > >  1 file changed, 1 insertion(+), 2 deletions(-)
> > > >
> > > > diff --git a/debian/rules.d/0-common-vars.mk b/debian/rules.d/0-common-vars.mk
> > > > index a54b83dd943b..ec9c5680493b 100644
> > > > --- a/debian/rules.d/0-common-vars.mk
> > > > +++ b/debian/rules.d/0-common-vars.mk
> > > > @@ -278,8 +278,7 @@ LN = ln -sf
> > > >
> > > >  # Checks if a var is overriden by the custom rules. Called with var and
> > > >  # flavour as arguments.
> > > > -custom_override = \
> > > > - $(shell if [ -n "$($(1)_$(2))" ]; then echo "$($(1)_$(2))"; else echo "$($(1))"; fi)
> > > > +custom_override = $(or $($(1)_$(2)),$($(1)))
> > >
> > > Maybe add a note/comment what this is doing.
> >
> >
> >
> >
> > I do not know your expectations.
>
> That this $(or ...) is equivalent to an if..then..else. It's not obvious to
> me, but maybe that's just me. Just a suggestion.
>
> ...Juerg
>





I do not think we need comments for builtin functions
because they are explained in the manual.


FWIW, here is the explanation of $(or ...) function.

https://www.gnu.org/software/make/manual/make.html#Conditional-Functions











> >
> > It is already commented as
> >
> > # Checks if a var is overriden by the custom rules. Called with var and
> > # flavour as arguments.
> >
> >
> >
> >
> >
> >
> > > ...Juerg
> > >
> > >
> > > >  # selftests that Ubuntu cares about
> > > >  ubuntu_selftests = breakpoints cpu-hotplug efivarfs memfd memory-hotplug mount net ptrace seccomp timers powerpc user ftrace
> > >
>
diff mbox series

Patch

diff --git a/debian/rules.d/0-common-vars.mk b/debian/rules.d/0-common-vars.mk
index a54b83dd943b..ec9c5680493b 100644
--- a/debian/rules.d/0-common-vars.mk
+++ b/debian/rules.d/0-common-vars.mk
@@ -278,8 +278,7 @@  LN = ln -sf
 
 # Checks if a var is overriden by the custom rules. Called with var and
 # flavour as arguments.
-custom_override = \
- $(shell if [ -n "$($(1)_$(2))" ]; then echo "$($(1)_$(2))"; else echo "$($(1))"; fi)
+custom_override = $(or $($(1)_$(2)),$($(1)))
 
 # selftests that Ubuntu cares about
 ubuntu_selftests = breakpoints cpu-hotplug efivarfs memfd memory-hotplug mount net ptrace seccomp timers powerpc user ftrace