#!/usr/bin/env python3 # Generate C header file from .config # Usage: genconfig.py import sys import argparse parser = argparse.ArgumentParser(description="Generate C header file from KConfig") parser.add_argument("output", help="Output C file") args = parser.parse_args() values = {} def value_from_str(string): if string == 'y': return 1 if string == 'n': return 0 return string with open('.config', 'r') as f: lines = f.read().splitlines() for line in lines: if line.startswith('#') or len(line) == 0: continue vals = line.split('=') values[vals[0]] = value_from_str(vals[1]) with open(args.output, 'w') as f: f.write('/* This file is auto-generated by scripts/genconfig.py */\n') f.write('#ifndef GENCONFIG_CONFIG_H_\n') f.write('#define GENCONFIG_CONFIG_H_\n') for key, val in values.items(): f.write(f'#define {key} {val}\n') f.write('#endif\n')