]> git.sur5r.net Git - kconfig-frontends/commitdiff
configure: allow user to override program-prefix
authorYann E. MORIN" <yann.morin@orange.com>
Wed, 18 Apr 2012 16:56:12 +0000 (18:56 +0200)
committerYann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Wed, 18 Apr 2012 16:56:12 +0000 (18:56 +0200)
By default, use the current 'kconfig-' prefix,
but allow a user to change it, or even disable it.

Reported-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: "Yann E. MORIN" <yann.morin@orange.com>
18 files changed:
.hgignore
configure.ac
frontends/conf/Makefile.am
frontends/gconf/Makefile.am
frontends/mconf/Makefile.am
frontends/nconf/Makefile.am
frontends/qconf/Makefile.am
utils/Makefile.am
utils/diff [new file with mode: 0755]
utils/gettext.c [new file with mode: 0644]
utils/kconfig-diff [deleted file]
utils/kconfig-gettext.c [deleted file]
utils/kconfig-merge [deleted file]
utils/kconfig-streamline [deleted file]
utils/kconfig-tweak [deleted file]
utils/merge [new file with mode: 0755]
utils/streamline [new file with mode: 0755]
utils/tweak [new file with mode: 0755]

index 11bb574de94e4815a1092039da28d0da0c7b4ecc..b2a8e12a978fb3f9c7b120ad02236da754060ce1 100644 (file)
--- a/.hgignore
+++ b/.hgignore
@@ -7,11 +7,16 @@ syntax: glob
 *.la
 *.lai
 
-frontends/conf/kconfig-conf
-frontends/gconf/kconfig-gconf
-frontends/mconf/kconfig-mconf
-frontends/nconf/kconfig-nconf
-frontends/qconf/kconfig-qconf
+frontends/conf/conf
+frontends/conf/*-conf
+frontends/gconf/gconf
+frontends/gconf/*-gconf
+frontends/mconf/mconf
+frontends/mconf/*-mconf
+frontends/nconf/nconf
+frontends/nconf/*-nconf
+frontends/qconf/qconf
+frontends/qconf/*-qconf
 frontends/qconf/qconf.moc
 frontends/*/.libs
 
