2023-12-17 03:09:20 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
2023-12-17 22:08:18 +08:00
|
|
|
"""
|
|
|
|
|
@copyright (c) 2023, MR Development Team
|
|
|
|
|
|
|
|
|
|
@license SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
|
|
@date 2023-12-17 MacRsh First version
|
|
|
|
|
"""
|
|
|
|
|
|
2023-11-27 23:17:23 +08:00
|
|
|
import re
|
|
|
|
|
|
2023-12-20 02:46:59 +08:00
|
|
|
try:
|
|
|
|
|
from build import install_package
|
|
|
|
|
except ImportError:
|
|
|
|
|
exit(1)
|
2023-11-27 23:17:23 +08:00
|
|
|
|
2023-12-17 03:09:20 +08:00
|
|
|
try:
|
|
|
|
|
from kconfiglib import Kconfig
|
|
|
|
|
except ImportError:
|
|
|
|
|
install_package('kconfiglib')
|
2023-12-20 02:46:59 +08:00
|
|
|
from kconfiglib import Kconfig
|
2023-11-27 23:17:23 +08:00
|
|
|
|
2023-12-17 03:09:20 +08:00
|
|
|
try:
|
|
|
|
|
import curses
|
|
|
|
|
except ImportError:
|
|
|
|
|
install_package('windows-curses')
|
2023-12-20 02:46:59 +08:00
|
|
|
import curses
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
from build import log_print
|
|
|
|
|
except ImportError:
|
|
|
|
|
exit(1)
|
2023-12-17 03:09:20 +08:00
|
|
|
|
|
|
|
|
|
2023-12-31 16:44:49 +08:00
|
|
|
def generate_config_file(kconfig_file, config_in, config_out, header_out):
|
2023-12-20 02:46:59 +08:00
|
|
|
kconf = Kconfig(kconfig_file, warn=False, warn_to_stderr=False)
|
2023-11-27 23:17:23 +08:00
|
|
|
|
2023-12-17 22:08:18 +08:00
|
|
|
# Load config
|
|
|
|
|
kconf.load_config(config_in)
|
|
|
|
|
kconf.write_config(config_out)
|
|
|
|
|
kconf.write_autoconf(header_out)
|
2023-11-27 23:17:23 +08:00
|
|
|
|
|
|
|
|
with open(header_out, 'r+') as header_file:
|
|
|
|
|
content = header_file.read()
|
|
|
|
|
header_file.truncate(0)
|
|
|
|
|
header_file.seek(0)
|
2023-12-17 03:09:20 +08:00
|
|
|
|
2023-11-27 23:17:23 +08:00
|
|
|
# Remove CONFIG_ and MR_USING_XXX following number
|
|
|
|
|
content = content.replace("#define CONFIG_", "#define ")
|
|
|
|
|
content = re.sub(r'#define MR_USING_(\w+) (\d+)', r'#define MR_USING_\1', content)
|
|
|
|
|
|
|
|
|
|
# Add the micro
|
2023-12-17 03:09:20 +08:00
|
|
|
header_file.write("#ifndef _MR_CONFIG_H_\n")
|
2023-11-27 23:17:23 +08:00
|
|
|
header_file.write("#define _MR_CONFIG_H_\n\n")
|
2023-12-17 03:09:20 +08:00
|
|
|
|
2023-11-27 23:17:23 +08:00
|
|
|
header_file.write("#ifdef __cplusplus\n")
|
2023-12-17 03:09:20 +08:00
|
|
|
header_file.write("extern \"C\" {\n")
|
2023-11-27 23:17:23 +08:00
|
|
|
header_file.write("#endif /* __cplusplus */\n\n")
|
|
|
|
|
|
|
|
|
|
# Write back the original data
|
|
|
|
|
header_file.write(content)
|
|
|
|
|
|
|
|
|
|
# Add the micro
|
|
|
|
|
header_file.write("\n#ifdef __cplusplus\n")
|
|
|
|
|
header_file.write("}\n")
|
|
|
|
|
header_file.write("#endif /* __cplusplus */\n\n")
|
|
|
|
|
header_file.write("#endif /* _MR_CONFIG_H_ */\n")
|
|
|
|
|
|
2023-12-17 22:08:18 +08:00
|
|
|
header_file.close()
|
2023-12-31 16:44:49 +08:00
|
|
|
log_print('success', "config file make success")
|
2023-12-17 22:08:18 +08:00
|
|
|
|
2023-12-17 03:09:20 +08:00
|
|
|
|
2023-11-27 23:17:23 +08:00
|
|
|
def main():
|
2023-12-17 03:09:20 +08:00
|
|
|
kconfig_file = 'Kconfig'
|
2023-11-27 23:17:23 +08:00
|
|
|
config_in = '.config'
|
|
|
|
|
config_out = '.config'
|
|
|
|
|
header_out = 'include/mr_config.h'
|
2023-12-31 16:44:49 +08:00
|
|
|
generate_config_file(kconfig_file, config_in, config_out, header_out)
|
2023-11-27 23:17:23 +08:00
|
|
|
|
2023-12-17 03:09:20 +08:00
|
|
|
|
2023-11-27 23:17:23 +08:00
|
|
|
if __name__ == "__main__":
|
2023-12-17 03:09:20 +08:00
|
|
|
main()
|