I'm looking for a way to convert a choice to an int in a Kconfig file. So for example, I would want:
config BUFSIZE
int
choice
prompt "choose a buffersize"
depends on FOOBAR
default 10 if FOO
default 15 if BAR
default 20
config SIZE10
bool "10"
depends on !FOO
select BUFSIZE=10
config SIZE15
bool "15"
depends on FOOBAR | BAR
select BUFSIZE=15
config SIZE20
bool "20"
depends on BAR
select BUFSIZE=20
endchoice
of course, you can't use =
with select
, so the above does not work. The actual list of choices is somewhat long and volatile, so I would like to avoid having a string of #ifdef
's in another file to convert these to integers (plus these values are used in Makefiles as well as C files...)
My alternative is to make BUFSIZE
user configurable, but that's problematic, as I cannot restrict the possible values very well. As well, if I specify a default value for an int
, and run make oldconfig
(where the value has not previously been defined), it prompts me for a value. If you set a default for a choice, it does not seem to prompt you on make oldconfig. This is important, as FOOBAR
is turned off/on often, and I would like it to automatically select the default value for the architecture when it is turned on.
I'm wondering if there's a clean solution to this that I've overlooked.
Do it like this:
choice
prompt "choose a buffersize"
depends on FOOBAR
config BUFFERSIZE_15
bool "15"
config BUFFERSIZE_20
bool "20"
config BUFFERSIZE_25
bool "25"
endchoice
config BUFSIZE
int
default 10
default 15 if BUFFERSIZE_15
default 20 if BUFFERSIZE_20
default 25 if BUFFERSIZE_25