1 /***************************************************************************
3 * (C) 2002 Randy Dunlap <rddunlap@osdl.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 # Rules for scripts/mkconfigs.c input.config output.c
20 # to generate configs.c from linux/.config:
21 # - drop lines that begin with '#'
23 # - lines that use double-quotes must \\-escape-quote them
25 ################## skeleton configs.c file: ####################
27 #include <linux/init.h>
28 #include <linux/module.h>
30 static char *configs[] __initdata =
32 <insert lines selected lines of .config, quoted, with added '\n'>,
36 ################### end configs.c file ######################
38 * Changelog for ver. 0.2, 2002-02-15, rddunlap@osdl.org:
39 - strip leading "CONFIG_" from config option strings;
40 - use "static" and "__attribute__((unused))";
41 - don't use EXPORT_SYMBOL();
42 - separate each config line with \newline instead of space;
44 * Changelog for ver. 0.3, 2002-02-18, rddunlap@osdl.org:
45 - keep all "not set" comment lines from .config so that 'make *config'
46 will be happy, but don't keep other comments;
47 - keep leading "CONFIG_" on each line;
49 ****************************************************************/
57 #define LINE_SIZE 1000
59 int include_all_lines = 1; // whether to include "=n" lines in the output
61 void usage (const char *progname)
63 fprintf (stderr, "%s ver. %s\n", progname, VERSION);
64 fprintf (stderr, "usage: %s input.config.name path/configs.c\n",
69 void make_intro (FILE *sourcefile)
71 fprintf (sourcefile, "#include <linux/init.h>\n");
72 ///// fprintf (sourcefile, "#include <linux/module.h>\n");
73 fprintf (sourcefile, "\n");
74 ///// fprintf (sourcefile, "char *configs[] __initdata = {\n");
75 fprintf (sourcefile, "static char __attribute__ ((unused)) *configs[] __initdata = {\n");
76 fprintf (sourcefile, " \"CONFIG_BEGIN=n\\n\" ,\n");
79 void make_ending (FILE *sourcefile)
81 fprintf (sourcefile, " \"CONFIG_END=n\\n\"\n");
82 fprintf (sourcefile, "};\n");
83 ///// fprintf (sourcefile, "EXPORT_SYMBOL (configs);\n");
86 void make_lines (FILE *configfile, FILE *sourcefile)
88 char cfgline[LINE_SIZE];
91 while (fgets (cfgline, LINE_SIZE, configfile)) {
92 /* kill the trailing newline in cfgline */
93 cfgline[strlen (cfgline) - 1] = '\0';
95 /* don't keep #-only line or an empty/blank line */
96 if ((cfgline[0] == '#' && cfgline[1] == '\0') ||
100 if (!include_all_lines &&
101 cfgline[0] == '#') // strip out all comment lines
104 /* really only want to keep lines that begin with
105 * "CONFIG_" or "# CONFIG_" */
106 if (strncmp (cfgline, "CONFIG_", 7) &&
107 strncmp (cfgline, "# CONFIG_", 9))
111 * use strchr() to check for "-quote in cfgline;
112 * if not found, output the line, quoted;
113 * if found, output a char at a time, with \\-quote
114 * preceding double-quote chars
116 if (!strchr (cfgline, '"')) {
117 fprintf (sourcefile, " \"%s\\n\" ,\n", cfgline);
121 /* go to char-at-a-time mode for this config and
122 * precede any double-quote with a backslash */
123 fprintf (sourcefile, " \""); /* lead-in */
124 for (ch = cfgline; *ch; ch++) {
126 fputc ('\\', sourcefile);
127 fputc (*ch, sourcefile);
129 fprintf (sourcefile, "\\n\" ,\n");
133 void make_configs (FILE *configfile, FILE *sourcefile)
135 make_intro (sourcefile);
136 make_lines (configfile, sourcefile);
137 make_ending (sourcefile);
140 int main (int argc, char *argv[])
142 char *progname = argv[0];
143 char *configname, *sourcename;
144 FILE *configfile, *sourcefile;
149 configname = argv[1];
150 sourcename = argv[2];
152 configfile = fopen (configname, "r");
154 fprintf (stderr, "%s: cannot open '%s'\n",
155 progname, configname);
158 sourcefile = fopen (sourcename, "w");
160 fprintf (stderr, "%s: cannot open '%s'\n",
161 progname, sourcename);
165 make_configs (configfile, sourcefile);
167 if (fclose (sourcefile)) {
168 fprintf (stderr, "%s: error %d closing '%s'\n",
169 progname, errno, sourcename);
172 if (fclose (configfile)) {
173 fprintf (stderr, "%s: error %d closing '%s'\n",
174 progname, errno, configname);
181 /* end mkconfigs.c */