def main(): """The main entry point.""" parser = argparse.ArgumentParser( description='Produce headers of assembly constants.') parser.add_argument('--cc', metavar='CC', help='C compiler (including options) to use') parser.add_argument('--test', action='store_true', help='Generate test case instead of header') parser.add_argument('--python', action='store_true', help='Generate Python file instead of header') parser.add_argument('sym_file', help='.sym file to process') args = parser.parse_args() sym_data = [] with open(args.sym_file, 'r') as sym_file: started = False for line in sym_file: line = line.strip() if line == '': continue # Pass preprocessor directives through. if line.startswith('#'): sym_data.append(line) continue words = line.split(maxsplit=1) if not started: sym_data.append('START') started = True # Separator. if words[0] == '--': continue name = words[0] value = words[1] if len(words) > 1 else words[0] sym_data.append((name, value)) if not started: sym_data.append('START') if args.test: print(gen_test(sym_data)) elif args.python: consts = glibcextract.compute_c_consts(sym_data, args.cc) print('# GENERATED FILE\n' '\n' '# Constant definitions.\n' '# See gen-as-const.py for details.\n') print(''.join('%s = %s\n' % c for c in sorted(consts.items())), end='') else: consts = glibcextract.compute_c_consts(sym_data, args.cc) print(''.join('#define %s %s\n' % c for c in sorted(consts.items())), end='')
def linux_kernel_version(cc): """Return the (major, minor) version of the Linux kernel headers.""" sym_data = ['#include <linux/version.h>', 'START', ('LINUX_VERSION_CODE', 'LINUX_VERSION_CODE')] val = glibcextract.compute_c_consts(sym_data, cc)['LINUX_VERSION_CODE'] val = int(val) return ((val & 0xff0000) >> 16, (val & 0xff00) >> 8)