2005-01-30 19:35:54

by Sam Ravnborg

[permalink] [raw]
Subject: kbuild: shorthand ym2y, ym2m etc

We have in several cases the need to transpose a i'm' to 'y' in the Kbuild
files.
One example is the following snippet from sound/Makefile:
ifeq ($(CONFIG_SND),y)
obj-y += last.o
endif

Alternative syntax could be:
obj-$(call y2y,CONFIG_SND) += last.o


y2y takes one parameter and return y unly if parameter is y, otherwise
return nothing.


>From drivers/vidoe/Makfile:
ifeq ($(CONFIG_FB),y)
obj-$(CONFIG_PPC) += macmodes.o
endif

Altetnative syntax:
obj-$(call yx2x,CONFIG_FB,CONFIG_PPC) += mcmodes.o

yx2x return second parameter (x) if first parameter is y. Otherwise
nothing is returned.

To be complete the full set would be:

ym2y
ym2m
empty2y
empty2m
y2y
m2y
y2m
m2m
yx2x
mx2x

Would that be considered usefull?

Sam


2005-01-30 19:46:40

by Muli Ben-Yehuda

[permalink] [raw]
Subject: Re: kbuild: shorthand ym2y, ym2m etc

On Sun, Jan 30, 2005 at 08:37:33PM +0100, Sam Ravnborg wrote:

> Would that be considered usefull?

IMHO, no. Small languages are only useful when they are more
descriptive than the alternative. In this case, you are replacing two
obvious lines with one entirely not obvious line, causing the Makefile
to become less readable.

Cheers,
Muli
--
Muli Ben-Yehuda
http://www.mulix.org | http://mulix.livejournal.com/


Attachments:
(No filename) (416.00 B)
signature.asc (189.00 B)
Digital signature
Download all attachments

2005-01-30 19:52:35

by Christoph Hellwig

[permalink] [raw]
Subject: Re: kbuild: shorthand ym2y, ym2m etc

> We have in several cases the need to transpose a i'm' to 'y' in the Kbuild
> files.
> One example is the following snippet from sound/Makefile:
> ifeq ($(CONFIG_SND),y)
> obj-y += last.o
> endif
>
> Alternative syntax could be:
> obj-$(call y2y,CONFIG_SND) += last.o

This should go away with either syntax, and I don't think yours is much
cleaner..

> ifeq ($(CONFIG_FB),y)
> obj-$(CONFIG_PPC) += macmodes.o
> endif
>
> Altetnative syntax:
> obj-$(call yx2x,CONFIG_FB,CONFIG_PPC) += mcmodes.o

obj-$(CONFIG_FB)$(CONFIG_PPC) += macmodes.o

would be a lot more obvious, but I'm not sure how to handle
it for the case where one of them evaluates to m

2005-01-30 22:38:38

by Sam Ravnborg

[permalink] [raw]
Subject: Re: kbuild: shorthand ym2y, ym2m etc

On Sun, Jan 30, 2005 at 07:52:30PM +0000, Christoph Hellwig wrote:
>
> obj-$(CONFIG_FB)$(CONFIG_PPC) += macmodes.o
>
> would be a lot more obvious, but I'm not sure how to handle
> it for the case where one of them evaluates to m

The real problem is when say CONFIG_FB are empty. Then kbuild will see:
obj-$(CONFIG_PPC) which I doubt was what you wanted.

This can be fixed by changing Kconfig to evaluate all known symbols to
either y,m,n - in contradiction to today where symbols that evaluate
to n is left empty.

Sam

2005-01-30 22:44:59

by Russell King

[permalink] [raw]
Subject: Re: kbuild: shorthand ym2y, ym2m etc

On Sun, Jan 30, 2005 at 11:39:26PM +0100, Sam Ravnborg wrote:
> On Sun, Jan 30, 2005 at 07:52:30PM +0000, Christoph Hellwig wrote:
> >
> > obj-$(CONFIG_FB)$(CONFIG_PPC) += macmodes.o
> >
> > would be a lot more obvious, but I'm not sure how to handle
> > it for the case where one of them evaluates to m
>
> The real problem is when say CONFIG_FB are empty. Then kbuild will see:
> obj-$(CONFIG_PPC) which I doubt was what you wanted.
>
> This can be fixed by changing Kconfig to evaluate all known symbols to
> either y,m,n - in contradiction to today where symbols that evaluate
> to n is left empty.

