outf.close()
os.chmod(f, int(m, 8))
+def automatic_backport_mangle_c_file(name):
+ return name.replace('/', '-')
+
def add_automatic_backports(args):
export = re.compile(r'^EXPORT_SYMBOL(_GPL)?\((?P<sym>[^\)]*)\)')
bpi = kconfig.get_backport_info(os.path.join(args.outdir, 'compat', 'Kconfig'))
for sym, vals in bpi.iteritems():
- symtype, c_files, h_files = vals
+ symtype, module_name, c_files, h_files = vals
# first copy files
files = []
for f in c_files:
- files.append((f, os.path.join('compat', os.path.basename(f))))
+ files.append((f, os.path.join('compat', automatic_backport_mangle_c_file(f))))
for f in h_files:
files.append((os.path.join('include', f),
os.path.join('include', os.path.dirname(f), 'backport-' + os.path.basename(f))))
# now add the Makefile line
mf = open(os.path.join(args.outdir, 'compat', 'Makefile'), 'a+')
- o_files = [os.path.basename(f)[:-1] + 'o' for f in c_files]
+ o_files = [automatic_backport_mangle_c_file(f)[:-1] + 'o' for f in c_files]
if symtype == 'tristate':
- mf.write('obj-$(CPTCFG_%s) += %s\n' % (sym, ' '.join(o_files)))
+ if not module_name:
+ raise Exception('backporting a module requires a #module-name')
+ for of in o_files:
+ mf.write('%s-objs += %s\n' % (module_name, of))
+ mf.write('obj-$(CPTCFG_%s) += %s.o\n' % (sym, module_name))
elif symtype == 'bool':
mf.write('compat-$(CPTCFG_%s) += %s\n' % (sym, ' '.join(o_files)))
# finally create the include file
syms = []
for f in c_files:
- for l in open(os.path.join(args.outdir, 'compat', os.path.basename(f)), 'r'):
+ for l in open(os.path.join(args.outdir, 'compat',
+ automatic_backport_mangle_c_file(f)), 'r'):
m = export.match(l)
if m:
syms.append(m.group('sym'))
bool_line = re.compile(r'^(?P<spc>\s+)bool')
cfg_line = re.compile(r'^(config|menuconfig)\s+(?P<sym>[^\s]*)')
sel_line = re.compile(r'^(?P<spc>\s+)select\s+(?P<sym>[^\s]*)\s*$')
-ch_line = re.compile(r'^\s+#(?P<ch>[ch])-file\s*(?P<file>.*)')
+backport_line = re.compile(r'^\s+#(?P<key>[ch]-file|module-name)\s*(?P<name>.*)')
class ConfigTree(object):
def __init__(self, rootfile):
f = open(filename, 'r')
result = {}
conf = None
+ module_name = None
# trick to always have an empty line last
def append_empty(f):
m = cfg_line.match(line)
if not line.strip() or m:
if conf and conf_type and (c_files or h_files):
- result[conf] = (conf_type, c_files, h_files)
+ result[conf] = (conf_type, module_name, c_files, h_files)
conf = None
conf_type = None
+ module_name = None
c_files = []
h_files = []
if m:
if m:
conf_type = 'bool'
continue
- m = ch_line.match(line)
+ m = backport_line.match(line)
if m:
- if m.group('ch') == 'c':
- c_files.append(m.group('file'))
- elif m.group('ch') == 'h':
- h_files.append(m.group('file'))
+ if m.group('key') == 'c-file':
+ c_files.append(m.group('name'))
+ elif m.group('key') == 'h-file':
+ h_files.append(m.group('name'))
+ elif m.group('key') == 'module-name':
+ module_name = m.group('name')
return result