3 # kconfig2wiki - Kconfig to MediaWiki converter for
4 # https://www.coreboot.org/coreboot_Options
5 # based on http://landley.net/kdocs/make/menuconfig2html.py
7 # SPDX-License-Identifier: GPL-2.0-only
15 ## Remove quotes from Kconfig string options
18 if str[0]=='"': str = str[1:str.rfind('"')]
22 ## Escape HTML special characters
25 return str.strip().replace("&","&").replace("<","<").replace(">",">")
28 ## Process Kconfig file
30 def readfile(filename):
34 source=filename.replace("src/","").replace("/Kconfig","").replace("Kconfig","toplevel")
37 lines = open(filename).read().split("\n")
39 sys.stderr.write("File %s missing\n" % filename)
47 if not len(i) or i[:helplen].isspace():
48 sys.stdout.write("%s<br />\n" % htmlescape(i))
52 sys.stdout.write("</td></tr>\n")
54 words = i.strip().split(None,1)
55 if not len(words): continue
57 if words[0] in ("config", "menuconfig"):
60 elif words[0] in ("bool", "boolean", "tristate", "string", "hex", "int"):
61 configtype = htmlescape(zapquotes(words[0]))
62 if len(words)>1: description = htmlescape(zapquotes(words[1]))
63 elif words[0]=="prompt":
64 description = htmlescape(zapquotes(words[1]))
65 elif words[0] in ("help", "---help---"):
66 sys.stdout.write("<tr bgcolor=\"#eeeeee\">\n")
67 sys.stdout.write("<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>\n" % (config,source,configtype,description) )
68 helplen = len(i[:i.find(words[0])].expandtabs())
69 elif words[0] == "comment":
70 sys.stdout.write("<tr bgcolor=\"#eeeeee\">\n")
71 sys.stdout.write("<td></td><td>%s</td><td>(comment)</td><td></td><td>%s</td></tr>\n" % (source, htmlescape(zapquotes(words[1]))))
72 elif words[0]=="menu":
74 temp = htmlescape(zapquotes(words[1]))
75 sys.stdout.write("<tr bgcolor=\"#6699dd\">\n")
76 sys.stdout.write("<td colspan=5>Menu: %s</td></tr>\n" % temp)
77 elif words[0] == "endmenu":
78 sys.stdout.write("\n")
79 elif words[0] == "source":
80 fn=zapquotes(words[1])
81 for name in glob.glob(fn):
83 elif words[0] in ("default","depends", "select", "if", "endif", "#"): pass
84 #else: sys.stderr.write("unknown: %s\n" % i)
85 if helplen: sys.stdout.write("</td></tr>\n")
91 sys.stderr.write("Usage: kconfig2wiki kconfigfile version\n")
94 sys.stdout.write("This is an automatically generated list of '''coreboot compile-time options'''.\n")
95 sys.stdout.write("\nLast update: %s\n" % sys.argv[2])
96 sys.stdout.write("<table border=\"0\" style=\"font-size: smaller\">\n");
97 sys.stdout.write("<tr bgcolor=\"#6699dd\">\n")
98 sys.stdout.write("<td align=\"left\">Option</td>\n")
99 sys.stdout.write("<td align=\"left\">Source</td>\n")
100 sys.stdout.write("<td align=\"left\">Format</td>\n")
101 sys.stdout.write("<td align=\"left\">Short Description</td>\n")
102 sys.stdout.write("<td align=\"left\">Description</td></tr>\n")
103 readfile(sys.argv[1])
104 sys.stdout.write("</table>\n")
106 if __name__ == "__main__":