From 4f1674fc32224003931af4a74aa18168786ec9a2 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 27 Apr 2019 14:16:10 +0200 Subject: defconfig: Add script Simple script for initializing the configuration from an existing configuration file (usually a minimal configuration). Just copying the minimal configuration to .config would usually work, due to Kconfig semantics, but having it be a full configuration file from the start might be handier and less confusing. --- README.rst | 7 +++++++ defconfig.py | 43 +++++++++++++++++++++++++++++++++++++++++++ setup.py | 2 ++ 3 files changed, 52 insertions(+) create mode 100755 defconfig.py diff --git a/README.rst b/README.rst index 638de30..46b236e 100644 --- a/README.rst +++ b/README.rst @@ -65,6 +65,8 @@ available in the C tools. - `savedefconfig `_ +- `defconfig `_ + - `alldefconfig `_ - `allnoconfig `_ @@ -133,6 +135,11 @@ Getting started 3. Generate an initial configuration with e.g. ``menuconfig`` or ``alldefconfig``. The configuration is saved as ``.config`` by default. + For more advanced projects, the ``defconfig`` utility can be used to + generate the initial configuration from an existing configuration file. + Usually, this existing configuration file would be a minimal configuration + file, as generated by e.g. ``savedefconfig``. + 4. Run ``genconfig`` to generate a header file. By default, it is saved as ``config.h``. diff --git a/defconfig.py b/defconfig.py new file mode 100755 index 0000000..7b02833 --- /dev/null +++ b/defconfig.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +# Copyright (c) 2019, Ulf Magnusson +# SPDX-License-Identifier: ISC + +""" +Reads a specified configuration file, then writes a new configuration file. +This can be used to initialize the configuration from e.g. an arch-specific +configuration file. This input configuration file would usually be a minimal +configuration file, as generated by e.g. savedefconfig. + +The default output filename is '.config'. A different filename can be passed in +the KCONFIG_CONFIG environment variable. +""" +import argparse + +import kconfiglib + + +def main(): + parser = argparse.ArgumentParser( + formatter_class=argparse.RawDescriptionHelpFormatter, + description=__doc__) + + parser.add_argument( + "--kconfig", + default="Kconfig", + help="Base Kconfig file (default: Kconfig)") + + parser.add_argument( + "config", + metavar="CONFIGURATION", + help="Input configuration file") + + args = parser.parse_args() + + kconf = kconfiglib.Kconfig(args.kconfig) + kconf.load_config(args.config) + kconf.write_config() + + +if __name__ == "__main__": + main() diff --git a/setup.py b/setup.py index b9e5e88..1660ccc 100644 --- a/setup.py +++ b/setup.py @@ -33,6 +33,7 @@ setuptools.setup( "oldconfig", "olddefconfig", "savedefconfig", + "defconfig", "alldefconfig", "allnoconfig", "allmodconfig", @@ -50,6 +51,7 @@ setuptools.setup( "oldconfig = oldconfig:_main", "olddefconfig = olddefconfig:main", "savedefconfig = savedefconfig:main", + "defconfig = defconfig:main", "alldefconfig = alldefconfig:main", "allnoconfig = allnoconfig:main", "allmodconfig = allmodconfig:main", -- cgit v1.2.3