4

This question already has an answer here:

Is there any method to configure linux kernel in such way (just an example):

make config CONFIG_OPTION=y && make config CONFIG_OPTION1=no CONFIG_OPTION3=64 CONFIG_OPTION4=/path/

and all the dependencies and alternatives of these configuration options will be set automatically in non-interactive mode.

marked as duplicate by drewbenn, Thomas, Tomasz, slm linux Jun 16 '18 at 22:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from stackoverflow.com Sep 1 '11 at 13:19

This question came from our site for professional and enthusiast programmers.

3

Option I:

The qconfig tool seems to serve the purpose, albeit depends on what interface you'd prefer. It takes an input file with the CONFIG_ directives that you'd want changed, and changes them. I didn't try it yet.

I didn't try it yet, but it doesn't look like it has an interface via command line arguments, along the lines of what you described.

Option II:

sed -i 's:CONFIG_X=y:# CONFIG_X is not set:g' .config

It's strange that non-interactive configuration seems to not get attention at all. It's certainly not applicable in general, but when you need to just flip a few switches (with few or no dependencies), e.g., a make target, then it would be very useful, more user-friendly than directly using sed, and better than maintaining .config-with-X, .config-without-X.

1

The simplest way would be to hand build the .config file with the required options. This would of course require all of the configuration options to be given, so it would be applicable in case of minor changes to an existing interactively-created .config file.

If you are asking about using the current .config but only changing some flags via the make, than I don't know. But you might try to edit the .config file via a script and then run make.

  • I tried to use sed for this purpose (changing only some flags in current .config), but in the case of many different .config files it is very difficult to take into account all dependencies and alternatives. – dimorphus Sep 1 '11 at 11:27
  • Indeed. The kernel compilation system is quite complex. If you could explain more about what you are trying to accomplish, we might be able to help you more. – Eli Iser Sep 1 '11 at 12:16
0

Answer moved to: How to script make menuconfig to automate Linux kernel build configuration?

Config fragments

scripts/kconfig/merge_config.sh

Usage:

git checkout v4.9

make x86_64_defconfig

grep -E 'CONFIG_(DEBUG_INFO|GDB_SCRIPTS)[= ]' .config
# # CONFIG_DEBUG_INFO is not set

# GDB_SCRIPTS depends on CONFIG_DEBUG_INFO in lib/Kconfig.debug

cat <<EOF >.config-fragment
CONFIG_DEBUG_INFO=y
CONFIG_GDB_SCRIPTS=y
EOF

# Order is important here. Must be first base config, then fragment.
./scripts/kconfig/merge_config.sh .config .config-fragment

grep -E 'CONFIG_(DEBUG_INFO|GDB_SCRIPTS)[= ]' .config
# CONFIG_DEBUG_INFO=y
# CONFIG_GDB_SCRIPTS=y

Process substitution does not work unfortunately:

./scripts/kconfig/merge_config.sh arch/x86/configs/x86_64_defconfig \
    <( printf 'CONFIG_DEBUG_INFO=y\nCONFIG_GDB_SCRIPTS=y\n' ) 

because of: https://unix.stackexchange.com/a/164109/32558

merge_config.sh is a simple front-end for the make alldefconfig target.

When cross compiling, ARCH must be exported when you run merge_config.sh, e.g.:

export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
make defconfig
./scripts/kconfig/merge_config.sh .config .config-fragment

Buildroot automates it with BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES: https://stackoverflow.com/questions/1414968/how-do-i-configure-the-linux-kernel-within-buildroot

Related: https://stackoverflow.com/questions/7505164/how-do-you-non-interactively-turn-on-features-in-a-linux-kernel-config-file