@@ -20,7 +25,8 @@ libs/images/images.h
 libs/parser/?conf.c
 libs/*/.libs
 
-utils/kconfig-gettext
+utils/gettext
+utils/*-gettext
 utils/.libs
 
 aclocal.m4
index f5d613b670363db67948c0c2e52248e1b3e8851c..f286155c756fa1ab3769af5c60f1509203eda658 100644 (file)
@@ -19,6 +19,15 @@ AC_CONFIG_MACRO_DIR([scripts/.autostuff/m4])
 
 #----------------------------------------
 # Prepare automake
+
+# We want to allow the user to override our default program-prefix,
+# so we must set-it now, before automake has a chance to interpret
+# it, but after the options are parsed, so as not to overwrite the
+# value (if any) set by the user
+AS_IF(
+    [test "$program_prefix" = NONE],
+    [program_prefix=kconfig-])
+
 AM_INIT_AUTOMAKE
 
 #----------------------------------------
@@ -445,5 +454,6 @@ AC_MSG_NOTICE([- parser library     :$lib_list])
 AC_MSG_NOTICE([  - root-menu prompt : $root_menu])
 AC_MSG_NOTICE([  - config prefix    : $config_prefix])
 AC_MSG_NOTICE([- frontends          :$fe_list])
+AC_MSG_NOTICE([  - transform name   : $program_transform_name])
 AC_MSG_NOTICE([- install utilities  : $enable_utils])
 AC_MSG_NOTICE([- CFLAGS CXXFLAGS    : $wall_CFLAGS $werror_CFLAGS])
index 502fd7681aa591cf0fc039af90f30eb89211ebc7..12f7b6a9ca399a783fc812a31a8e4753a6504820 100644 (file)
@@ -1,9 +1,9 @@
-bin_PROGRAMS = kconfig-conf
+bin_PROGRAMS = conf
 
-kconfig_conf_SOURCES = conf.c
-kconfig_conf_CPPFLAGS = $(AM_CPPFLAGS)  \
-                        $(GETTEXT)      \
-                        -I$(top_srcdir)/libs/parser
-kconfig_conf_CFLAGS = $(AM_CFLAGS) $(kf_CFLAGS)
-kconfig_conf_LDADD = $(top_builddir)/libs/parser/libkconfig-parser.la  \
-                     $(conf_EXTRA_LIBS)
+conf_SOURCES = conf.c
+conf_CPPFLAGS = $(AM_CPPFLAGS)  \
+                $(GETTEXT)      \
+                -I$(top_srcdir)/libs/parser
+conf_CFLAGS = $(AM_CFLAGS) $(kf_CFLAGS)
+conf_LDADD = $(top_builddir)/libs/parser/libkconfig-parser.la  \
+             $(conf_EXTRA_LIBS)
index aa4186a3c347d2771ac5691f6f416811b604aef7..8d9cdedeb188b88282c7a5eb9707b3aae0f23adc 100644 (file)
@@ -1,16 +1,16 @@
-bin_PROGRAMS = kconfig-gconf
+bin_PROGRAMS = gconf
 
-kconfig_gconf_SOURCES = gconf.c gconf.glade
-kconfig_gconf_CPPFLAGS = $(AM_CPPFLAGS)                 \
-                         $(GETTEXT)                     \
-                         -I$(top_srcdir)/libs/parser    \
-                         -I$(top_builddir)/libs/images  \
-                         -DGUI_PATH='"$(pkgdatadir)/gconf.glade"'
-kconfig_gconf_CFLAGS = $(AM_CFLAGS) \
-                       $(kf_CFLAGS) \
-                       $(gtk_CFLAGS)
-kconfig_gconf_LDADD = $(top_builddir)/libs/parser/libkconfig-parser.la  \
-                      $(top_builddir)/libs/images/libkconfig-images.a   \
-                      $(gtk_LIBS) $(gconf_EXTRA_LIBS)
-kconfig_gconfdir = $(pkgdatadir)
-kconfig_gconf_DATA = gconf.glade
+gconf_SOURCES = gconf.c gconf.glade
+gconf_CPPFLAGS = $(AM_CPPFLAGS)                 \
+                 $(GETTEXT)                     \
+                 -I$(top_srcdir)/libs/parser    \
+                 -I$(top_builddir)/libs/images  \
+                 -DGUI_PATH='"$(pkgdatadir)/gconf.glade"'
+gconf_CFLAGS = $(AM_CFLAGS) \
+               $(kf_CFLAGS) \
+               $(gtk_CFLAGS)
+gconf_LDADD = $(top_builddir)/libs/parser/libkconfig-parser.la  \
+              $(top_builddir)/libs/images/libkconfig-images.a   \
+              $(gtk_LIBS) $(gconf_EXTRA_LIBS)
+gconfdir = $(pkgdatadir)
+gconf_DATA = gconf.glade
index e5ce1b33370724eb6f72b87f19ad428aadaa0720..566fbe35c4ce1f7cbacb2b939f4d45c6ec26f10d 100644 (file)
@@ -1,13 +1,13 @@
-bin_PROGRAMS = kconfig-mconf
+bin_PROGRAMS = mconf
 
-kconfig_mconf_SOURCES = mconf.c
-kconfig_mconf_CPPFLAGS = $(AM_CPPFLAGS)                 \
-                         -DCURSES_LOC='"$(CURSES_LOC)"' \
-                         $(GETTEXT)                     \
-                         -I$(top_srcdir)/libs           \
-                         -I$(top_srcdir)/libs/parser
-kconfig_mconf_CFLAGS = $(AM_CFLAGS) \
-                       $(kf_CFLAGS)
-kconfig_mconf_LDADD = $(top_builddir)/libs/parser/libkconfig-parser.la      \
-                      $(top_builddir)/libs/lxdialog/libkconfig-lxdialog.a   \
-                      $(ncurses_LIBS) $(mconf_EXTRA_LIBS)
+mconf_SOURCES = mconf.c
+mconf_CPPFLAGS = $(AM_CPPFLAGS)                 \
+                 -DCURSES_LOC='"$(CURSES_LOC)"' \
+                 $(GETTEXT)                     \
+                 -I$(top_srcdir)/libs           \
+                 -I$(top_srcdir)/libs/parser
+mconf_CFLAGS = $(AM_CFLAGS) \
+               $(kf_CFLAGS)
+mconf_LDADD = $(top_builddir)/libs/parser/libkconfig-parser.la      \
+              $(top_builddir)/libs/lxdialog/libkconfig-lxdialog.a   \
+              $(ncurses_LIBS) $(mconf_EXTRA_LIBS)
index 9127dd9b1cbb205f561aebcc27323303b340f1f3..00c9ca7769fc16957556302cc9891b709bf6a666 100644 (file)
@@ -1,11 +1,11 @@
-bin_PROGRAMS = kconfig-nconf
+bin_PROGRAMS = nconf
 
-kconfig_nconf_SOURCES = nconf.c nconf.gui.c nconf.h
-kconfig_nconf_CPPFLAGS = $(AM_CPPFLAGS) \
-                         $(GETTEXT)     \
-                         -I$(top_srcdir)/libs/parser
-kconfig_nconf_CFLAGS = $(AM_CFLAGS) \
-                       $(kf_CFLAGS)
-kconfig_nconf_LDADD = $(top_builddir)/libs/parser/libkconfig-parser.la  \
-                      $(ncurses_extra_LIBS) $(ncurses_LIBS)             \
-                      $(nconf_EXTRA_LIBS)
+nconf_SOURCES = nconf.c nconf.gui.c nconf.h
+nconf_CPPFLAGS = $(AM_CPPFLAGS) \
+                 $(GETTEXT)     \
+                 -I$(top_srcdir)/libs/parser
+nconf_CFLAGS = $(AM_CFLAGS) \
+               $(kf_CFLAGS)
+nconf_LDADD = $(top_builddir)/libs/parser/libkconfig-parser.la  \
+              $(ncurses_extra_LIBS) $(ncurses_LIBS)             \
+              $(nconf_EXTRA_LIBS)
index 99809b7a12d9ede30bd0a6b7ba411afc635a3a4b..f6a66874bb97f0a06f89e6135d73a9a395b27c8c 100644 (file)
@@ -1,17 +1,17 @@
-bin_PROGRAMS = kconfig-qconf
+bin_PROGRAMS = qconf
 
-kconfig_qconf_SOURCES = qconf.cc qconf.h
+qconf_SOURCES = qconf.cc qconf.h
 BUILT_SOURCES = qconf.moc
-kconfig_qconf_CPPFLAGS = $(AM_CPPFLAGS)                 \
-                         $(GETTEXT)                     \
-                         -I$(top_srcdir)/libs/parser    \
-                         -I$(top_builddir)/libs/images
-kconfig_qconf_CXXFLAGS = $(AM_CXXFLAGS) \
-                         $(kf_CFLAGS)   \
-                         $(qt4_CFLAGS)
-kconfig_qconf_LDADD = $(top_builddir)/libs/parser/libkconfig-parser.la  \
-                      $(top_builddir)/libs/images/libkconfig-images.a   \
-                      $(qt4_LIBS) $(qconf_EXTRA_LIBS)
+qconf_CPPFLAGS = $(AM_CPPFLAGS)                 \
+                 $(GETTEXT)                     \
+                 -I$(top_srcdir)/libs/parser    \
+                 -I$(top_builddir)/libs/images
+qconf_CXXFLAGS = $(AM_CXXFLAGS) \
+                 $(kf_CFLAGS)   \
+                 $(qt4_CFLAGS)
+qconf_LDADD = $(top_builddir)/libs/parser/libkconfig-parser.la  \
+              $(top_builddir)/libs/images/libkconfig-images.a   \
+              $(qt4_LIBS) $(qconf_EXTRA_LIBS)
 CLEANFILES = qconf.moc
 
 .h.moc:
index 0268bbb7f7df131ad7d68b9a0362091e9664f1d6..990db30aabd8533e655ea71dbe45c5efa4893d20 100644 (file)
@@ -1,9 +1,9 @@
-dist_bin_SCRIPTS =  kconfig-tweak kconfig-diff kconfig-merge
-dist_bin_SCRIPTS += kconfig-streamline
-bin_PROGRAMS = kconfig-gettext
+dist_bin_SCRIPTS =  tweak diff merge
+dist_bin_SCRIPTS += streamline
+bin_PROGRAMS = gettext
 
-kconfig_gettext_SOURCES = kconfig-gettext.c
-kconfig_gettext_CPPFLAGS = $(AM_CPPFLAGS)   \
-                           -I$(top_srcdir)/libs/parser
-kconfig_gettext_CFLAGS = $(AM_CFLAGS) $(kf_CFLAGS)
-kconfig_gettext_LDADD = $(top_builddir)/libs/parser/libkconfig-parser.la
+gettext_SOURCES = gettext.c
+gettext_CPPFLAGS = $(AM_CPPFLAGS)   \
+                   -I$(top_srcdir)/libs/parser
+gettext_CFLAGS = $(AM_CFLAGS) $(kf_CFLAGS)
+gettext_LDADD = $(top_builddir)/libs/parser/libkconfig-parser.la
diff --git a/utils/diff b/utils/diff
new file mode 100755 (executable)
index 0000000..b91f3e3
--- /dev/null
@@ -0,0 +1,129 @@
+#!/usr/bin/python
+#
+# diffconfig - a tool to compare .config files.
+#
+# originally written in 2006 by Matt Mackall
+#  (at least, this was in his bloatwatch source code)
+# last worked on 2008 by Tim Bird
+#
+
+import sys, os
+
+def usage():
+    print """Usage: diffconfig [-h] [-m] [<config1> <config2>]
+
+Diffconfig is a simple utility for comparing two .config files.
+Using standard diff to compare .config files often includes extraneous and
+distracting information.  This utility produces sorted output with only the
+changes in configuration values between the two files.
+
+Added and removed items are shown with a leading plus or minus, respectively.
+Changed items show the old and new values on a single line.
+
+If -m is specified, then output will be in "merge" style, which has the
+changed and new values in kernel config option format.
+
+If no config files are specified, .config and .config.old are used.
+
+Example usage:
+ $ diffconfig .config config-with-some-changes
+-EXT2_FS_XATTR  n
+-EXT2_FS_XIP  n
+ CRAMFS  n -> y
+ EXT2_FS  y -> n
+ LOG_BUF_SHIFT  14 -> 16
+ PRINTK_TIME  n -> y
+"""
+    sys.exit(0)
+
+# returns a dictionary of name/value pairs for config items in the file
+def readconfig(config_file):
+    d = {}
+    for line in config_file:
+        line = line[:-1]
+        if line[:7] == "CONFIG_":
+            name, val = line[7:].split("=", 1)
+            d[name] = val
+        if line[-11:] == " is not set":
+            d[line[9:-11]] = "n"
+    return d
+
+def print_config(op, config, value, new_value):
+    global merge_style
+
+    if merge_style:
+        if new_value:
+            if new_value=="n":
+                print "# CONFIG_%s is not set" % config
+            else:
+                print "CONFIG_%s=%s" % (config, new_value)
+    else:
+        if op=="-":
+            print "-%s %s" % (config, value)
+        elif op=="+":
+            print "+%s %s" % (config, new_value)
+        else:
+            print " %s %s -> %s" % (config, value, new_value)
+
+def main():
+    global merge_style
+
+    # parse command line args
+    if ("-h" in sys.argv or "--help" in sys.argv):
+       usage()
+
+    merge_style = 0
+    if "-m" in sys.argv:
+        merge_style = 1
+        sys.argv.remove("-m")
+
+    argc = len(sys.argv)
+    if not (argc==1 or argc == 3):
+        print "Error: incorrect number of arguments or unrecognized option"
+        usage()
+
+    if argc == 1:
+        # if no filenames given, assume .config and .config.old
+        build_dir=""
+        if os.environ.has_key("KBUILD_OUTPUT"):
+            build_dir = os.environ["KBUILD_OUTPUT"]+"/"
+
+        configa_filename = build_dir + ".config.old"
+        configb_filename = build_dir + ".config"
+    else:
+        configa_filename = sys.argv[1]
+        configb_filename = sys.argv[2]
+
+    a = readconfig(file(configa_filename))
+    b = readconfig(file(configb_filename))
+
+    # print items in a but not b (accumulate, sort and print)
+    old = []
+    for config in a:
+        if config not in b:
+            old.append(config)
+    old.sort()
+    for config in old:
+        print_config("-", config, a[config], None)
+        del a[config]
+
+    # print items that changed (accumulate, sort, and print)
+    changed = []
+    for config in a:
+        if a[config] != b[config]:
+            changed.append(config)
+        else:
+            del b[config]
+    changed.sort()
+    for config in changed:
+        print_config("->", config, a[config], b[config])
+        del b[config]
+
+    # now print items in b but not in a
+    # (items from b that were in a were removed above)
+    new = b.keys()
+    new.sort()
+    for config in new:
+        print_config("+", config, None, b[config])
+
+main()
diff --git a/utils/gettext.c b/utils/gettext.c
new file mode 100644 (file)
index 0000000..2858738
--- /dev/null
@@ -0,0 +1,235 @@
+/*
+ * Arnaldo Carvalho de Melo <acme@conectiva.com.br>, 2005
+ *
+ * Released under the terms of the GNU GPL v2.0
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "lkc.h"
+
+static char *escape(const char* text, char *bf, int len)
+{
+       char *bfp = bf;
+       int multiline = strchr(text, '\n') != NULL;
+       int eol = 0;
+       int textlen = strlen(text);
+
+       if ((textlen > 0) && (text[textlen-1] == '\n'))
+               eol = 1;
+
+       *bfp++ = '"';
+       --len;
+
+       if (multiline) {
+               *bfp++ = '"';
+               *bfp++ = '\n';
+               *bfp++ = '"';
+               len -= 3;
+       }
+
+       while (*text != '\0' && len > 1) {
+               if (*text == '"')
+                       *bfp++ = '\\';
+               else if (*text == '\n') {
+                       *bfp++ = '\\';
+                       *bfp++ = 'n';
+                       *bfp++ = '"';
+                       *bfp++ = '\n';
+                       *bfp++ = '"';
+                       len -= 5;
+                       ++text;
+                       goto next;
+               }
+               else if (*text == '\\') {
+                       *bfp++ = '\\';
+                       len--;
+               }
+               *bfp++ = *text++;
+next:
+               --len;
+       }
+
+       if (multiline && eol)
+               bfp -= 3;
+
+       *bfp++ = '"';
+       *bfp = '\0';
+
+       return bf;
+}
+
+struct file_line {
+       struct file_line *next;
+       const char *file;
+       int lineno;
+};
+
+static struct file_line *file_line__new(const char *file, int lineno)
+{
+       struct file_line *self = malloc(sizeof(*self));
+
+       if (self == NULL)
+               goto out;
+
+       self->file   = file;
+       self->lineno = lineno;
+       self->next   = NULL;
+out:
+       return self;
+}
+
+struct message {
+       const char       *msg;
+       const char       *option;
+       struct message   *next;
+       struct file_line *files;
+};
+
+static struct message *message__list;
+
+static struct message *message__new(const char *msg, char *option,
+                                   const char *file, int lineno)
+{
+       struct message *self = malloc(sizeof(*self));
+
+       if (self == NULL)
+               goto out;
+
+       self->files = file_line__new(file, lineno);
+       if (self->files == NULL)
+               goto out_fail;
+
+       self->msg = strdup(msg);
+       if (self->msg == NULL)
+               goto out_fail_msg;
+
+       self->option = option;
+       self->next = NULL;
+out:
+       return self;
+out_fail_msg:
+       free(self->files);
+out_fail:
+       free(self);
+       self = NULL;
+       goto out;
+}
+
+static struct message *mesage__find(const char *msg)
+{
+       struct message *m = message__list;
+
+       while (m != NULL) {
+               if (strcmp(m->msg, msg) == 0)
+                       break;
+               m = m->next;
+       }
+
+       return m;
+}
+
+static int message__add_file_line(struct message *self, const char *file,
+                                 int lineno)
+{
+       int rc = -1;
+       struct file_line *fl = file_line__new(file, lineno);
+
+       if (fl == NULL)
+               goto out;
+
+       fl->next    = self->files;
+       self->files = fl;
+       rc = 0;
+out:
+       return rc;
+}
+
+static int message__add(const char *msg, char *option, const char *file,
+                       int lineno)
+{
+       int rc = 0;
+       char bf[16384];
+       char *escaped = escape(msg, bf, sizeof(bf));
+       struct message *m = mesage__find(escaped);
+
+       if (m != NULL)
+               rc = message__add_file_line(m, file, lineno);
+       else {
+               m = message__new(escaped, option, file, lineno);
+
+               if (m != NULL) {
+                       m->next       = message__list;
+                       message__list = m;
+               } else
+                       rc = -1;
+       }
+       return rc;
+}
+
+static void menu_build_message_list(struct menu *menu)
+{
+       struct menu *child;
+
+       message__add(menu_get_prompt(menu), NULL,
+                    menu->file == NULL ? "Root Menu" : menu->file->name,
+                    menu->lineno);
+
+       if (menu->sym != NULL && menu_has_help(menu))
+               message__add(menu_get_help(menu), menu->sym->name,
+                            menu->file == NULL ? "Root Menu" : menu->file->name,
+                            menu->lineno);
+
+       for (child = menu->list; child != NULL; child = child->next)
+               if (child->prompt != NULL)
+                       menu_build_message_list(child);
+}
+
+static void message__print_file_lineno(struct message *self)
+{
+       struct file_line *fl = self->files;
+
+       putchar('\n');
+       if (self->option != NULL)
+               printf("# %s:00000\n", self->option);
+
+       printf("#: %s:%d", fl->file, fl->lineno);
+       fl = fl->next;
+
+       while (fl != NULL) {
+               printf(", %s:%d", fl->file, fl->lineno);
+               fl = fl->next;
+       }
+
+       putchar('\n');
+}
+
+static void message__print_gettext_msgid_msgstr(struct message *self)
+{
+       message__print_file_lineno(self);
+
+       printf("msgid %s\n"
+              "msgstr \"\"\n", self->msg);
+}
+
+static void menu__xgettext(void)
+{
+       struct message *m = message__list;
+
+       while (m != NULL) {
+               /* skip empty lines ("") */
+               if (strlen(m->msg) > sizeof("\"\""))
+                       message__print_gettext_msgid_msgstr(m);
+               m = m->next;
+       }
+}
+
+int main(int ac, char **av)
+{
+       conf_parse(av[1]);
+
+       menu_build_message_list(menu_get_root_menu(NULL));
+       menu__xgettext();
+       return 0;
+}
diff --git a/utils/kconfig-diff b/utils/kconfig-diff
deleted file mode 100755 (executable)
index b91f3e3..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-#!/usr/bin/python
-#
-# diffconfig - a tool to compare .config files.
-#
-# originally written in 2006 by Matt Mackall
-#  (at least, this was in his bloatwatch source code)
-# last worked on 2008 by Tim Bird
-#
-
-import sys, os
-
-def usage():
-    print """Usage: diffconfig [-h] [-m] [<config1> <config2>]
-
-Diffconfig is a simple utility for comparing two .config files.
-Using standard diff to compare .config files often includes extraneous and
-distracting information.  This utility produces sorted output with only the
-changes in configuration values between the two files.
-
-Added and removed items are shown with a leading plus or minus, respectively.
-Changed items show the old and new values on a single line.
-
-If -m is specified, then output will be in "merge" style, which has the
-changed and new values in kernel config option format.
-
-If no config files are specified, .config and .config.old are used.
-
-Example usage:
- $ diffconfig .config config-with-some-changes
--EXT2_FS_XATTR  n
--EXT2_FS_XIP  n
- CRAMFS  n -> y
- EXT2_FS  y -> n
- LOG_BUF_SHIFT  14 -> 16
- PRINTK_TIME  n -> y
-"""
-    sys.exit(0)
-
-# returns a dictionary of name/value pairs for config items in the file
-def readconfig(config_file):
-    d = {}
-    for line in config_file:
-        line = line[:-1]
-        if line[:7] == "CONFIG_":
-            name, val = line[7:].split("=", 1)
-            d[name] = val
-        if line[-11:] == " is not set":
-            d[line[9:-11]] = "n"
-    return d
-
-def print_config(op, config, value, new_value):
-    global merge_style
-
-    if merge_style:
-        if new_value:
-            if new_value=="n":
-                print "# CONFIG_%s is not set" % config
-            else:
-                print "CONFIG_%s=%s" % (config, new_value)
-    else:
-        if op=="-":
-            print "-%s %s" % (config, value)
-        elif op=="+":
-            print "+%s %s" % (config, new_value)
-        else:
-            print " %s %s -> %s" % (config, value, new_value)
-
-def main():
-    global merge_style
-
-    # parse command line args
-    if ("-h" in sys.argv or "--help" in sys.argv):
-       usage()
-
-    merge_style = 0
-    if "-m" in sys.argv:
-        merge_style = 1
-        sys.argv.remove("-m")
-
-    argc = len(sys.argv)
-    if not (argc==1 or argc == 3):
-        print "Error: incorrect number of arguments or unrecognized option"
-        usage()
-
-    if argc == 1:
-        # if no filenames given, assume .config and .config.old
-        build_dir=""
-        if os.environ.has_key("KBUILD_OUTPUT"):
-            build_dir = os.environ["KBUILD_OUTPUT"]+"/"
-
-        configa_filename = build_dir + ".config.old"
-        configb_filename = build_dir + ".config"
-    else:
-        configa_filename = sys.argv[1]
-        configb_filename = sys.argv[2]
-
-    a = readconfig(file(configa_filename))
-    b = readconfig(file(configb_filename))
-
-    # print items in a but not b (accumulate, sort and print)
-    old = []
-    for config in a:
-        if config not in b:
-            old.append(config)
-    old.sort()
-    for config in old:
-        print_config("-", config, a[config], None)
-        del a[config]
-
-    # print items that changed (accumulate, sort, and print)
-    changed = []
-    for config in a:
-        if a[config] != b[config]:
-            changed.append(config)
-        else:
-            del b[config]
-    changed.sort()
-    for config in changed:
-        print_config("->", config, a[config], b[config])
-        del b[config]
-
-    # now print items in b but not in a
-    # (items from b that were in a were removed above)
-    new = b.keys()
-    new.sort()
-    for config in new:
-        print_config("+", config, None, b[config])
-
-main()
diff --git a/utils/kconfig-gettext.c b/utils/kconfig-gettext.c
deleted file mode 100644 (file)
index 2858738..0000000
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Arnaldo Carvalho de Melo <acme@conectiva.com.br>, 2005
- *
- * Released under the terms of the GNU GPL v2.0
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "lkc.h"
-
-static char *escape(const char* text, char *bf, int len)
-{
-       char *bfp = bf;
-       int multiline = strchr(text, '\n') != NULL;
-       int eol = 0;
-       int textlen = strlen(text);
-
-       if ((textlen > 0) && (text[textlen-1] == '\n'))
-               eol = 1;
-
-       *bfp++ = '"';
-       --len;
-
-       if (multiline) {
-               *bfp++ = '"';
-               *bfp++ = '\n';
-               *bfp++ = '"';
-               len -= 3;
-       }
-
-       while (*text != '\0' && len > 1) {
-               if (*text == '"')
-                       *bfp++ = '\\';
-               else if (*text == '\n') {
-                       *bfp++ = '\\';
-                       *bfp++ = 'n';
-                       *bfp++ = '"';
-                       *bfp++ = '\n';
-                       *bfp++ = '"';
-                       len -= 5;
-                       ++text;
-                       goto next;
-               }
-               else if (*text == '\\') {
-                       *bfp++ = '\\';
-                       len--;
-               }
-               *bfp++ = *text++;
-next:
-               --len;
-       }
-
-       if (multiline && eol)
-               bfp -= 3;
-
-       *bfp++ = '"';
-       *bfp = '\0';
-
-       return bf;
-}
-
-struct file_line {
-       struct file_line *next;
-       const char *file;
-       int lineno;
-};
-
-static struct file_line *file_line__new(const char *file, int lineno)
-{
-       struct file_line *self = malloc(sizeof(*self));
-
-       if (self == NULL)
-               goto out;
-
-       self->file   = file;
-       self->lineno = lineno;
-       self->next   = NULL;
-out:
-       return self;
-}
-
-struct message {
-       const char       *msg;
-       const char       *option;
-       struct message   *next;
-       struct file_line *files;
-};
-
-static struct message *message__list;
-
-static struct message *message__new(const char *msg, char *option,
-                                   const char *file, int lineno)
-{
-       struct message *self = malloc(sizeof(*self));
-
-       if (self == NULL)
-               goto out;
-
-       self->files = file_line__new(file, lineno);
-       if (self->files == NULL)
-               goto out_fail;
-
-       self->msg = strdup(msg);
-       if (self->msg == NULL)
-               goto out_fail_msg;
-
-       self->option = option;
-       self->next = NULL;
-out:
-       return self;
-out_fail_msg:
-       free(self->files);
-out_fail:
-       free(self);
-       self = NULL;
-       goto out;
-}
-
-static struct message *mesage__find(const char *msg)
-{
-       struct message *m = message__list;
-
-       while (m != NULL) {
-               if (strcmp(m->msg, msg) == 0)
-                       break;
-               m = m->next;
-       }
-
-       return m;
-}
-
-static int message__add_file_line(struct message *self, const char *file,
-                                 int lineno)
-{
-       int rc = -1;
-       struct file_line *fl = file_line__new(file, lineno);
-
-       if (fl == NULL)
-               goto out;
-
-       fl->next    = self->files;
-       self->files = fl;
-       rc = 0;
-out:
-       return rc;
-}
-
-static int message__add(const char *msg, char *option, const char *file,
-                       int lineno)
-{
-       int rc = 0;
-       char bf[16384];
-       char *escaped = escape(msg, bf, sizeof(bf));
-       struct message *m = mesage__find(escaped);
-
-       if (m != NULL)
-               rc = message__add_file_line(m, file, lineno);
-       else {
-               m = message__new(escaped, option, file, lineno);
-
-               if (m != NULL) {
-                       m->next       = message__list;
-                       message__list = m;
-               } else
-                       rc = -1;
-       }
-       return rc;
-}
-
-static void menu_build_message_list(struct menu *menu)
-{
-       struct menu *child;
-
-       message__add(menu_get_prompt(menu), NULL,
-                    menu->file == NULL ? "Root Menu" : menu->file->name,
-                    menu->lineno);
-
-       if (menu->sym != NULL && menu_has_help(menu))
-               message__add(menu_get_help(menu), menu->sym->name,
-                            menu->file == NULL ? "Root Menu" : menu->file->name,
-                            menu->lineno);
-
-       for (child = menu->list; child != NULL; child = child->next)
-               if (child->prompt != NULL)
-                       menu_build_message_list(child);
-}
-
-static void message__print_file_lineno(struct message *self)
-{
-       struct file_line *fl = self->files;
-
-       putchar('\n');
-       if (self->option != NULL)
-               printf("# %s:00000\n", self->option);
-
-       printf("#: %s:%d", fl->file, fl->lineno);
-       fl = fl->next;
-
-       while (fl != NULL) {
-               printf(", %s:%d", fl->file, fl->lineno);
-               fl = fl->next;
-       }
-
-       putchar('\n');
-}
-
-static void message__print_gettext_msgid_msgstr(struct message *self)
-{
-       message__print_file_lineno(self);
-
-       printf("msgid %s\n"
-              "msgstr \"\"\n", self->msg);
-}
-
-static void menu__xgettext(void)
-{
-       struct message *m = message__list;
-
-       while (m != NULL) {
-               /* skip empty lines ("") */
-               if (strlen(m->msg) > sizeof("\"\""))
-                       message__print_gettext_msgid_msgstr(m);
-               m = m->next;
-       }
-}
-
-int main(int ac, char **av)
-{
-       conf_parse(av[1]);
-
-       menu_build_message_list(menu_get_root_menu(NULL));
-       menu__xgettext();
-       return 0;
-}
diff --git a/utils/kconfig-merge b/utils/kconfig-merge
deleted file mode 100755 (executable)
index 974d5cb..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-#!/bin/sh
-#  merge_config.sh - Takes a list of config fragment values, and merges
-#  them one by one. Provides warnings on overridden values, and specified
-#  values that did not make it to the resulting .config file (due to missed
-#  dependencies or config symbol removal).
-#
-#  Portions reused from kconf_check and generate_cfg:
-#  http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/kconf_check
-#  http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/generate_cfg
-#
-#  Copyright (c) 2009-2010 Wind River Systems, Inc.
-#  Copyright 2011 Linaro
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License version 2 as
-#  published by the Free Software Foundation.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-#  See the GNU General Public License for more details.
-
-clean_up() {
-       rm -f $TMP_FILE
-       exit
-}
-trap clean_up HUP INT TERM
-
-usage() {
-       echo "Usage: $0 [OPTIONS] [CONFIG [...]]"
-       echo "  -h    display this help text"
-       echo "  -m    only merge the fragments, do not execute the make command"
-       echo "  -n    use allnoconfig instead of alldefconfig"
-       echo "  -r    list redundant entries when merging fragments"
-}
-
-MAKE=true
-ALLTARGET=alldefconfig
-WARNREDUN=false
-
-while true; do
-       case $1 in
-       "-n")
-               ALLTARGET=allnoconfig
-               shift
-               continue
-               ;;
-       "-m")
-               MAKE=false
-               shift
-               continue
-               ;;
-       "-h")
-               usage
-               exit
-               ;;
-       "-r")
-               WARNREDUN=true
-               shift
-               continue
-               ;;
-       *)
-               break
-               ;;
-       esac
-done
-
-INITFILE=$1
-shift;
-
-MERGE_LIST=$*
-SED_CONFIG_EXP="s/^\(# \)\{0,1\}\(CONFIG_[a-zA-Z0-9_]*\)[= ].*/\2/p"
-TMP_FILE=$(mktemp ./.tmp.config.XXXXXXXXXX)
-
-echo "Using $INITFILE as base"
-cat $INITFILE > $TMP_FILE
-
-# Merge files, printing warnings on overrided values
-for MERGE_FILE in $MERGE_LIST ; do
-       echo "Merging $MERGE_FILE"
-       CFG_LIST=$(sed -n "$SED_CONFIG_EXP" $MERGE_FILE)
-
-       for CFG in $CFG_LIST ; do
-               grep -q -w $CFG $TMP_FILE
-               if [ $? -eq 0 ] ; then
-                       PREV_VAL=$(grep -w $CFG $TMP_FILE)
-                       NEW_VAL=$(grep -w $CFG $MERGE_FILE)
-                       if [ "x$PREV_VAL" != "x$NEW_VAL" ] ; then
-                       echo Value of $CFG is redefined by fragment $MERGE_FILE:
-                       echo Previous  value: $PREV_VAL
-                       echo New value:       $NEW_VAL
-                       echo
-                       elif [ "$WARNREDUN" = "true" ]; then
-                       echo Value of $CFG is redundant by fragment $MERGE_FILE:
-                       fi
-                       sed -i "/$CFG[ =]/d" $TMP_FILE
-               fi
-       done
-       cat $MERGE_FILE >> $TMP_FILE
-done
-
-if [ "$MAKE" = "false" ]; then
-       cp $TMP_FILE .config
-       echo "#"
-       echo "# merged configuration written to .config (needs make)"
-       echo "#"
-       clean_up
-       exit
-fi
-
-# Use the merged file as the starting point for:
-# alldefconfig: Fills in any missing symbols with Kconfig default
-# allnoconfig: Fills in any missing symbols with # CONFIG_* is not set
-make KCONFIG_ALLCONFIG=$TMP_FILE $ALLTARGET
-
-
-# Check all specified config values took (might have missed-dependency issues)
-for CFG in $(sed -n "$SED_CONFIG_EXP" $TMP_FILE); do
-
-       REQUESTED_VAL=$(grep -w -e "$CFG" $TMP_FILE)
-       ACTUAL_VAL=$(grep -w -e "$CFG" .config)
-       if [ "x$REQUESTED_VAL" != "x$ACTUAL_VAL" ] ; then
-               echo "Value requested for $CFG not in final .config"
-               echo "Requested value:  $REQUESTED_VAL"
-               echo "Actual value:     $ACTUAL_VAL"
-               echo ""
-       fi
-done
-
-clean_up
diff --git a/utils/kconfig-streamline b/utils/kconfig-streamline
deleted file mode 100755 (executable)
index bccf07d..0000000
+++ /dev/null
@@ -1,495 +0,0 @@
-#!/usr/bin/perl -w
-#
-# Copyright 2005-2009 - Steven Rostedt
-# Licensed under the terms of the GNU GPL License version 2
-#
-#  It's simple enough to figure out how this works.
-#  If not, then you can ask me at stripconfig@goodmis.org
-#
-# What it does?
-#
-#   If you have installed a Linux kernel from a distribution
-#   that turns on way too many modules than you need, and
-#   you only want the modules you use, then this program
-#   is perfect for you.
-#
-#   It gives you the ability to turn off all the modules that are
-#   not loaded on your system.
-#
-# Howto:
-#
-#  1. Boot up the kernel that you want to stream line the config on.
-#  2. Change directory to the directory holding the source of the
-#       kernel that you just booted.
-#  3. Copy the configuraton file to this directory as .config
-#  4. Have all your devices that you need modules for connected and
-#      operational (make sure that their corresponding modules are loaded)
-#  5. Run this script redirecting the output to some other file
-#       like config_strip.
-#  6. Back up your old config (if you want too).
-#  7. copy the config_strip file to .config
-#  8. Run "make oldconfig"
-#
-#  Now your kernel is ready to be built with only the modules that
-#  are loaded.
-#
-# Here's what I did with my Debian distribution.
-#
-#    cd /usr/src/linux-2.6.10
-#    cp /boot/config-2.6.10-1-686-smp .config
-#    ~/bin/streamline_config > config_strip
-#    mv .config config_sav
-#    mv config_strip .config
-#    make oldconfig
-#
-use strict;
-use Getopt::Long;
-
-my $config = ".config";
-
-my $uname = `uname -r`;
-chomp $uname;
-
-my @searchconfigs = (
-       {
-           "file" => ".config",
-           "exec" => "cat",
-       },
-       {
-           "file" => "/proc/config.gz",
-           "exec" => "zcat",
-       },
-       {
-           "file" => "/boot/config-$uname",
-           "exec" => "cat",
-       },
-       {
-           "file" => "/boot/vmlinuz-$uname",
-           "exec" => "scripts/extract-ikconfig",
-           "test" => "scripts/extract-ikconfig",
-       },
-       {
-           "file" => "vmlinux",
-           "exec" => "scripts/extract-ikconfig",
-           "test" => "scripts/extract-ikconfig",
-       },
-       {
-           "file" => "/lib/modules/$uname/kernel/kernel/configs.ko",
-           "exec" => "scripts/extract-ikconfig",
-           "test" => "scripts/extract-ikconfig",
-       },
-       {
-           "file" => "kernel/configs.ko",
-           "exec" => "scripts/extract-ikconfig",
-           "test" => "scripts/extract-ikconfig",
-       },
-       {
-           "file" => "kernel/configs.o",
-           "exec" => "scripts/extract-ikconfig",
-           "test" => "scripts/extract-ikconfig",
-       },
-);
-
-sub find_config {
-    foreach my $conf (@searchconfigs) {
-       my $file = $conf->{"file"};
-
-       next if ( ! -f "$file");
-
-       if (defined($conf->{"test"})) {
-           `$conf->{"test"} $conf->{"file"} 2>/dev/null`;
-           next if ($?);
-       }
-
-       my $exec = $conf->{"exec"};
-
-       print STDERR "using config: '$file'\n";
-
-       open(CIN, "$exec $file |") || die "Failed to run $exec $file";
-       return;
-    }
-    die "No config file found";
-}
-
-find_config;
-
-# Parse options
-my $localmodconfig = 0;
-my $localyesconfig = 0;
-
-GetOptions("localmodconfig" => \$localmodconfig,
-          "localyesconfig" => \$localyesconfig);
-
-# Get the build source and top level Kconfig file (passed in)
-my $ksource = $ARGV[0];
-my $kconfig = $ARGV[1];
-my $lsmod_file = $ENV{'LSMOD'};
-
-my @makefiles = `find $ksource -name Makefile 2>/dev/null`;
-chomp @makefiles;
-
-my %depends;
-my %selects;
-my %prompts;
-my %objects;
-my $var;
-my $iflevel = 0;
-my @ifdeps;
-
-# prevent recursion
-my %read_kconfigs;
-
-sub read_kconfig {
-    my ($kconfig) = @_;
-
-    my $state = "NONE";
-    my $config;
-    my @kconfigs;
-
-    my $cont = 0;
-    my $line;
-
-    my $source = "$ksource/$kconfig";
-    my $last_source = "";
-
-    # Check for any environment variables used
-    while ($source =~ /\$(\w+)/ && $last_source ne $source) {
-       my $env = $1;
-       $last_source = $source;
-       $source =~ s/\$$env/$ENV{$env}/;
-    }
-
-    open(KIN, "$source") || die "Can't open $kconfig";
-    while (<KIN>) {
-       chomp;
-
-       # Make sure that lines ending with \ continue
-       if ($cont) {
-           $_ = $line . " " . $_;
-       }
-
-       if (s/\\$//) {
-           $cont = 1;
-           $line = $_;
-           next;
-       }
-
-       $cont = 0;
-
-       # collect any Kconfig sources
-       if (/^source\s*"(.*)"/) {
-           $kconfigs[$#kconfigs+1] = $1;
-       }
-
-       # configs found
-       if (/^\s*(menu)?config\s+(\S+)\s*$/) {
-           $state = "NEW";
-           $config = $2;
-
-           for (my $i = 0; $i < $iflevel; $i++) {
-               if ($i) {
-                   $depends{$config} .= " " . $ifdeps[$i];
-               } else {
-                   $depends{$config} = $ifdeps[$i];
-               }
-               $state = "DEP";
-           }
-
-       # collect the depends for the config
-       } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
-           $state = "DEP";
-           $depends{$config} = $1;
-       } elsif ($state eq "DEP" && /^\s*depends\s+on\s+(.*)$/) {
-           $depends{$config} .= " " . $1;
-
-       # Get the configs that select this config
-       } elsif ($state ne "NONE" && /^\s*select\s+(\S+)/) {
-           if (defined($selects{$1})) {
-               $selects{$1} .= " " . $config;
-           } else {
-               $selects{$1} = $config;
-           }
-
-       # configs without prompts must be selected
-       } elsif ($state ne "NONE" && /^\s*tristate\s\S/) {
-           # note if the config has a prompt
-           $prompts{$config} = 1;
-
-       # Check for if statements
-       } elsif (/^if\s+(.*\S)\s*$/) {
-           my $deps = $1;
-           # remove beginning and ending non text
-           $deps =~ s/^[^a-zA-Z0-9_]*//;
-           $deps =~ s/[^a-zA-Z0-9_]*$//;
-
-           my @deps = split /[^a-zA-Z0-9_]+/, $deps;
-
-           $ifdeps[$iflevel++] = join ':', @deps;
-
-       } elsif (/^endif/) {
-
-           $iflevel-- if ($iflevel);
-
-       # stop on "help"
-       } elsif (/^\s*help\s*$/) {
-           $state = "NONE";
-       }
-    }
-    close(KIN);
-
-    # read in any configs that were found.
-    foreach $kconfig (@kconfigs) {
-       if (!defined($read_kconfigs{$kconfig})) {
-           $read_kconfigs{$kconfig} = 1;
-           read_kconfig($kconfig);
-       }
-    }
-}
-
-if ($kconfig) {
-    read_kconfig($kconfig);
-}
-
-sub convert_vars {
-    my ($line, %vars) = @_;
-
-    my $process = "";
-
-    while ($line =~ s/^(.*?)(\$\((.*?)\))//) {
-       my $start = $1;
-       my $variable = $2;
-       my $var = $3;
-
-       if (defined($vars{$var})) {
-           $process .= $start . $vars{$var};
-       } else {
-           $process .= $start . $variable;
-       }
-    }
-
-    $process .= $line;
-
-    return $process;
-}
-
-# Read all Makefiles to map the configs to the objects
-foreach my $makefile (@makefiles) {
-
-    my $line = "";
-    my %make_vars;
-
-    open(MIN,$makefile) || die "Can't open $makefile";
-    while (<MIN>) {
-       # if this line ends with a backslash, continue
-       chomp;
-       if (/^(.*)\\$/) {
-           $line .= $1;
-           next;
-       }
-
-       $line .= $_;
-       $_ = $line;
-       $line = "";
-
-       my $objs;
-
-       $_ = convert_vars($_, %make_vars);
-
-       # collect objects after obj-$(CONFIG_FOO_BAR)
-       if (/obj-\$\((CONFIG_[^\)]*)\)\s*[+:]?=\s*(.*)/) {
-           $var = $1;
-           $objs = $2;
-
-       # check if variables are set
-       } elsif (/^\s*(\S+)\s*[:]?=\s*(.*\S)/) {
-           $make_vars{$1} = $2;
-       }
-       if (defined($objs)) {
-           foreach my $obj (split /\s+/,$objs) {
-               $obj =~ s/-/_/g;
-               if ($obj =~ /(.*)\.o$/) {
-                   # Objects may be enabled by more than one config.
-                   # Store configs in an array.
-                   my @arr;
-
-                   if (defined($objects{$1})) {
-                       @arr = @{$objects{$1}};
-                   }
-
-                   $arr[$#arr+1] = $var;
-
-                   # The objects have a hash mapping to a reference
-                   # of an array of configs.
-                   $objects{$1} = \@arr;
-               }
-           }
-       }
-    }
-    close(MIN);
-}
-
-my %modules;
-
-if (defined($lsmod_file)) {
-    if ( ! -f $lsmod_file) {
-       if ( -f $ENV{'objtree'}."/".$lsmod_file) {
-           $lsmod_file = $ENV{'objtree'}."/".$lsmod_file;
-       } else {
-               die "$lsmod_file not found";
-       }
-    }
-    if ( -x $lsmod_file) {
-       # the file is executable, run it
-       open(LIN, "$lsmod_file|");
-    } else {
-       # Just read the contents
-       open(LIN, "$lsmod_file");
-    }
-} else {
-
-    # see what modules are loaded on this system
-    my $lsmod;
-
-    foreach my $dir ( ("/sbin", "/bin", "/usr/sbin", "/usr/bin") ) {
-       if ( -x "$dir/lsmod" ) {
-           $lsmod = "$dir/lsmod";
-           last;
-       }
-}
-    if (!defined($lsmod)) {
-       # try just the path
-       $lsmod = "lsmod";
-    }
-
-    open(LIN,"$lsmod|") || die "Can not call lsmod with $lsmod";
-}
-
-while (<LIN>) {
-       next if (/^Module/);  # Skip the first line.
-       if (/^(\S+)/) {
-               $modules{$1} = 1;
-       }
-}
-close (LIN);
-
-# add to the configs hash all configs that are needed to enable
-# a loaded module.
-my %configs;
-foreach my $module (keys(%modules)) {
-    if (defined($objects{$module})) {
-       my @arr = @{$objects{$module}};
-       foreach my $conf (@arr) {
-           $configs{$conf} = $module;
-       }
-    } else {
-       # Most likely, someone has a custom (binary?) module loaded.
-       print STDERR "$module config not found!!\n";
-    }
-}
-
-my $valid = "A-Za-z_0-9";
-my $repeat = 1;
-
-#
-# Note, we do not care about operands (like: &&, ||, !) we want to add any
-# config that is in the depend list of another config. This script does
-# not enable configs that are not already enabled. If we come across a
-# config A that depends on !B, we can still add B to the list of depends
-# to keep on. If A was on in the original config, B would not have been
-# and B would not be turned on by this script.
-#
-sub parse_config_dep_select
-{
-    my ($p) = @_;
-
-    while ($p =~ /[$valid]/) {
-
-       if ($p =~ /^[^$valid]*([$valid]+)/) {
-           my $conf = "CONFIG_" . $1;
-
-           $p =~ s/^[^$valid]*[$valid]+//;
-
-           if (!defined($configs{$conf})) {
-               # We must make sure that this config has its
-               # dependencies met.
-               $repeat = 1; # do again
-               $configs{$conf} = 1;
-           }
-       } else {
-           die "this should never happen";
-       }
-    }
-}
-
-while ($repeat) {
-    $repeat = 0;
-
-    foreach my $config (keys %configs) {
-       $config =~ s/^CONFIG_//;
-
-       if (defined($depends{$config})) {
-           # This config has dependencies. Make sure they are also included
-           parse_config_dep_select $depends{$config};
-       }
-
-       if (defined($prompts{$config}) || !defined($selects{$config})) {
-           next;
-       }
-
-       # config has no prompt and must be selected.
-       parse_config_dep_select $selects{$config};
-    }
-}
-
-my %setconfigs;
-
-# Finally, read the .config file and turn off any module enabled that
-# we could not find a reason to keep enabled.
-while(<CIN>) {
-
-    if (/CONFIG_IKCONFIG/) {
-       if (/# CONFIG_IKCONFIG is not set/) {
-           # enable IKCONFIG at least as a module
-           print "CONFIG_IKCONFIG=m\n";
-           # don't ask about PROC
-           print "# CONFIG_IKCONFIG_PROC is not set\n";
-       } else {
-           print;
-       }
-       next;
-    }
-
-    if (/^(CONFIG.*)=(m|y)/) {
-       if (defined($configs{$1})) {
-           if ($localyesconfig) {
-               $setconfigs{$1} = 'y';
-           } else {
-               $setconfigs{$1} = $2;
-           }
-       } elsif ($2 eq "m") {
-           print "# $1 is not set\n";
-           next;
-       }
-    }
-    print;
-}
-close(CIN);
-
-# Integrity check, make sure all modules that we want enabled do
-# indeed have their configs set.
-loop:
-foreach my $module (keys(%modules)) {
-    if (defined($objects{$module})) {
-       my @arr = @{$objects{$module}};
-       foreach my $conf (@arr) {
-           if (defined($setconfigs{$conf})) {
-               next loop;
-           }
-       }
-       print STDERR "module $module did not have configs";
-       foreach my $conf (@arr) {
-           print STDERR " " , $conf;
-       }
-       print STDERR "\n";
-    }
-}
diff --git a/utils/kconfig-tweak b/utils/kconfig-tweak
deleted file mode 100755 (executable)
index a7c7c4b..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-#!/bin/bash
-# Manipulate options in a .config file from the command line
-
-usage() {
-       cat >&2 <<EOL
-Manipulate options in a .config file from the command line.
-Usage:
-config options command ...
-commands:
-       --enable|-e option   Enable option
-       --disable|-d option  Disable option
-       --module|-m option   Turn option into a module
-       --set-str option string
-                            Set option to "string"
-       --set-val option value
-                            Set option to value
-       --state|-s option    Print state of option (n,y,m,undef)
-
-       --enable-after|-E beforeopt option
-                             Enable option directly after other option
-       --disable-after|-D beforeopt option
-                             Disable option directly after other option
-       --module-after|-M beforeopt option
-                             Turn option into module directly after other option
-
-       commands can be repeated multiple times
-
-options:
-       --file .config file to change (default .config)
-
-config doesn't check the validity of the .config file. This is done at next
- make time.
-EOL
-       exit 1
-}
-
-checkarg() {
-       ARG="$1"
-       if [ "$ARG" = "" ] ; then
-               usage
-       fi
-       case "$ARG" in
-       CONFIG_*)
-               ARG="${ARG/CONFIG_/}"
-               ;;
-       esac
-       ARG="`echo $ARG | tr a-z A-Z`"
-}
-
-set_var() {
-       local name=$1 new=$2 before=$3
-
-       name_re="^($name=|# $name is not set)"
-       before_re="^($before=|# $before is not set)"
-       if test -n "$before" && grep -Eq "$before_re" "$FN"; then
-               sed -ri "/$before_re/a $new" "$FN"
-       elif grep -Eq "$name_re" "$FN"; then
-               sed -ri "s:$name_re.*:$new:" "$FN"
-       else
-               echo "$new" >>"$FN"
-       fi
-}
-
-if [ "$1" = "--file" ]; then
-       FN="$2"
-       if [ "$FN" = "" ] ; then
-               usage
-       fi
-       shift 2
-else
-       FN=.config
-fi
-
-if [ "$1" = "" ] ; then
-       usage
-fi
-
-while [ "$1" != "" ] ; do
-       CMD="$1"
-       shift
-       case "$CMD" in
-       --refresh)
-               ;;
-       --*-after)
-               checkarg "$1"
-               A=$ARG
-               checkarg "$2"
-               B=$ARG
-               shift 2
-               ;;
-       -*)
-               checkarg "$1"
-               shift
-               ;;
-       esac
-       case "$CMD" in
-       --enable|-e)
-               set_var "CONFIG_$ARG" "CONFIG_$ARG=y"
-               ;;
-
-       --disable|-d)
-               set_var "CONFIG_$ARG" "# CONFIG_$ARG is not set"
-               ;;
-
-       --module|-m)
-               set_var "CONFIG_$ARG" "CONFIG_$ARG=m"
-               ;;
-
-       --set-str)
-               set_var "CONFIG_$ARG" "CONFIG_$ARG=\"$1\""
-               shift
-               ;;
-
-       --set-val)
-               set_var "CONFIG_$ARG" "CONFIG_$ARG=$1"
-               shift
-               ;;
-
-       --state|-s)
-               if grep -q "# CONFIG_$ARG is not set" $FN ; then
-                       echo n
-               else
-                       V="$(grep "^CONFIG_$ARG=" $FN)"
-                       if [ $? != 0 ] ; then
-                               echo undef
-                       else
-                               V="${V/CONFIG_$ARG=/}"
-                               V="${V/\"/}"
-                               echo "$V"
-                       fi
-               fi
-               ;;
-
-       --enable-after|-E)
-               set_var "CONFIG_$B" "CONFIG_$B=y" "CONFIG_$A"
-               ;;
-
-       --disable-after|-D)
-               set_var "CONFIG_$B" "# CONFIG_$B is not set" "CONFIG_$A"
-               ;;
-
-       --module-after|-M)
-               set_var "CONFIG_$B" "CONFIG_$B=m" "CONFIG_$A"
-               ;;
-
-       # undocumented because it ignores --file (fixme)
-       --refresh)
-               yes "" | make oldconfig
-               ;;
-
-       *)
-               usage
-               ;;
-       esac
-done
-
diff --git a/utils/merge b/utils/merge
new file mode 100755 (executable)
index 0000000..974d5cb
--- /dev/null
@@ -0,0 +1,130 @@
+#!/bin/sh
+#  merge_config.sh - Takes a list of config fragment values, and merges
+#  them one by one. Provides warnings on overridden values, and specified
+#  values that did not make it to the resulting .config file (due to missed
+#  dependencies or config symbol removal).
+#
+#  Portions reused from kconf_check and generate_cfg:
+#  http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/kconf_check
+#  http://git.yoctoproject.org/cgit/cgit.cgi/yocto-kernel-tools/tree/tools/generate_cfg
+#
+#  Copyright (c) 2009-2010 Wind River Systems, Inc.
+#  Copyright 2011 Linaro
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License version 2 as
+#  published by the Free Software Foundation.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#  See the GNU General Public License for more details.
+
+clean_up() {
+       rm -f $TMP_FILE
+       exit
+}
+trap clean_up HUP INT TERM
+
+usage() {
+       echo "Usage: $0 [OPTIONS] [CONFIG [...]]"
+       echo "  -h    display this help text"
+       echo "  -m    only merge the fragments, do not execute the make command"
+       echo "  -n    use allnoconfig instead of alldefconfig"
+       echo "  -r    list redundant entries when merging fragments"
+}
+
+MAKE=true
+ALLTARGET=alldefconfig
+WARNREDUN=false
+
+while true; do
+       case $1 in
+       "-n")
+               ALLTARGET=allnoconfig
+               shift
+               continue
+               ;;
+       "-m")
+               MAKE=false
+               shift
+               continue
+               ;;
+       "-h")
+               usage
+               exit
+               ;;
+       "-r")
+               WARNREDUN=true
+               shift
+               continue
+               ;;
+       *)
+               break
+               ;;
+       esac
+done
+
+INITFILE=$1
+shift;
+
+MERGE_LIST=$*
+SED_CONFIG_EXP="s/^\(# \)\{0,1\}\(CONFIG_[a-zA-Z0-9_]*\)[= ].*/\2/p"
+TMP_FILE=$(mktemp ./.tmp.config.XXXXXXXXXX)
+
+echo "Using $INITFILE as base"
+cat $INITFILE > $TMP_FILE
+
+# Merge files, printing warnings on overrided values
+for MERGE_FILE in $MERGE_LIST ; do
+       echo "Merging $MERGE_FILE"
+       CFG_LIST=$(sed -n "$SED_CONFIG_EXP" $MERGE_FILE)
+
+       for CFG in $CFG_LIST ; do
+               grep -q -w $CFG $TMP_FILE
+               if [ $? -eq 0 ] ; then
+                       PREV_VAL=$(grep -w $CFG $TMP_FILE)
+                       NEW_VAL=$(grep -w $CFG $MERGE_FILE)
+                       if [ "x$PREV_VAL" != "x$NEW_VAL" ] ; then
+                       echo Value of $CFG is redefined by fragment $MERGE_FILE:
+                       echo Previous  value: $PREV_VAL
+                       echo New value:       $NEW_VAL
+                       echo
+                       elif [ "$WARNREDUN" = "true" ]; then
+                       echo Value of $CFG is redundant by fragment $MERGE_FILE:
+                       fi
+                       sed -i "/$CFG[ =]/d" $TMP_FILE
+               fi
+       done
+       cat $MERGE_FILE >> $TMP_FILE
+done
+
+if [ "$MAKE" = "false" ]; then
+       cp $TMP_FILE .config
+       echo "#"
+       echo "# merged configuration written to .config (needs make)"
+       echo "#"
+       clean_up
+       exit
+fi
+
+# Use the merged file as the starting point for:
+# alldefconfig: Fills in any missing symbols with Kconfig default
+# allnoconfig: Fills in any missing symbols with # CONFIG_* is not set
+make KCONFIG_ALLCONFIG=$TMP_FILE $ALLTARGET
+
+
+# Check all specified config values took (might have missed-dependency issues)
+for CFG in $(sed -n "$SED_CONFIG_EXP" $TMP_FILE); do
+
+       REQUESTED_VAL=$(grep -w -e "$CFG" $TMP_FILE)
+       ACTUAL_VAL=$(grep -w -e "$CFG" .config)
+       if [ "x$REQUESTED_VAL" != "x$ACTUAL_VAL" ] ; then
+               echo "Value requested for $CFG not in final .config"
+               echo "Requested value:  $REQUESTED_VAL"
+               echo "Actual value:     $ACTUAL_VAL"
+               echo ""
+       fi
+done
+
+clean_up
diff --git a/utils/streamline b/utils/streamline
new file mode 100755 (executable)
index 0000000..bccf07d
--- /dev/null
@@ -0,0 +1,495 @@
+#!/usr/bin/perl -w
+#
+# Copyright 2005-2009 - Steven Rostedt
+# Licensed under the terms of the GNU GPL License version 2
+#
+#  It's simple enough to figure out how this works.
+#  If not, then you can ask me at stripconfig@goodmis.org
+#
+# What it does?
+#
+#   If you have installed a Linux kernel from a distribution
+#   that turns on way too many modules than you need, and
+#   you only want the modules you use, then this program
+#   is perfect for you.
+#
+#   It gives you the ability to turn off all the modules that are
+#   not loaded on your system.
+#
+# Howto:
+#
+#  1. Boot up the kernel that you want to stream line the config on.
+#  2. Change directory to the directory holding the source of the
+#       kernel that you just booted.
+#  3. Copy the configuraton file to this directory as .config
+#  4. Have all your devices that you need modules for connected and
+#      operational (make sure that their corresponding modules are loaded)
+#  5. Run this script redirecting the output to some other file
+#       like config_strip.
+#  6. Back up your old config (if you want too).
+#  7. copy the config_strip file to .config
+#  8. Run "make oldconfig"
+#
+#  Now your kernel is ready to be built with only the modules that
+#  are loaded.
+#
+# Here's what I did with my Debian distribution.
+#
+#    cd /usr/src/linux-2.6.10
+#    cp /boot/config-2.6.10-1-686-smp .config
+#    ~/bin/streamline_config > config_strip
+#    mv .config config_sav
+#    mv config_strip .config
+#    make oldconfig
+#
+use strict;
+use Getopt::Long;
+
+my $config = ".config";
+
+my $uname = `uname -r`;
+chomp $uname;
+
+my @searchconfigs = (
+       {
+           "file" => ".config",
+           "exec" => "cat",
+       },
+       {
+           "file" => "/proc/config.gz",
+           "exec" => "zcat",
+       },
+       {
+           "file" => "/boot/config-$uname",
+           "exec" => "cat",
+       },
+       {
+           "file" => "/boot/vmlinuz-$uname",
+           "exec" => "scripts/extract-ikconfig",
+           "test" => "scripts/extract-ikconfig",
+       },
+       {
+           "file" => "vmlinux",
+           "exec" => "scripts/extract-ikconfig",
+           "test" => "scripts/extract-ikconfig",
+       },
+       {
+           "file" => "/lib/modules/$uname/kernel/kernel/configs.ko",
+           "exec" => "scripts/extract-ikconfig",
+           "test" => "scripts/extract-ikconfig",
+       },
+       {
+           "file" => "kernel/configs.ko",
+           "exec" => "scripts/extract-ikconfig",
+           "test" => "scripts/extract-ikconfig",
+       },
+       {
+           "file" => "kernel/configs.o",
+           "exec" => "scripts/extract-ikconfig",
+           "test" => "scripts/extract-ikconfig",
+       },
+);
+
+sub find_config {
+    foreach my $conf (@searchconfigs) {
+       my $file = $conf->{"file"};
+
+       next if ( ! -f "$file");
+
+       if (defined($conf->{"test"})) {
+           `$conf->{"test"} $conf->{"file"} 2>/dev/null`;
+           next if ($?);
+       }
+
+       my $exec = $conf->{"exec"};
+
+       print STDERR "using config: '$file'\n";
+
+       open(CIN, "$exec $file |") || die "Failed to run $exec $file";
+       return;
+    }
+    die "No config file found";
+}
+
+find_config;
+
+# Parse options
+my $localmodconfig = 0;
+my $localyesconfig = 0;
+
+GetOptions("localmodconfig" => \$localmodconfig,
+          "localyesconfig" => \$localyesconfig);
+
+# Get the build source and top level Kconfig file (passed in)
+my $ksource = $ARGV[0];
+my $kconfig = $ARGV[1];
+my $lsmod_file = $ENV{'LSMOD'};
+
+my @makefiles = `find $ksource -name Makefile 2>/dev/null`;
+chomp @makefiles;
+
+my %depends;
+my %selects;
+my %prompts;
+my %objects;
+my $var;
+my $iflevel = 0;
+my @ifdeps;
+
+# prevent recursion
+my %read_kconfigs;
+
+sub read_kconfig {
+    my ($kconfig) = @_;
+
+    my $state = "NONE";
+    my $config;
+    my @kconfigs;
+
+    my $cont = 0;
+    my $line;
+
+    my $source = "$ksource/$kconfig";
+    my $last_source = "";
+
+    # Check for any environment variables used
+    while ($source =~ /\$(\w+)/ && $last_source ne $source) {
+       my $env = $1;
+       $last_source = $source;
+       $source =~ s/\$$env/$ENV{$env}/;
+    }
+
+    open(KIN, "$source") || die "Can't open $kconfig";
+    while (<KIN>) {
+       chomp;
+
+       # Make sure that lines ending with \ continue
+       if ($cont) {
+           $_ = $line . " " . $_;
+       }
+
+       if (s/\\$//) {
+           $cont = 1;
+           $line = $_;
+           next;
+       }
+
+       $cont = 0;
+
+       # collect any Kconfig sources
+       if (/^source\s*"(.*)"/) {
+           $kconfigs[$#kconfigs+1] = $1;
+       }
+
+       # configs found
+       if (/^\s*(menu)?config\s+(\S+)\s*$/) {
+           $state = "NEW";
+           $config = $2;
+
+           for (my $i = 0; $i < $iflevel; $i++) {
+               if ($i) {
+                   $depends{$config} .= " " . $ifdeps[$i];
+               } else {
+                   $depends{$config} = $ifdeps[$i];
+               }
+               $state = "DEP";
+           }
+
+       # collect the depends for the config
+       } elsif ($state eq "NEW" && /^\s*depends\s+on\s+(.*)$/) {
+           $state = "DEP";
+           $depends{$config} = $1;
+       } elsif ($state eq "DEP" && /^\s*depends\s+on\s+(.*)$/) {
+           $depends{$config} .= " " . $1;
+
+       # Get the configs that select this config
+       } elsif ($state ne "NONE" && /^\s*select\s+(\S+)/) {
+           if (defined($selects{$1})) {
+               $selects{$1} .= " " . $config;
+           } else {
+               $selects{$1} = $config;
+           }
+
+       # configs without prompts must be selected
+       } elsif ($state ne "NONE" && /^\s*tristate\s\S/) {
+           # note if the config has a prompt
+           $prompts{$config} = 1;
+
+       # Check for if statements
+       } elsif (/^if\s+(.*\S)\s*$/) {
+           my $deps = $1;
+           # remove beginning and ending non text
+           $deps =~ s/^[^a-zA-Z0-9_]*//;
+           $deps =~ s/[^a-zA-Z0-9_]*$//;
+
+           my @deps = split /[^a-zA-Z0-9_]+/, $deps;
+
+           $ifdeps[$iflevel++] = join ':', @deps;
+
+       } elsif (/^endif/) {
+
+           $iflevel-- if ($iflevel);
+
+       # stop on "help"
+       } elsif (/^\s*help\s*$/) {
+           $state = "NONE";
+       }
+    }
+    close(KIN);
+
+    # read in any configs that were found.
+    foreach $kconfig (@kconfigs) {
+       if (!defined($read_kconfigs{$kconfig})) {
+           $read_kconfigs{$kconfig} = 1;
+           read_kconfig($kconfig);
+       }
+    }
+}
+
+if ($kconfig) {
+    read_kconfig($kconfig);
+}
+
+sub convert_vars {
+    my ($line, %vars) = @_;
+
+    my $process = "";
+
+    while ($line =~ s/^(.*?)(\$\((.*?)\))//) {
+       my $start = $1;
+       my $variable = $2;
+       my $var = $3;
+
+       if (defined($vars{$var})) {
+           $process .= $start . $vars{$var};
+       } else {
+           $process .= $start . $variable;
+       }
+    }
+
+    $process .= $line;
+
+    return $process;
+}
+
+# Read all Makefiles to map the configs to the objects
+foreach my $makefile (@makefiles) {
+
+    my $line = "";
+    my %make_vars;
+
+    open(MIN,$makefile) || die "Can't open $makefile";
+    while (<MIN>) {
+       # if this line ends with a backslash, continue
+       chomp;
+       if (/^(.*)\\$/) {
+           $line .= $1;
+           next;
+       }
+
+       $line .= $_;
+       $_ = $line;
+       $line = "";
+
+       my $objs;
+
+       $_ = convert_vars($_, %make_vars);
+
+       # collect objects after obj-$(CONFIG_FOO_BAR)
+       if (/obj-\$\((CONFIG_[^\)]*)\)\s*[+:]?=\s*(.*)/) {
+           $var = $1;
+           $objs = $2;
+
+       # check if variables are set
+       } elsif (/^\s*(\S+)\s*[:]?=\s*(.*\S)/) {
+           $make_vars{$1} = $2;
+       }
+       if (defined($objs)) {
+           foreach my $obj (split /\s+/,$objs) {
+               $obj =~ s/-/_/g;
+               if ($obj =~ /(.*)\.o$/) {
+                   # Objects may be enabled by more than one config.
+                   # Store configs in an array.
+                   my @arr;
+
+                   if (defined($objects{$1})) {
+                       @arr = @{$objects{$1}};
+                   }
+
+                   $arr[$#arr+1] = $var;
+
+                   # The objects have a hash mapping to a reference
+                   # of an array of configs.
+                   $objects{$1} = \@arr;
+               }
+           }
+       }
+    }
+    close(MIN);
+}
+
+my %modules;
+
+if (defined($lsmod_file)) {
+    if ( ! -f $lsmod_file) {
+       if ( -f $ENV{'objtree'}."/".$lsmod_file) {
+           $lsmod_file = $ENV{'objtree'}."/".$lsmod_file;
+       } else {
+               die "$lsmod_file not found";
+       }
+    }
+    if ( -x $lsmod_file) {
+       # the file is executable, run it
+       open(LIN, "$lsmod_file|");
+    } else {
+       # Just read the contents
+       open(LIN, "$lsmod_file");
+    }
+} else {
+
+    # see what modules are loaded on this system
+    my $lsmod;
+
+    foreach my $dir ( ("/sbin", "/bin", "/usr/sbin", "/usr/bin") ) {
+       if ( -x "$dir/lsmod" ) {
+           $lsmod = "$dir/lsmod";
+           last;
+       }
+}
+    if (!defined($lsmod)) {
+       # try just the path
+       $lsmod = "lsmod";
+    }
+
+    open(LIN,"$lsmod|") || die "Can not call lsmod with $lsmod";
+}
+
+while (<LIN>) {
+       next if (/^Module/);  # Skip the first line.
+       if (/^(\S+)/) {
+               $modules{$1} = 1;
+       }
+}
+close (LIN);
+
+# add to the configs hash all configs that are needed to enable
+# a loaded module.
+my %configs;
+foreach my $module (keys(%modules)) {
+    if (defined($objects{$module})) {
+       my @arr = @{$objects{$module}};
+       foreach my $conf (@arr) {
+           $configs{$conf} = $module;
+       }
+    } else {
+       # Most likely, someone has a custom (binary?) module loaded.
+       print STDERR "$module config not found!!\n";
+    }
+}
+
+my $valid = "A-Za-z_0-9";
+my $repeat = 1;
+
+#
+# Note, we do not care about operands (like: &&, ||, !) we want to add any
+# config that is in the depend list of another config. This script does
+# not enable configs that are not already enabled. If we come across a
+# config A that depends on !B, we can still add B to the list of depends
+# to keep on. If A was on in the original config, B would not have been
+# and B would not be turned on by this script.
+#
+sub parse_config_dep_select
+{
+    my ($p) = @_;
+
+    while ($p =~ /[$valid]/) {
+
+       if ($p =~ /^[^$valid]*([$valid]+)/) {
+           my $conf = "CONFIG_" . $1;
+
+           $p =~ s/^[^$valid]*[$valid]+//;
+
+           if (!defined($configs{$conf})) {
+               # We must make sure that this config has its
+               # dependencies met.
+               $repeat = 1; # do again
+               $configs{$conf} = 1;
+           }
+       } else {
+           die "this should never happen";
+       }
+    }
+}
+
+while ($repeat) {
+    $repeat = 0;
+
+    foreach my $config (keys %configs) {
+       $config =~ s/^CONFIG_//;
+
+       if (defined($depends{$config})) {
+           # This config has dependencies. Make sure they are also included
+           parse_config_dep_select $depends{$config};
+       }
+
+       if (defined($prompts{$config}) || !defined($selects{$config})) {
+           next;
+       }
+
+       # config has no prompt and must be selected.
+       parse_config_dep_select $selects{$config};
+    }
+}
+
+my %setconfigs;
+
+# Finally, read the .config file and turn off any module enabled that
+# we could not find a reason to keep enabled.
+while(<CIN>) {
+
+    if (/CONFIG_IKCONFIG/) {
+       if (/# CONFIG_IKCONFIG is not set/) {
+           # enable IKCONFIG at least as a module
+           print "CONFIG_IKCONFIG=m\n";
+           # don't ask about PROC
+           print "# CONFIG_IKCONFIG_PROC is not set\n";
+       } else {
+           print;
+       }
+       next;
+    }
+
+    if (/^(CONFIG.*)=(m|y)/) {
+       if (defined($configs{$1})) {
+           if ($localyesconfig) {
+               $setconfigs{$1} = 'y';
+           } else {
+               $setconfigs{$1} = $2;
+           }
+       } elsif ($2 eq "m") {
+           print "# $1 is not set\n";
+           next;
+       }
+    }
+    print;
+}
+close(CIN);
+
+# Integrity check, make sure all modules that we want enabled do
+# indeed have their configs set.
+loop:
+foreach my $module (keys(%modules)) {
+    if (defined($objects{$module})) {
+       my @arr = @{$objects{$module}};
+       foreach my $conf (@arr) {
+           if (defined($setconfigs{$conf})) {
+               next loop;
+           }
+       }
+       print STDERR "module $module did not have configs";
+       foreach my $conf (@arr) {
+           print STDERR " " , $conf;
+       }
+       print STDERR "\n";
+    }
+}
diff --git a/utils/tweak b/utils/tweak
new file mode 100755 (executable)
index 0000000..a7c7c4b
--- /dev/null
@@ -0,0 +1,156 @@
+#!/bin/bash
+# Manipulate options in a .config file from the command line
+
+usage() {
+       cat >&2 <<EOL
+Manipulate options in a .config file from the command line.
+Usage:
+config options command ...
+commands:
+       --enable|-e option   Enable option
+       --disable|-d option  Disable option
+       --module|-m option   Turn option into a module
+       --set-str option string
+                            Set option to "string"
+       --set-val option value
+                            Set option to value
+       --state|-s option    Print state of option (n,y,m,undef)
+
+       --enable-after|-E beforeopt option
+                             Enable option directly after other option
+       --disable-after|-D beforeopt option
+                             Disable option directly after other option
+       --module-after|-M beforeopt option
+                             Turn option into module directly after other option
+
+       commands can be repeated multiple times
+
+options:
+       --file .config file to change (default .config)
+
+config doesn't check the validity of the .config file. This is done at next
+ make time.
+EOL
+       exit 1
+}
+
+checkarg() {
+       ARG="$1"
+       if [ "$ARG" = "" ] ; then
+               usage
+       fi
+       case "$ARG" in
+       CONFIG_*)
+               ARG="${ARG/CONFIG_/}"
+               ;;
+       esac
+       ARG="`echo $ARG | tr a-z A-Z`"
+}
+
+set_var() {
+       local name=$1 new=$2 before=$3
+
+       name_re="^($name=|# $name is not set)"
+       before_re="^($before=|# $before is not set)"
+       if test -n "$before" && grep -Eq "$before_re" "$FN"; then
+               sed -ri "/$before_re/a $new" "$FN"
+       elif grep -Eq "$name_re" "$FN"; then
+               sed -ri "s:$name_re.*:$new:" "$FN"
+       else
+               echo "$new" >>"$FN"
+       fi
+}
+
+if [ "$1" = "--file" ]; then
+       FN="$2"
+       if [ "$FN" = "" ] ; then
+               usage
+       fi
+       shift 2
+else
+       FN=.config
+fi
+
+if [ "$1" = "" ] ; then
+       usage
+fi
+
+while [ "$1" != "" ] ; do
+       CMD="$1"
+       shift
+       case "$CMD" in
+       --refresh)
+               ;;
+       --*-after)
+               checkarg "$1"
+               A=$ARG
+               checkarg "$2"
+               B=$ARG
+               shift 2
+               ;;
+       -*)
+               checkarg "$1"
+               shift
+               ;;
+       esac
+       case "$CMD" in
+       --enable|-e)
+               set_var "CONFIG_$ARG" "CONFIG_$ARG=y"
+               ;;
+
+       --disable|-d)
+               set_var "CONFIG_$ARG" "# CONFIG_$ARG is not set"
+               ;;
+
+       --module|-m)
+               set_var "CONFIG_$ARG" "CONFIG_$ARG=m"
+               ;;
+
+       --set-str)
+               set_var "CONFIG_$ARG" "CONFIG_$ARG=\"$1\""
+               shift
+               ;;
+
+       --set-val)
+               set_var "CONFIG_$ARG" "CONFIG_$ARG=$1"
+               shift
+               ;;
+
+       --state|-s)
+               if grep -q "# CONFIG_$ARG is not set" $FN ; then
+                       echo n
+               else
+                       V="$(grep "^CONFIG_$ARG=" $FN)"
+                       if [ $? != 0 ] ; then
+                               echo undef
+                       else
+                               V="${V/CONFIG_$ARG=/}"
+                               V="${V/\"/}"
+                               echo "$V"
+                       fi
+               fi
+               ;;
+
+       --enable-after|-E)
+               set_var "CONFIG_$B" "CONFIG_$B=y" "CONFIG_$A"
+               ;;
+
+       --disable-after|-D)
+               set_var "CONFIG_$B" "# CONFIG_$B is not set" "CONFIG_$A"
+               ;;
+
+       --module-after|-M)
+               set_var "CONFIG_$B" "CONFIG_$B=m" "CONFIG_$A"
+               ;;
+
+       # undocumented because it ignores --file (fixme)
+       --refresh)
+               yes "" | make oldconfig
+               ;;
+
+       *)
+               usage
+               ;;
+       esac
+done
+