xref: /optee_os/scripts/kconfig/kconfiglib/allnoconfig.py (revision c689edbb2550c76ae81dcecab717d82a564b2d7b)
1#!/usr/bin/env python3
2
3# Copyright (c) 2018-2019, Ulf Magnusson
4# SPDX-License-Identifier: ISC
5
6"""
7Writes a configuration file where as many symbols as possible are set to 'n'.
8
9The default output filename is '.config'. A different filename can be passed
10in the KCONFIG_CONFIG environment variable.
11
12Usage for the Linux kernel:
13
14  $ make [ARCH=<arch>] scriptconfig SCRIPT=Kconfiglib/allnoconfig.py
15"""
16
17# See examples/allnoconfig_walk.py for another way to implement this script
18
19import kconfiglib
20
21
22def main():
23    kconf = kconfiglib.standard_kconfig(__doc__)
24
25    # Avoid warnings that would otherwise get printed by Kconfiglib for the
26    # following:
27    #
28    # 1. Assigning a value to a symbol without a prompt, which never has any
29    #    effect
30    #
31    # 2. Assigning values invalid for the type (only bool/tristate symbols
32    #    accept 0/1/2, for n/m/y). The assignments will be ignored for other
33    #    symbol types, which is what we want.
34    kconf.warn = False
35    for sym in kconf.unique_defined_syms:
36        sym.set_value(2 if sym.is_allnoconfig_y else 0)
37    kconf.warn = True
38
39    kconf.load_allconfig("allno.config")
40
41    print(kconf.write_config())
42
43
44if __name__ == "__main__":
45    main()
46