diff mbox

[U-Boot,RFC,1/2] kbuild: add a makefile macro useful with per-image config options

Message ID 1437651116-3057-2-git-send-email-yamada.masahiro@socionext.com
State Superseded
Headers show

Commit Message

Masahiro Yamada July 23, 2015, 11:31 a.m. UTC
Commit e02ee2548afe ("kconfig: switch to single .config
configuration") made the configuration itself pretty simple,
instead, we lost the way to systematically enable/disable config
options for each image independently.

Our current strategy is, put entries into Makefile.spl for options
we need separate enabling, or once enable the options globally in
Kconfig and then undef them in Makefile.uncmd_spl if we do not want
to compile the features for SPL at all.  Things are getting really
messy.  Besides, "ifdef CONFIG_SPL_BUILD" are sprinkled everywhere
in makefiles.

This commit adds a macro to help describe makefile simpler, allowing
separate switch for U-boot main and SPL.

This macro takes a config option without the prefix CONFIG_.
$(call CONFIG,FOO) evaluates to
  $(CONFIG_FOO) if CONFIG_SPL_BUILD is undefined (U-boot build),
  $(CONFIG_SPL_FOO) if CONFIG_SPL_BUILD is defined (SPL_BUILD).

That is,

  $(call CONFIG,FOO) += foo.o

is a shorthand for

  ifdef CONFIG_SPL_BUILD
  obj-$(CONFIG_SPL_FOO) += foo.o
  else
  obj-$(CONFIG_FOO) += foo.o
  endif

If CONFIG_SPL_FOO does not exist in Kconfig, it is equivalent to

  ifndef CONFIG_SPL_BUILD
  obj-$(CONFIG_SPL_FOO) += foo.o
  endif

This is the pattern we often see in our current makefiles.

To take advantage of this macro, we should prefix SPL_ for the SPL
version of the option that we need independent control between
U-boot and SPL.  With this naming scheme, we only have to add a
single line in a Makefile for each config option.

It means we want to rename existing config options as follows
in the long run:

  CONFIG_SPL_SERIAL_SUPPORT     -> CONFIG_SPL_SERIAL
  CONFIG_SPL_I2C_SUPPORT        -> CONFIG_SPL_I2C
  CONFIG_SPL_GPIO_SUPPORT       -> CONFIG_SPL_GPIO
  CONFIG_SPL_SPI_SUPPORT        -> CONFIG_SPL_SPI
  CONFIG_SPL_DISABLE_OF_CONTROL -> CONFIG_SPL_OF_CONTROL
                                      (inverting the logic)

Then drivers/Makefile would be re-worked as follows:

  obj-$(call CONFIG,SERIAL)  += serial/
  obj-$(call CONFIG,I2C)     += i2c/
  obj-$(call CONFIG,GPIO)    += gpio/
  obj-$(call CONFIG,SPI)     += spi/
     ...

Eventually, SPL-specialized entries in Makefile.spl would go away.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 scripts/Kbuild.include | 3 +++
 1 file changed, 3 insertions(+)

Comments

Tom Rini July 27, 2015, 3:08 p.m. UTC | #1
On Thu, Jul 23, 2015 at 08:31:55PM +0900, Masahiro Yamada wrote:

> Commit e02ee2548afe ("kconfig: switch to single .config
> configuration") made the configuration itself pretty simple,
> instead, we lost the way to systematically enable/disable config
> options for each image independently.
> 
> Our current strategy is, put entries into Makefile.spl for options
> we need separate enabling, or once enable the options globally in
> Kconfig and then undef them in Makefile.uncmd_spl if we do not want
> to compile the features for SPL at all.  Things are getting really
> messy.  Besides, "ifdef CONFIG_SPL_BUILD" are sprinkled everywhere
> in makefiles.
> 
> This commit adds a macro to help describe makefile simpler, allowing
> separate switch for U-boot main and SPL.
> 
> This macro takes a config option without the prefix CONFIG_.
> $(call CONFIG,FOO) evaluates to
>   $(CONFIG_FOO) if CONFIG_SPL_BUILD is undefined (U-boot build),
>   $(CONFIG_SPL_FOO) if CONFIG_SPL_BUILD is defined (SPL_BUILD).
> 
> That is,
> 
>   $(call CONFIG,FOO) += foo.o
> 
> is a shorthand for
> 
>   ifdef CONFIG_SPL_BUILD
>   obj-$(CONFIG_SPL_FOO) += foo.o
>   else
>   obj-$(CONFIG_FOO) += foo.o
>   endif
> 
> If CONFIG_SPL_FOO does not exist in Kconfig, it is equivalent to
> 
>   ifndef CONFIG_SPL_BUILD
>   obj-$(CONFIG_SPL_FOO) += foo.o
>   endif
> 
> This is the pattern we often see in our current makefiles.
> 
> To take advantage of this macro, we should prefix SPL_ for the SPL
> version of the option that we need independent control between
> U-boot and SPL.  With this naming scheme, we only have to add a
> single line in a Makefile for each config option.
> 
> It means we want to rename existing config options as follows
> in the long run:
> 
>   CONFIG_SPL_SERIAL_SUPPORT     -> CONFIG_SPL_SERIAL
>   CONFIG_SPL_I2C_SUPPORT        -> CONFIG_SPL_I2C
>   CONFIG_SPL_GPIO_SUPPORT       -> CONFIG_SPL_GPIO
>   CONFIG_SPL_SPI_SUPPORT        -> CONFIG_SPL_SPI
>   CONFIG_SPL_DISABLE_OF_CONTROL -> CONFIG_SPL_OF_CONTROL
>                                       (inverting the logic)
> 
> Then drivers/Makefile would be re-worked as follows:
> 
>   obj-$(call CONFIG,SERIAL)  += serial/
>   obj-$(call CONFIG,I2C)     += i2c/
>   obj-$(call CONFIG,GPIO)    += gpio/
>   obj-$(call CONFIG,SPI)     += spi/
>      ...
> 
> Eventually, SPL-specialized entries in Makefile.spl would go away.
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Reviewed-by: Tom Rini <trini@konsulko.com>
Masahiro Yamada July 27, 2015, 3:19 p.m. UTC | #2
Tom,


2015-07-28 0:08 GMT+09:00 Tom Rini <trini@konsulko.com>:
> On Thu, Jul 23, 2015 at 08:31:55PM +0900, Masahiro Yamada wrote:
>
>> Commit e02ee2548afe ("kconfig: switch to single .config
>> configuration") made the configuration itself pretty simple,
>> instead, we lost the way to systematically enable/disable config
>> options for each image independently.
>>
>> Our current strategy is, put entries into Makefile.spl for options
>> we need separate enabling, or once enable the options globally in
>> Kconfig and then undef them in Makefile.uncmd_spl if we do not want
>> to compile the features for SPL at all.  Things are getting really
>> messy.  Besides, "ifdef CONFIG_SPL_BUILD" are sprinkled everywhere
>> in makefiles.
>>
>> This commit adds a macro to help describe makefile simpler, allowing
>> separate switch for U-boot main and SPL.
>>
>> This macro takes a config option without the prefix CONFIG_.
>> $(call CONFIG,FOO) evaluates to
>>   $(CONFIG_FOO) if CONFIG_SPL_BUILD is undefined (U-boot build),
>>   $(CONFIG_SPL_FOO) if CONFIG_SPL_BUILD is defined (SPL_BUILD).
>>
>> That is,
>>
>>   $(call CONFIG,FOO) += foo.o
>>
>> is a shorthand for
>>
>>   ifdef CONFIG_SPL_BUILD
>>   obj-$(CONFIG_SPL_FOO) += foo.o
>>   else
>>   obj-$(CONFIG_FOO) += foo.o
>>   endif
>>
>> If CONFIG_SPL_FOO does not exist in Kconfig, it is equivalent to
>>
>>   ifndef CONFIG_SPL_BUILD
>>   obj-$(CONFIG_SPL_FOO) += foo.o
>>   endif
>>
>> This is the pattern we often see in our current makefiles.
>>
>> To take advantage of this macro, we should prefix SPL_ for the SPL
>> version of the option that we need independent control between
>> U-boot and SPL.  With this naming scheme, we only have to add a
>> single line in a Makefile for each config option.
>>
>> It means we want to rename existing config options as follows
>> in the long run:
>>
>>   CONFIG_SPL_SERIAL_SUPPORT     -> CONFIG_SPL_SERIAL
>>   CONFIG_SPL_I2C_SUPPORT        -> CONFIG_SPL_I2C
>>   CONFIG_SPL_GPIO_SUPPORT       -> CONFIG_SPL_GPIO
>>   CONFIG_SPL_SPI_SUPPORT        -> CONFIG_SPL_SPI
>>   CONFIG_SPL_DISABLE_OF_CONTROL -> CONFIG_SPL_OF_CONTROL
>>                                       (inverting the logic)
>>
>> Then drivers/Makefile would be re-worked as follows:
>>
>>   obj-$(call CONFIG,SERIAL)  += serial/
>>   obj-$(call CONFIG,I2C)     += i2c/
>>   obj-$(call CONFIG,GPIO)    += gpio/
>>   obj-$(call CONFIG,SPI)     += spi/
>>      ...
>>
>> Eventually, SPL-specialized entries in Makefile.spl would go away.
>>
>> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
>
> Reviewed-by: Tom Rini <trini@konsulko.com>
>

This patch was superseded by

http://patchwork.ozlabs.org/patch/500034/


If you do not mind, I will put your Reviewed-by there
when I send the next version.
Tom Rini July 27, 2015, 3:31 p.m. UTC | #3
On Tue, Jul 28, 2015 at 12:19:07AM +0900, Masahiro Yamada wrote:
> Tom,
> 
> 
> 2015-07-28 0:08 GMT+09:00 Tom Rini <trini@konsulko.com>:
> > On Thu, Jul 23, 2015 at 08:31:55PM +0900, Masahiro Yamada wrote:
> >
> >> Commit e02ee2548afe ("kconfig: switch to single .config
> >> configuration") made the configuration itself pretty simple,
> >> instead, we lost the way to systematically enable/disable config
> >> options for each image independently.
> >>
> >> Our current strategy is, put entries into Makefile.spl for options
> >> we need separate enabling, or once enable the options globally in
> >> Kconfig and then undef them in Makefile.uncmd_spl if we do not want
> >> to compile the features for SPL at all.  Things are getting really
> >> messy.  Besides, "ifdef CONFIG_SPL_BUILD" are sprinkled everywhere
> >> in makefiles.
> >>
> >> This commit adds a macro to help describe makefile simpler, allowing
> >> separate switch for U-boot main and SPL.
> >>
> >> This macro takes a config option without the prefix CONFIG_.
> >> $(call CONFIG,FOO) evaluates to
> >>   $(CONFIG_FOO) if CONFIG_SPL_BUILD is undefined (U-boot build),
> >>   $(CONFIG_SPL_FOO) if CONFIG_SPL_BUILD is defined (SPL_BUILD).
> >>
> >> That is,
> >>
> >>   $(call CONFIG,FOO) += foo.o
> >>
> >> is a shorthand for
> >>
> >>   ifdef CONFIG_SPL_BUILD
> >>   obj-$(CONFIG_SPL_FOO) += foo.o
> >>   else
> >>   obj-$(CONFIG_FOO) += foo.o
> >>   endif
> >>
> >> If CONFIG_SPL_FOO does not exist in Kconfig, it is equivalent to
> >>
> >>   ifndef CONFIG_SPL_BUILD
> >>   obj-$(CONFIG_SPL_FOO) += foo.o
> >>   endif
> >>
> >> This is the pattern we often see in our current makefiles.
> >>
> >> To take advantage of this macro, we should prefix SPL_ for the SPL
> >> version of the option that we need independent control between
> >> U-boot and SPL.  With this naming scheme, we only have to add a
> >> single line in a Makefile for each config option.
> >>
> >> It means we want to rename existing config options as follows
> >> in the long run:
> >>
> >>   CONFIG_SPL_SERIAL_SUPPORT     -> CONFIG_SPL_SERIAL
> >>   CONFIG_SPL_I2C_SUPPORT        -> CONFIG_SPL_I2C
> >>   CONFIG_SPL_GPIO_SUPPORT       -> CONFIG_SPL_GPIO
> >>   CONFIG_SPL_SPI_SUPPORT        -> CONFIG_SPL_SPI
> >>   CONFIG_SPL_DISABLE_OF_CONTROL -> CONFIG_SPL_OF_CONTROL
> >>                                       (inverting the logic)
> >>
> >> Then drivers/Makefile would be re-worked as follows:
> >>
> >>   obj-$(call CONFIG,SERIAL)  += serial/
> >>   obj-$(call CONFIG,I2C)     += i2c/
> >>   obj-$(call CONFIG,GPIO)    += gpio/
> >>   obj-$(call CONFIG,SPI)     += spi/
> >>      ...
> >>
> >> Eventually, SPL-specialized entries in Makefile.spl would go away.
> >>
> >> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> >
> > Reviewed-by: Tom Rini <trini@konsulko.com>
> >
> 
> This patch was superseded by
> 
> http://patchwork.ozlabs.org/patch/500034/
> 
> 
> If you do not mind, I will put your Reviewed-by there
> when I send the next version.

I kinda thought that's how it was looking in my inbox.  I'll read that
whole series later today.
diff mbox

Patch

diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index d20f20a..335d656 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -294,3 +294,6 @@  why =                                                                        \
 
 echo-why = $(call escsq, $(strip $(why)))
 endif
+
+# U-Boot only
+CONFIG = $(if $(CONFIG_SPL_BUILD),$(CONFIG_SPL_$(1)),$(CONFIG_$(1)))