]> git.pld-linux.org Git - packages/kernel.git/blame - kernel-config.py
- take from suse kernel-source-2.6.22.5-31.src.rpm -> patches.fixes.tar.bz2 -> patche...
[packages/kernel.git] / kernel-config.py
CommitLineData
744f880e
ER
1#!/usr/bin/python
2
3# Generate kernel .config file based on special kernel.conf rules file.
4# arekm@pld-linux.org
5
6import sys
7import re
8
9if len(sys.argv) != 5:
10 print "Usage: %s target_arch kernel.conf input-config output-config" % sys.argv[0]
11 sys.exit(1)
12
13arch = sys.argv[1]
14kernelconfig = sys.argv[2]
15inconfig = sys.argv[3]
16outconfig = sys.argv[4]
17
18from UserDict import UserDict
19
20# odict from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/107747
21class odict(UserDict):
22 def __init__(self, dict = None):
23 self._keys = []
24 UserDict.__init__(self, dict)
25
26 def __delitem__(self, key):
27 UserDict.__delitem__(self, key)
28 self._keys.remove(key)
29
30 def __setitem__(self, key, item):
31 UserDict.__setitem__(self, key, item)
32 if key not in self._keys: self._keys.append(key)
33
34 def clear(self):
35 UserDict.clear(self)
36 self._keys = []
37
38 def copy(self):
39 dict = UserDict.copy(self)
40 dict._keys = self._keys[:]
41 return dict
42
43 def items(self):
44 return zip(self._keys, self.values())
45
46 def keys(self):
47 return self._keys
48
49 def popitem(self):
50 try:
51 key = self._keys[-1]
52 except IndexError:
53 raise KeyError('dictionary is empty')
54
55 val = self[key]
56 del self[key]
57
58 return (key, val)
59
60 def setdefault(self, key, failobj = None):
61 UserDict.setdefault(self, key, failobj)
62 if key not in self._keys: self._keys.append(key)
63
64 def update(self, dict):
65 UserDict.update(self, dict)
66 for key in dict.keys():
67 if key not in self._keys: self._keys.append(key)
68
69 def values(self):
70 return map(self.get, self._keys)
71
72dict = odict()
73
74f = open(kernelconfig, 'r')
75for l in f:
76 if l[:6] == 'CONFIG_':
77 print "Omit CONFIG_ when specifing symbol name: %s" % l
78 continue
79 if re.match('^#', l) or re.match('^\s*$', l):
80 continue
81 if not re.match('^[0-9A-Z]+', l):
82 print "Unknown line: %s" % l
83 sys.exit(1)
84 c = l.strip().split()
85 symbol = c[0]
86 if dict.has_key(symbol):
87 print "Duplicate symbol %s!" % symbol
88 sys.exit(1)
89
90 par = False
91 for i in c[1:]:
92 par = True
93 i = i.split('=')
94 key = i[0]
95 if key != arch and key != "all":
96 continue
97 val = i[1]
98 dict[symbol] = val
99 if not par:
100 print "Unknown line: %s" % l
101 sys.exit(1)
102
103f.close()
104
105f = open(inconfig, 'r')
106cfg = f.read()
107f.close()
108
109cfg += '\n# PLD configs\n'
110for symbol in dict.items():
111 (key, val) = symbol
112
113 # strip contents
114 rp = re.compile("^CONFIG_%s=.*$" % key, re.MULTILINE)
115 cfg = rp.sub("", cfg)
116 rp = re.compile("^# CONFIG_%s is not set$" % key, re.MULTILINE)
117 cfg = rp.sub("", cfg)
118
119 if val == "y":
120 cfg += "CONFIG_%s=y\n" % key
121 elif val == "m":
122 cfg += "CONFIG_%s=m\n" % key
123 elif val == "n":
124 cfg += "# CONFIG_%s is not set\n" % key
125 elif re.compile('^[a-zA-Z0-9"\-]+$').match(val):
126 cfg += "CONFIG_%s=%s\n" % (key, val)
127 else:
128 print "Unknown value [%s] for key: %s" % (val, key)
129 sys.exit(1)
130
131f = open(outconfig, 'w')
132f.write(cfg)
133f.close()
This page took 0.047664 seconds and 4 git commands to generate.