2007-02-15 19:19:48

by Kumar Gala

[permalink] [raw]
Subject: kbuild question

I was wondering if there was some way to make a Kconfig menu either
be just a menu or a choice depending on another bool being set or not.

What I'm trying to accomplish is if CONFIG_ONLY_HAVE_ONE is set I
want it so you can only select on option, however if
CONFIG_ONLY_HAVE_ONE is not set you should be able to select multiple
options.

thanks

- k


2007-02-15 22:33:35

by Sam Ravnborg

[permalink] [raw]
Subject: Re: kbuild question

On Thu, Feb 15, 2007 at 01:18:52PM -0600, Kumar Gala wrote:
> I was wondering if there was some way to make a Kconfig menu either
> be just a menu or a choice depending on another bool being set or not.
>
> What I'm trying to accomplish is if CONFIG_ONLY_HAVE_ONE is set I
> want it so you can only select on option, however if
> CONFIG_ONLY_HAVE_ONE is not set you should be able to select multiple
> options.

You can do so using if.
See following example:
--------------------------------------------------------------
config ONLY_HAVE_ONE
prompt "only have one?"
boolean

if ONLY_HAVE_ONE
config FOO
bool foo
default y
endif

if !ONLY_HAVE_ONE
choice
prompt "multiple values"
default VAL_FIRST

config VAL_FIRST
bool "First value"

config VAL_SECOND
bool "Second value"
endchoice

endif
--------------------------------------------------------------

You should be able to modify this for the usage you ask for.

Hope this is useful,

Sam

2007-02-15 23:45:41

by Kumar Gala

[permalink] [raw]
Subject: Re: kbuild question


On Feb 15, 2007, at 4:33 PM, Sam Ravnborg wrote:

> On Thu, Feb 15, 2007 at 01:18:52PM -0600, Kumar Gala wrote:
>> I was wondering if there was some way to make a Kconfig menu either
>> be just a menu or a choice depending on another bool being set or
>> not.
>>
>> What I'm trying to accomplish is if CONFIG_ONLY_HAVE_ONE is set I
>> want it so you can only select on option, however if
>> CONFIG_ONLY_HAVE_ONE is not set you should be able to select multiple
>> options.
>
> You can do so using if.
> See following example:
> --------------------------------------------------------------
> config ONLY_HAVE_ONE
> prompt "only have one?"
> boolean
>
> if ONLY_HAVE_ONE
> config FOO
> bool foo
> default y
> endif
>
> if !ONLY_HAVE_ONE
> choice
> prompt "multiple values"
> default VAL_FIRST
>
> config VAL_FIRST
> bool "First value"
>
> config VAL_SECOND
> bool "Second value"
> endchoice
>
> endif
> --------------------------------------------------------------
>
> You should be able to modify this for the usage you ask for.
>
> Hope this is useful,

It is.

Now is there some way to not have to duplicate the 'config choices
between if ONLY_HAVE_ONE and if !ONLY_HAVE_ONE

To use your example I want to do:

config ONLY_HAVE_ONE
prompt "only have one?"
boolean

if ONLY_HAVE_ONE
config VAL_FIRST
bool "First value"

config VAL_SECOND
bool "Second value"
endif

if !ONLY_HAVE_ONE
choice
prompt "multiple values"
default VAL_FIRST

config VAL_FIRST
bool "First value"

config VAL_SECOND
bool "Second value"
endchoice

endif

I'd like not to have to repeat/duplicate VAL_FIRST, VAL_SECOND, etc..

- k

2007-02-16 08:50:05

by Sam Ravnborg

[permalink] [raw]
Subject: Re: kbuild question

>
> Now is there some way to not have to duplicate the 'config choices
> between if ONLY_HAVE_ONE and if !ONLY_HAVE_ONE
>
> To use your example I want to do:
>
> config ONLY_HAVE_ONE
> prompt "only have one?"
> boolean
>
> if ONLY_HAVE_ONE
> config VAL_FIRST
> bool "First value"
>
> config VAL_SECOND
> bool "Second value"
> endif
>
> if !ONLY_HAVE_ONE
> choice
> prompt "multiple values"
> default VAL_FIRST
>
> config VAL_FIRST
> bool "First value"
>
> config VAL_SECOND
> bool "Second value"
> endchoice
>
> endif
>
> I'd like not to have to repeat/duplicate VAL_FIRST, VAL_SECOND, etc..

A choice allow you to select multiple values if the type of all
choice entries are of type 'tristate' but this gets enabled
only when CONFIG_MODULES equal to 'y'.
So except if you really need the 'select multiple' when MODULES
are selected I see no easy way to achive what you want.

I did not try but carefull usage of 'depends on' could also help you
but it will get messy quite fast.

Maybe Roman can se a better way?

Sam

