All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3 v2] kconfig: get the CONFIG_ prefix from the environment
@ 2012-10-18 19:50 Yann E. MORIN
  2012-10-18 19:50 ` [PATCH 1/3] kconfig: remove CONFIG_ from string constants Yann E. MORIN
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Yann E. MORIN @ 2012-10-18 19:50 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Michal Marek, linux-kernel

Hello All!

This little patch series allows one to override the CONFIG_ prefix at 
runtime, without the need to rebuild the frontends.

This will be useful to have, to share the same kconfig frontends between
different projects that may use different prefix. For example:
  - busybox and uClibc use the standard 'CONFIG_'
  - crosstool-NG uses 'CT_'
  - PTXdist uses 'PTXCONF_'
  - buildroot does not use a prefix at all
  - and so on...

    [PATCH 1/3] kconfig: remove CONFIG_ from string constants
    [PATCH 2/3] kconfig: add a function to get the CONFIG_ prefix
    [PATCH 3/3] kconfig: get CONFIG_ prefix from environment

This is part of my efforts to get a generic package that encapsulates the
kconfig frontends and parser into a standalone package, to make it easy
for third-party projects to easily sync (and ultimately share) their
kconfig infrastructure:
    kconfig-frontends
    http://ymorin.is-a-geek.org/projects/kconfig-frontends

Changes this v1:
  - call getenv() only once
  - don't touch code when not strictly neeeded (don't fold not-so-long lines)
  - rebase on-top 3.7-rc1

Regards,
Yann E. MORIN.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] kconfig: remove CONFIG_ from string constants
  2012-10-18 19:50 [PATCH 0/3 v2] kconfig: get the CONFIG_ prefix from the environment Yann E. MORIN
@ 2012-10-18 19:50 ` Yann E. MORIN
  2012-10-18 19:50 ` [PATCH 2/3] kconfig: add a function to get the CONFIG_ prefix Yann E. MORIN
  2012-10-18 19:50 ` [PATCH 3/3] kconfig: get CONFIG_ prefix from the environment Yann E. MORIN
  2 siblings, 0 replies; 6+ messages in thread
From: Yann E. MORIN @ 2012-10-18 19:50 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Michal Marek, linux-kernel, Yann E. MORIN

Having the CONFIG_ prefix in string constants gets in the way of
using a run-time-defined CONFIG_ prefix.

Fix that by using temp growable strings (gstr) in which we printf
the text.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
---
 scripts/kconfig/mconf.c |   10 ++++++++--
 scripts/kconfig/nconf.c |   11 +++++++++--
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index 48f6744..5f29618 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -348,15 +348,19 @@ static void search_conf(void)
 {
 	struct symbol **sym_arr;
 	struct gstr res;
+	struct gstr title;
 	char *dialog_input;
 	int dres, vscroll = 0, hscroll = 0;
 	bool again;
 
+	title = str_new();
+	str_printf( &title, _("Enter %s (sub)string to search for "
+			      "(with or without \"%s\")"), CONFIG_, CONFIG_);
+
 again:
 	dialog_clear();
 	dres = dialog_inputbox(_("Search Configuration Parameter"),
-			      _("Enter " CONFIG_ " (sub)string to search for "
-				"(with or without \"" CONFIG_ "\")"),
+			      str_get(&title),
 			      10, 75, "");
 	switch (dres) {
 	case 0:
@@ -365,6 +369,7 @@ again:
 		show_helptext(_("Search Configuration"), search_help);
 		goto again;
 	default:
+		str_free(&title);
 		return;
 	}
 
@@ -398,6 +403,7 @@ again:
 		str_free(&res);
 	} while (again);
 	free(sym_arr);
+	str_free(&title);
 }
 
 static void build_conf(struct menu *menu)
diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
index 87d4b15..261f926 100644
--- a/scripts/kconfig/nconf.c
+++ b/scripts/kconfig/nconf.c
@@ -696,13 +696,18 @@ static void search_conf(void)
 {
 	struct symbol **sym_arr;
 	struct gstr res;
+	struct gstr title;
 	char *dialog_input;
 	int dres;
+
+	title = str_new();
+	str_printf( &title, _("Enter %s (sub)string to search for "
+			      "(with or without \"%s\")"), CONFIG_, CONFIG_);
+
 again:
 	dres = dialog_inputbox(main_window,
 			_("Search Configuration Parameter"),
-			_("Enter " CONFIG_ " (sub)string to search for "
-				"(with or without \"" CONFIG_ "\")"),
+			str_get(&title),
 			"", &dialog_input_result, &dialog_input_result_len);
 	switch (dres) {
 	case 0:
@@ -712,6 +717,7 @@ again:
 				_("Search Configuration"), search_help);
 		goto again;
 	default:
+		str_free(&title);
 		return;
 	}
 
@@ -726,6 +732,7 @@ again:
 	show_scroll_win(main_window,
 			_("Search Results"), str_get(&res));
 	str_free(&res);
+	str_free(&title);
 }
 
 
-- 
1.7.2.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] kconfig: add a function to get the CONFIG_ prefix
  2012-10-18 19:50 [PATCH 0/3 v2] kconfig: get the CONFIG_ prefix from the environment Yann E. MORIN
  2012-10-18 19:50 ` [PATCH 1/3] kconfig: remove CONFIG_ from string constants Yann E. MORIN
@ 2012-10-18 19:50 ` Yann E. MORIN
  2012-10-19 17:01   ` Michal Marek
  2012-10-18 19:50 ` [PATCH 3/3] kconfig: get CONFIG_ prefix from the environment Yann E. MORIN
  2 siblings, 1 reply; 6+ messages in thread
From: Yann E. MORIN @ 2012-10-18 19:50 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Michal Marek, linux-kernel, Yann E. MORIN

Currently, we get the CONFIG_ prefix via the CONFIG_ macro, which means
the CONFIG_ prefix is hard-coded at compile time. This goes against
having a run-time defined CONFIG_ prefix.

Add a function that returns the CONFIG_ prefix to use (but keep the
current hard-coded behavior, to be changed in a later patch).

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
---
 scripts/kconfig/lkc.h |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index c18f2bd..25862fd 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -36,9 +36,17 @@ extern "C" {
 #define _(text) gettext(text)
 #define N_(text) (text)
 
-#ifndef CONFIG_
-#define CONFIG_ "CONFIG_"
+/* Those two defines copied from include/linux/stringify.h */
+#define __stringify_1(x...)	#x
+#define __stringify(x...)	__stringify_1(x)
+static inline const char *CONFIG_prefix(void)
+{
+	return __stringify(CONFIG_);
+}
+#ifdef CONFIG_
+#undef CONFIG_
 #endif
+#define CONFIG_ CONFIG_prefix()
 
 #define TF_COMMAND	0x0001
 #define TF_PARAM	0x0002
-- 
1.7.2.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] kconfig: get CONFIG_ prefix from the environment
  2012-10-18 19:50 [PATCH 0/3 v2] kconfig: get the CONFIG_ prefix from the environment Yann E. MORIN
  2012-10-18 19:50 ` [PATCH 1/3] kconfig: remove CONFIG_ from string constants Yann E. MORIN
  2012-10-18 19:50 ` [PATCH 2/3] kconfig: add a function to get the CONFIG_ prefix Yann E. MORIN
