kconfig: add module_name shortcut
Subsystems (4)
PATCH 5/8 kconfig: add module_name shortcut
From: Alexey Dobriyan <[email protected]>
As correctly noticed in bug 11446
(http://bugzilla.kernel.org/show_bug.cgi?id=11446) "To compile this driver as a module, blah-blah" boilerplate is being copy-pasted to death with slight variations.
Add Kconfig token "module_name" to supply module's name. Example:
config FOO tristate "foo" module_name foo ---help--- foo
Print module's name as following on menuconfigs help screen (press 'h'):
Module name: foo
8139too driver converted to show real-life example.
P.S.: menuconfig only, no checking wrt modular/standalone code et al.
---
drivers/net/Kconfig | 4 scripts/kconfig/expr.h | 4 scripts/kconfig/lkc.h | 1 scripts/kconfig/mconf.c | 2 scripts/kconfig/menu.c | 8 scripts/kconfig/symbol.c | 2 scripts/kconfig/zconf.gperf | 1 scripts/kconfig/zconf.hash.c_shipped | 184 ++++---- scripts/kconfig/zconf.tab.c_shipped | 539 ++++++++++++------------- scripts/kconfig/zconf.y | 12 10 files changed, 404 insertions(+), 353 deletions(-)
drivers/net/Kconfig renamed from drivers/net/Kconfig~kconfig-add-module_name-shortcut +1 -3
@@ -1551,14 +1551,12 @@ config 8139TOO depends on NET_PCI && PCI select CRC32 select MII + module_name 8139too ---help--- This is a driver for the Fast Ethernet PCI network cards based on the RTL 8129/8130/8139 chips. If you have one of those, say Y and read the Ethernet-HOWTO <http://www.tldp.org/docs.html#howto>. - To compile this driver as a module, choose M here: the module - will be called 8139too. This is recommended. - config 8139TOO_PIO bool "Use PIO instead of MMIO" default y
scripts/kconfig/expr.h renamed from scripts/kconfig/expr.h~kconfig-add-module_name-shortcut +3 -1
@@ -107,7 +107,8 @@ struct symbol {enum prop_type {P_UNKNOWN ,P_PROMPT ,P_COMMENT ,P_MENU ,P_DEFAULT ,P_CHOICE , -P_SELECT ,P_RANGE ,P_ENV +P_SELECT ,P_RANGE ,P_ENV , +P_MODULE_NAME , };struct property {
@@ -115,6 +116,7 @@ struct property {struct symbol *sym;enum prop_type type;const char *text; +char *module_name;struct expr_value visible;struct expr *expr;struct menu *menu;
scripts/kconfig/lkc.h renamed from scripts/kconfig/lkc.h~kconfig-add-module_name-shortcut +1 -0
@@ -95,6 +95,7 @@ struct property *menu_add_prompt(enum prvoid menu_add_expr (enum prop_type type,struct expr *expr,struct expr *dep);void menu_add_symbol (enum prop_type type,struct symbol *sym,struct expr *dep);void menu_add_option (int token,char *arg); +void menu_add_module_name (char *module_name);void menu_finalize (struct menu *parent);void menu_set_type (int type);
scripts/kconfig/mconf.c renamed from scripts/kconfig/mconf.c~kconfig-add-module_name-shortcut +2 -0
@@ -320,6 +320,8 @@ static void get_symbol_str(struct gstr *bool hit;struct property *prop; + for_all_properties(sym, prop, P_MODULE_NAME) +str_printf (r,_ ("Module name: %s\n\n" ), prop->module_name);if (sym && sym->name)str_printf (r,"Symbol: %s [=%s]\n" , sym->name,sym_get_string_value (sym));
scripts/kconfig/menu.c renamed from scripts/kconfig/menu.c~kconfig-add-module_name-shortcut +8 -0
@@ -178,6 +178,14 @@ void menu_add_option(int token, char *ar } } +void menu_add_module_name (char *module_name) +{ +struct property *prop; + + prop =prop_alloc (P_MODULE_NAME , current_entry->sym); + prop->module_name =strdup (module_name); +} +static int menu_range_valid_sym (struct symbol *sym,struct symbol *sym2) { return sym2->type == S_INT || sym2->type == S_HEX ||
scripts/kconfig/symbol.c renamed from scripts/kconfig/symbol.c~kconfig-add-module_name-shortcut +2 -0
@@ -937,6 +937,8 @@ const char *prop_get_type_name(enum propreturn "select" ;case P_RANGE :return "range" ; +case P_MODULE_NAME : +return "module_name" ;case P_UNKNOWN :break ; }
scripts/kconfig/zconf.gperf renamed from scripts/kconfig/zconf.gperf~kconfig-add-module_name-shortcut +1 -0
@@ -41,4 +41,5 @@ on, T_ON, TF_PARAM modules, T_OPT_MODULES, TF_OPTION defconfig_list, T_OPT_DEFCONFIG_LIST,TF_OPTION env, T_OPT_ENV, TF_OPTION +module_name, T_MODULE_NAME, TF_COMMAND %%
scripts/kconfig/zconf.hash.c_shipped renamed from scripts/kconfig/zconf.hash.c_shipped~kconfig-add-module_name-shortcut +95 -89
259 lines not on this page · raw message
scripts/kconfig/zconf.tab.c_shipped renamed from scripts/kconfig/zconf.tab.c_shipped~kconfig-add-module_name-shortcut +279 -260
873 lines not on this page · raw message
scripts/kconfig/zconf.y renamed from scripts/kconfig/zconf.y~kconfig-add-module_name-shortcut +12 -0
@@ -72,6 +72,7 @@ static struct menu *current_menu, *curre %token <id>T_RANGE %token <id>T_OPTION %token <id>T_ON +%token <id>T_MODULE_NAME %token <string> T_WORD %token <string> T_WORD_QUOTE %token T_UNEQUAL
@@ -90,6 +91,7 @@ static struct menu *current_menu, *curre %type <expr> if_expr %type <id> end %type <id> option_name +%type <string> module_name %type <menu> if_entry menu_entry choice_entry %type <string> symbol_option_arg word_opt
@@ -217,6 +219,12 @@ config_option: T_RANGE symbol symbol if_ printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno()); }; +config_option: T_MODULE_NAME module_name T_EOL +{ + menu_add_module_name($2); + printd(DEBUG_PARSE, "%s:%d:module_name\n", zconf_curname(), zconf_lineno()); +}; + symbol_option: T_OPTION symbol_option_list T_EOL ;
@@ -461,6 +469,10 @@ symbol: T_WORD { $$ = sym_lookup($1, 0 word_opt: /* empty */ { $$ = NULL; } | T_WORD +; + +module_name: T_WORD { $$ = $1 } +; %%
_
Hi,
Quoted 7 lines · On Mon, 1 Dec 2008, [email protected] wrote:
From: Alexey Dobriyan <[email protected]>
As correctly noticed in bug 11446
(http://bugzilla.kernel.org/show_bug.cgi?id=11446) "To compile this driver as a module, blah-blah" boilerplate is being copy-pasted to death with slight variations.
Quoted 7 lines
Add
Kconfigtoken "module_name" to supply module's name. Example:config FOO tristate "foo" module_name foo ---help--- foo
This syntax is a little inflexible.
Below is a patch, which integrates modules fully into the kconfig syntax, so this is enough:
module foo
tristate "foo"
The config symbol is derived from the module name or can be specified after the name. I also added the option to specify the sources, so that these can be used to generate the Kbuild information.
As a bonus feature the behaviour of boolean modules regarding their dependencies is a little different, so that the module is only visible when all its dependencies are builtin.
I didn't modify the help text, but it short quite simply to do on top of this patch.
Review struct property { · line 122
Quoted 8 lines
(quoted diff) +1
-0@@ -115,6 +116,7 @@ struct property { struct symbol *sym; enum prop_type type; const char *text; + char *module_name; struct expr_value visible; struct expr *expr; struct menu *menu;
A short comment about this one: I try to keep the property structure as generic as possible, so adding new fields should be avoided. Simple string values can also be added as expressions by using a constant symbol:
menu_add_symbol(P_MODULE, sym_lookup($2, SYMBOL_CONST), NULL);
bye, Roman
[PATCH] add module syntax
Add specific syntax for defining a kernel module:
module foo
tristate "foo support"
sources foo1.c foo2.c
This information can be used by Kbuild to generate the necessary build information.
--- Documentation/kbuild/kconfig-language.txt | 18 scripts/kconfig/expr.h | 3 scripts/kconfig/menu.c | 2 scripts/kconfig/qconf.cc | 2 scripts/kconfig/symbol.c | 4 scripts/kconfig/zconf.gperf | 2 scripts/kconfig/zconf.hash.c_shipped | 187 ++++--- scripts/kconfig/zconf.tab.c_shipped | 714 ++++++++++++++++-------------- scripts/kconfig/zconf.y | 61 ++ 9 files changed, 587 insertions(+), 406 deletions(-)
Documentation/kbuild/kconfig-language.txt +18 -0
@@ -150,6 +150,10 @@ applicable everywhere (see syntax). to the build environment (if this is desired, it can be done via another symbol). +- sources: "source" <name> ... ["if" <expr>] + This is only valid for modules and allows to specify the source files + to be used for building the module. + Menu dependencies -----------------
@@ -243,6 +247,7 @@ line starts with a keyword (except help end a menu entry: - config - menuconfig +- module - choice/endchoice - comment - menu/endmenu
@@ -266,6 +271,19 @@ This is similar to the simple config ent hint to front ends, that all suboptions should be displayed as a separate list of options. +module: + "module" <name> [<symbol>] + <module options> + +This is similiar to a normal config option, but allows to specify +additional information, which are used to build modules. The config +symbol is optional and it's generated from the module name by +capitalizing it. +There is an important difference for boolean modules, their dependencies +are modified so that the module is only visible when all it's +dependencies are 'y' (i.e. builtin) unlike other boolean config option, +which are when it's dependecies are not 'n'. + choices: "choice"
scripts/kconfig/expr.h +2 -1
@@ -88,6 +88,7 @@ struct symbol {#define SYMBOL_CHECK 0x0008#define SYMBOL_CHOICE 0x0010#define SYMBOL_CHOICEVAL 0x0020 +#define SYMBOL_MODULE 0x0040#define SYMBOL_VALID 0x0080#define SYMBOL_OPTIONAL 0x0100#define SYMBOL_WRITE 0x0200
@@ -107,7 +108,7 @@ struct symbol {enum prop_type {P_UNKNOWN ,P_PROMPT ,P_COMMENT ,P_MENU ,P_DEFAULT ,P_CHOICE , -P_SELECT ,P_RANGE ,P_ENV +P_SELECT ,P_RANGE ,P_ENV ,P_MODULE ,P_SOURCES };struct property {
scripts/kconfig/menu.c +2 -0
@@ -272,6 +272,8 @@ void menu_finalize(struct menu *parent) dep =expr_transform (prop->visible.expr); dep =expr_alloc_and (expr_copy (basedep), dep); dep =expr_eliminate_dups (dep); +if (menu->sym && (menu->sym->flags &SYMBOL_MODULE )) + dep =expr_trans_compare (dep,E_EQUAL , &symbol_yes);if (menu->sym && menu->sym->type !=S_TRISTATE ) dep =expr_trans_bool (dep); prop->visible.expr = dep;
scripts/kconfig/qconf.cc +2 -0
@@ -1091,6 +1091,8 @@ QString ConfigInfoView::debug_info(struc case P_SELECT: case P_RANGE: case P_ENV: + case P_MODULE: + case P_SOURCES: debug += prop_get_type_name(prop->type); debug += ": "; expr_print(prop->expr, expr_print_help, &debug, E_NONE);
scripts/kconfig/symbol.c +4 -0
@@ -937,6 +937,10 @@ const char *prop_get_type_name(enum propreturn "select" ;case P_RANGE :return "range" ; +case P_MODULE : +return "module" ; +case P_SOURCES : +return "sources" ;case P_UNKNOWN :break ; }
scripts/kconfig/zconf.gperf +2 -0
@@ -19,6 +19,7 @@ endchoice, T_ENDCHOICE, TF_COMMAND comment, T_COMMENT, TF_COMMAND config, T_CONFIG, TF_COMMAND menuconfig, T_MENUCONFIG, TF_COMMAND +module, T_MODULE, TF_COMMAND help, T_HELP, TF_COMMAND if, T_IF, TF_COMMAND|TF_PARAM endif, T_ENDIF, TF_COMMAND
@@ -37,6 +38,7 @@ string, T_TYPE, TF_COMMAND, S_STRING select, T_SELECT, TF_COMMAND range, T_RANGE, TF_COMMAND option, T_OPTION, TF_COMMAND +sources, T_SOURCES, TF_COMMAND on, T_ON, TF_PARAM modules, T_OPT_MODULES, TF_OPTION defconfig_list, T_OPT_DEFCONFIG_LIST,TF_OPTION
scripts/kconfig/zconf.hash.c_shipped +97 -90
261 lines not on this page · raw message
scripts/kconfig/zconf.tab.c_shipped +400 -314
1,097 lines not on this page · raw message
scripts/kconfig/zconf.y +60 -1
103 lines not on this page · raw message
Quoted 19 lines · Roman Zippel
Hi,
Quoted 7 lines · On Mon, 1 Dec 2008, [email protected] wrote:
From: Alexey Dobriyan <[email protected]>
As correctly noticed in bug 11446
(http://bugzilla.kernel.org/show_bug.cgi?id=11446) "To compile this driver as a module, blah-blah" boilerplate is being copy-pasted to death with slight variations.Quoted 7 lines
Add
Kconfigtoken "module_name" to supply module's name. Example:config FOO tristate "foo" module_name foo ---help--- foo
Quoted 3 lines
This syntax is a little inflexible.
Below is a patch, which integrates modules fully into the kconfig syntax, so this is enough:
Thanks Roman - looks good.
Quoted 7 lines
module foo
tristate "foo"The config symbol is derived from the module name or can be specified after the name. I also added the option to specify the sources, so that these can be used to generate the
Kbuildinformation.
Do you have any idea how do do this properly on the Kbuild side? I see a few possibilities but have not made up my mind yet.
1) We could generate a Kbuild.foo file in the dir where we have the module
2) We could add info to auto.conf so we could build all modules defined in the configuration in one step
Both alternatives have their drawbacks.
I hesitate to add the patch until we have the kbuild bits sorted out. I do not ask you to do the kbuild bits - I'm just asking for inputs on what you have considered when you made this patch.
Have you ever considered the possibility to add the Kconfig info direct in the .c file so we could have a single file driver for the typical cases?
It could be a natural extension to what you made so far.
Sam
Hi,
Quoted 4 lines · Sam Ravnborg
Quoted 3 lines
The config symbol is derived from the module name or can be specified after the name. I also added the option to specify the sources, so that these can be used to generate the
Kbuildinformation.
Quoted 8 lines
Do you have any idea how do do this properly on the
Kbuildside? I see a few possibilities but have not made up my mind yet.1) We could generate a Kbuild.foo file in the dir where we have the module
2) We could add info to auto.conf so we could build all modules defined in the configuration in one stepBoth alternatives have their drawbacks.
I'm considering a combination of both.
Separate files keeps thing local, as we may need further Makefile fragments, so keeping things local reduces the risk of conflicts. OTOH we should have a global list of all dirs, which is then used by make, this avoids the dependency problem of some old generated Makefile still around which is magically included.
Quoted 3 lines
Have you ever considered the possibility to add the
Kconfiginfo direct in the .c file so we could have a single file driver for the typical cases?
I think currently it would create more problem than it provides in convenience.
First you have the dependency problem. How do you find new files? What happens if there are multiple version of a driver (e.g. a backup file). Then there will be a performance problem, so that we would need some caching. Currently the whole Kconfig is read, when something is changed, since it's a only few MB, we get away with with, but if you have to scan all the sources it's a problem.
bye, Roman