Linux – Safely changing Linux kernel config programmatically

configurationkernellinux-kernel

I'm writing a script that has to automatically change a number of Linux kernel configuration options based on an input file.
The easiest way to do this would of course be to edit the .config file directly, but this is discouraged and may cause issues.
I can't seem to find a way to do this "the right way" though.

"make help" doesn't show a way to change single options, nor does ./scripts/kconfig/conf –help. This file on kernel.org doesn't seem to have a way either.
Even Gentoo's Genkernel manually changes the .config file.

So, basically:
Is there a safe way to change kernel configuration options programmatically, complete with dependency tracking, etc.?
Can Kconfig be run manually to achieve this?

Best Answer

What I do is first:

make defconfig

Then append settings changes to .config followed by:

make olddefconfig

This should "fix up" any inconsistencies introduced in the configuration. YMMV since it may not fix them in the way you expect.

Related Question