def add_automatic_backports(args): disable_list = [] export = re.compile(r'^EXPORT_SYMBOL(_GPL)?\((?P<sym>[^\)]*)\)') bpi = kconfig.get_backport_info(os.path.join(args.bpid.target_dir, 'compat', 'Kconfig')) configtree = kconfig.ConfigTree(os.path.join(args.bpid.target_dir, 'Kconfig'), args.bpid) ignore=['Kconfig.kernel', 'Kconfig.versions'] configtree.verify_sources(ignore=ignore) git_debug_snapshot(args, "verify sources for automatic backports") all_selects = configtree.all_selects() for sym, vals in bpi.items(): if sym.startswith('BPAUTO_BUILD_'): if not sym[13:] in all_selects: disable_list.append(sym) continue symtype, module_name, c_files, h_files = vals # first copy files files = [] for f in c_files: 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)))) if args.git_revision: copy_git_files(args.kerneldir, files, args.git_revision, args.bpid.target_dir) else: copy_files(args.kerneldir, files, args.bpid.target_dir) # now add the Makefile line mf = open(os.path.join(args.bpid.target_dir, 'compat', 'Makefile'), 'a+') o_files = [automatic_backport_mangle_c_file(f)[:-1] + 'o' for f in c_files] if symtype == 'tristate': 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-$(%s%s) += %s.o\n' % (args.bpid.full_prefix, sym, module_name)) elif symtype == 'bool': mf.write('compat-$(%s%s) += %s\n' % (args.bpid.full_prefix, sym, ' '.join(o_files))) # finally create the include file syms = [] for f in c_files: for l in open(os.path.join(args.bpid.target_dir, 'compat', automatic_backport_mangle_c_file(f)), 'r'): m = export.match(l) if m: syms.append(m.group('sym')) for f in h_files: outf = open(os.path.join(args.bpid.target_dir, 'include', f), 'w') outf.write('/* Automatically created during backport process */\n') outf.write('#ifndef %s%s\n' % (args.bpid.full_prefix, sym)) outf.write('#include_next <%s>\n' % f) outf.write('#else\n'); for s in syms: outf.write('#undef %s\n' % s) outf.write('#define %s LINUX_BACKPORT(%s)\n' % (s, s)) outf.write('#include <%s>\n' % (os.path.dirname(f) + '/backport-' + os.path.basename(f), )) outf.write('#endif /* %s%s */\n' % (args.bpid.full_prefix, sym)) return disable_list