@ 2012-10-18 19:50 ` Yann E. MORIN
  2 siblings, 0 replies; 6+ messages in thread
From: Yann E. MORIN @ 2012-10-18 19:50 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Michal Marek, linux-kernel, Yann E. MORIN

Currently, the CONFIG_ prefix is hard-coded in the kconfig frontends
executables. This means that two projects that use kconfig with
different prefixes can not share the same kconfig frontends.

Instead of hard-coding the prefix in the frontends, get it from the
environment, and revert back to hard-coded value if not found.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
---
 scripts/kconfig/gconf.c |    2 +-
 scripts/kconfig/lkc.h   |    2 +-
 scripts/kconfig/nconf.c |    1 +
 3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/scripts/kconfig/gconf.c b/scripts/kconfig/gconf.c
index adc2306..f2bee70 100644
--- a/scripts/kconfig/gconf.c
+++ b/scripts/kconfig/gconf.c
@@ -10,6 +10,7 @@
 #  include <config.h>
 #endif
 
+#include <stdlib.h>
 #include "lkc.h"
 #include "images.c"
 
@@ -22,7 +23,6 @@
 #include <string.h>
 #include <unistd.h>
 #include <time.h>
-#include <stdlib.h>
 
 //#define DEBUG
 
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 25862fd..2faf8ac 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -41,7 +41,7 @@ extern "C" {
 #define __stringify(x...)	__stringify_1(x)
 static inline const char *CONFIG_prefix(void)
 {
-	return __stringify(CONFIG_);
+	return getenv( "CONFIG_" ) ?: __stringify(CONFIG_);
 }
 #ifdef CONFIG_
 #undef CONFIG_
diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c
index 261f926..ce93e87 100644
--- a/scripts/kconfig/nconf.c
+++ b/scripts/kconfig/nconf.c
@@ -7,6 +7,7 @@
  */
 #define _GNU_SOURCE
 #include <string.h>
+#include <stdlib.h>
 
 #include "lkc.h"
 #include "nconf.h"
-- 
1.7.2.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] kconfig: add a function to get the CONFIG_ prefix
  2012-10-18 19:50 ` [PATCH 2/3] kconfig: add a function to get the CONFIG_ prefix Yann E. MORIN
@ 2012-10-19 17:01   ` Michal Marek
  2012-10-19 17:59     ` Yann E. MORIN
  0 siblings, 1 reply; 6+ messages in thread
From: Michal Marek @ 2012-10-19 17:01 UTC (permalink / raw)
  To: Yann E. MORIN; +Cc: linux-kbuild, linux-kernel

On 18.10.2012 21:50, Yann E. MORIN wrote:
> -#ifndef CONFIG_
> -#define CONFIG_ "CONFIG_"
> +/* Those two defines copied from include/linux/stringify.h */
> +#define __stringify_1(x...)	#x
> +#define __stringify(x...)	__stringify_1(x)
> +static inline const char *CONFIG_prefix(void)
> +{
> +	return __stringify(CONFIG_);

This changes the semantics of the CONFIG_ macro. Previously, a
double-quoted string was accepted, now you have to define it to a token
that is turned into a string. Why don't you keep it as before and just do a

return CONFIG_;

in the function?

Michal

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] kconfig: add a function to get the CONFIG_ prefix
  2012-10-19 17:01   ` Michal Marek
@ 2012-10-19 17:59     ` Yann E. MORIN
  0 siblings, 0 replies; 6+ messages in thread
From: Yann E. MORIN @ 2012-10-19 17:59 UTC (permalink / raw)
  To: Michal Marek; +Cc: linux-kbuild, linux-kernel

Michal, All,

On Friday 19 October 2012 Michal Marek wrote:
> On 18.10.2012 21:50, Yann E. MORIN wrote:
> > -#ifndef CONFIG_
> > -#define CONFIG_ "CONFIG_"
> > +/* Those two defines copied from include/linux/stringify.h */
> > +#define __stringify_1(x...)	#x
> > +#define __stringify(x...)	__stringify_1(x)
> > +static inline const char *CONFIG_prefix(void)
> > +{
> > +	return __stringify(CONFIG_);
> 
> This changes the semantics of the CONFIG_ macro. Previously, a
> double-quoted string was accepted, now you have to define it to a token
> that is turned into a string. Why don't you keep it as before and just do a
> 
> return CONFIG_;
> 
> in the function?

Yes, that's as simple as it looks, indeed. /me hides.

Thank you!
Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-10-19 17:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-18 19:50 [PATCH 0/3 v2] kconfig: get the CONFIG_ prefix from the environment Yann E. MORIN
2012-10-18 19:50 ` [PATCH 1/3] kconfig: remove CONFIG_ from string constants Yann E. MORIN
2012-10-18 19:50 ` [PATCH 2/3] kconfig: add a function to get the CONFIG_ prefix Yann E. MORIN
2012-10-19 17:01   ` Michal Marek
2012-10-19 17:59     ` Yann E. MORIN
2012-10-18 19:50 ` [PATCH 3/3] kconfig: get CONFIG_ prefix from the environment Yann E. MORIN

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.