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.
Quoted 1 line
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
Quoted 1 line · Sam Ravnborg
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
Signature · 2 lines
Muli Ben-Yehuda http://www.mulix.org | http://mulix.livejournal.com/
Quoted 9 lines
We have in several cases the need to transpose a i'm' to 'y' in the
Kbuildfiles.
One example is the following snippet fromsound/Makefile:
ifeq ($(CONFIG_SND),y)
obj-y += last.o
endifAlternative 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..
Quoted 6 lines
ifeq ($(CONFIG_FB),y)
obj-$(CONFIG_PPC) += macmodes.o
endifAltetnative 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
Quoted 5 lines · Christoph Hellwig
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
Quoted 7 lines · Sam Ravnborg
Quoted 5 lines · Christoph Hellwig
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
Quoted 6 lines
The real problem is when say
CONFIG_FBare empty. Then kbuild will see:
obj-$(CONFIG_PPC) which I doubt was what you wanted.This can be fixed by changing
Kconfigto 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.
Signature · 4 lines
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 coreQuoted 7 lines · Russell King
This can be fixed by changing
Kconfigto evaluate all known symbols toQuoted 2 lines
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
Kconfigfiles (including all architecture specific ones) are read? Eg,CONFIG_PPCwouldn'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
Quoted 9 lines · Sam Ravnborg
We have in several cases the need to transpose a i'm' to 'y' in the
Kbuildfiles.
One example is the following snippet fromsound/Makefile:
ifeq ($(CONFIG_SND),y)
obj-y += last.o
endifAlternative 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.
Quoted 4 lines
From
drivers/vidoe/Makfile:
ifeq ($(CONFIG_FB),y)
obj-$(CONFIG_PPC) += macmodes.o
endif
macmodes-$(CONFIG_FB) := macmodes.o
obj-$(CONFIG_PPC) += $(macmodes-y)
Quoted 2 lines
ym2y
ym2m
tmp-$(CONFIG_FOO) := foo.o
tmp-$(CONFIG_BAR) := $(tmp-y)
obj-m += $(tmp-m)
Quoted 2 lines
empty2y
empty2m
tmp-$(CONFIG_FOO) := foo.o
obj-m += $(tmp-) $(tmp-n)
Quoted 8 lines
y2y
m2y
y2m
m2m
yx2x
mx2xWould 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 <><
Quoted 3 lines · Arnd Bergmann
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
Quoted 2 lines · Sam Ravnborg
We have in several cases the need to transpose a i'm' to 'y' in the
Kbuildfiles.
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
Quoted 21 lines
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
Quoted 1 line
Would that be considered usefull?
That would take the kbuild makefile obfuscation contest to the next level. Who should understand that stuff?
Cheers,
Signature · 2 lines
Andreas Gruenbacher <[email protected]> SUSE Labs, SUSE LINUX PRODUCTS GMBH