Isn't that rather hard to achieve, unless all Kconfig files (including
all architecture specific ones) are read? Eg, CONFIG_PPC wouldn't
exist on ARM.

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 PCMCIA - http://pcmcia.arm.linux.org.uk/
2.6 Serial core

2005-01-30 22:49:57

by Sam Ravnborg

[permalink] [raw]
Subject: Re: kbuild: shorthand ym2y, ym2m etc

On Sun, Jan 30, 2005 at 10:44:52PM +0000, Russell King wrote:
> This can be fixed by changing Kconfig to evaluate all known symbols to
> > either y,m,n - in contradiction to today where symbols that evaluate
> > to n is left empty.
>
> Isn't that rather hard to achieve, unless all Kconfig files (including
> all architecture specific ones) are read? Eg, CONFIG_PPC wouldn't
> exist on ARM.

Exactly - thats why I wrote "all known".
I do not see this as the solution that solve more than it breaks.
So I have not even tried it out.

Sam

2005-01-30 22:52:07

by Arnd Bergmann

[permalink] [raw]
Subject: Re: kbuild: shorthand ym2y, ym2m etc

On S?nndag 30 Januar 2005 20:37, Sam Ravnborg wrote:
> We have in several cases the need to transpose a i'm' to 'y' in the Kbuild
> files.
> One example is the following snippet from sound/Makefile:
> ifeq ($(CONFIG_SND),y)
> obj-y += last.o
> endif
>
> Alternative syntax could be:
> obj-$(call y2y,CONFIG_SND) += last.o

You can already write this as

last-$(CONFIG_SND) := last.o
obj-y += $(last-y)

I'm not sure if this is better than the current version, but I'd
prefer it to using the extra function.

> From drivers/vidoe/Makfile:
> ifeq ($(CONFIG_FB),y)
> obj-$(CONFIG_PPC) += macmodes.o
> endif

macmodes-$(CONFIG_FB) := macmodes.o
obj-$(CONFIG_PPC) += $(macmodes-y)

> ym2y
> ym2m

tmp-$(CONFIG_FOO) := foo.o
tmp-$(CONFIG_BAR) := $(tmp-y)
obj-m += $(tmp-m)

> empty2y
> empty2m

tmp-$(CONFIG_FOO) := foo.o
obj-m += $(tmp-) $(tmp-n)

> y2y
> m2y
> y2m
> m2m
> yx2x
> mx2x
>
> Would that be considered usefull?

I don't fully understand what all those examples should do, so they
are probably not that intuitive. I'm pretty sure that we can already
express them all with either ifeq() or two assignments, though.
Both are already used in the kernel (see ipc/Makefile for an
example of yx2x), so maybe the preferred style should be documented
in CodingStyle.

Arnd <><


Attachments:
(No filename) (1.27 kB)
(No filename) (189.00 B)
signature
Download all attachments

2005-01-30 22:58:24

by Sam Ravnborg

[permalink] [raw]
Subject: Re: kbuild: shorthand ym2y, ym2m etc

On Sun, Jan 30, 2005 at 11:41:34PM +0100, Arnd Bergmann wrote:
> Both are already used in the kernel (see ipc/Makefile for an
> example of yx2x), so maybe the preferred style should be documented
> in CodingStyle.

Thanks for input

I will try to do something. But their home will be
Documentation/kbuild/makefiles.txt

Sam

2005-01-31 01:57:18

by Andreas Gruenbacher

[permalink] [raw]
Subject: Re: kbuild: shorthand ym2y, ym2m etc

On Sunday 30 January 2005 20:37, Sam Ravnborg wrote:
> We have in several cases the need to transpose a i'm' to 'y' in the Kbuild
> files.

I assume you mean what you write in the text rather than what the example
shows. If so, why not use this:

obj-$(CONFIG_SND:m=y) += last.o

> One example is the following snippet from sound/Makefile:
> ifeq ($(CONFIG_SND),y)
> obj-y += last.o
> endif
>
> [...]
>
> To be complete the full set would be:
>
> ym2y
> ym2m
> empty2y
> empty2m
> y2y
> m2y
> y2m
> m2m
> yx2x
> mx2x
>
>
> Would that be considered usefull?

That would take the kbuild makefile obfuscation contest to the next level. Who
should understand that stuff?

Cheers,
--
Andreas Gruenbacher <[email protected]>
SUSE Labs, SUSE LINUX PRODUCTS GMBH