2007-02-16 10:24:09

by Roman Zippel

[permalink] [raw]
Subject: Re: kbuild question

Hi,

On Thu, 15 Feb 2007, Kumar Gala wrote:

> I was wondering if there was some way to make a Kconfig menu either be just a
> menu or a choice depending on another bool being set or not.
>
> What I'm trying to accomplish is if CONFIG_ONLY_HAVE_ONE is set I want it so
> you can only select on option, however if CONFIG_ONLY_HAVE_ONE is not set you
> should be able to select multiple options.

Could you please be more specific about the problem you're trying to
solve, instead of how you're trying to solve it?
A real example would help a lot to understand the actual problem.

bye, Roman

2007-02-16 14:15:38

by Kumar Gala

[permalink] [raw]
Subject: Re: kbuild question


On Feb 16, 2007, at 4:23 AM, Roman Zippel wrote:

> Hi,
>
> On Thu, 15 Feb 2007, Kumar Gala wrote:
>
>> I was wondering if there was some way to make a Kconfig menu
>> either be just a
>> menu or a choice depending on another bool being set or not.
>>
>> What I'm trying to accomplish is if CONFIG_ONLY_HAVE_ONE is set I
>> want it so
>> you can only select on option, however if CONFIG_ONLY_HAVE_ONE is
>> not set you
>> should be able to select multiple options.
>
> Could you please be more specific about the problem you're trying to
> solve, instead of how you're trying to solve it?
> A real example would help a lot to understand the actual problem.

Sure, on powerpc for some of the embedded sub-architectures you can
only select a single board to build for. For a lot of people this is
sufficient, however we are moving towards a world where you can
easily build in support for multiple boards into a single kernel.

I'd like to have it such that if I'm only building support for one
board (CONFIG_ONLY_HAVE_ONE, not going to call it that, but for this
discussion its sufficient), you get a choice menu from Kconfig
enforcing the ability to only select one board. However if !
CONFIG_ONLY_HAVE_ONE than you can select multiple boards to build
into your kernel.

if CONFIG_ONLY_HAVE_ONE is set we can optimize out the runtime checks
that get added for handling the multiple board case.

Hopefully that's clear.

- k

2007-02-18 17:16:09

by Roman Zippel

[permalink] [raw]
Subject: Re: kbuild question

Hi,

On Fri, 16 Feb 2007, Kumar Gala wrote:

> > Could you please be more specific about the problem you're trying to
> > solve, instead of how you're trying to solve it?
> > A real example would help a lot to understand the actual problem.
>
> Sure, on powerpc for some of the embedded sub-architectures you can only
> select a single board to build for. For a lot of people this is sufficient,
> however we are moving towards a world where you can easily build in support
> for multiple boards into a single kernel.
>
> I'd like to have it such that if I'm only building support for one board
> (CONFIG_ONLY_HAVE_ONE, not going to call it that, but for this discussion its
> sufficient), you get a choice menu from Kconfig enforcing the ability to only
> select one board. However if !CONFIG_ONLY_HAVE_ONE than you can select
> multiple boards to build into your kernel.
>
> if CONFIG_ONLY_HAVE_ONE is set we can optimize out the runtime checks that get
> added for handling the multiple board case.

On m68k we have the same problem, but what I'm what I'm considering is to
add a new mode for choice groups - at least one must be selected and
kconfig generates the extra information if only one is selected.

bye, Roman

2007-02-18 19:25:29

by Sam Ravnborg

[permalink] [raw]
Subject: Re: kbuild question

> >
> > Sure, on powerpc for some of the embedded sub-architectures you can only
> > select a single board to build for. For a lot of people this is sufficient,
> > however we are moving towards a world where you can easily build in support
> > for multiple boards into a single kernel.
> >
> > I'd like to have it such that if I'm only building support for one board
> > (CONFIG_ONLY_HAVE_ONE, not going to call it that, but for this discussion its
> > sufficient), you get a choice menu from Kconfig enforcing the ability to only
> > select one board. However if !CONFIG_ONLY_HAVE_ONE than you can select
> > multiple boards to build into your kernel.
> >
> > if CONFIG_ONLY_HAVE_ONE is set we can optimize out the runtime checks that get
> > added for handling the multiple board case.
>
> On m68k we have the same problem, but what I'm what I'm considering is to
> add a new mode for choice groups - at least one must be selected and
> kconfig generates the extra information if only one is selected.

How about extendign the current 'option' syntax to do this?
So we could do something like:

choice
prompt "choice prompt"
default VAL_FIRST
option multivalue if !CONFIG_ONLY_HAVE_ONE

config VAL_FIRST
bool "first"

config VAL_SECOND
bool "second"

endchoice

It seems to fit well with how option is used today, and extends current
syntax nicely.

Sam