xref: /linux-6.15/scripts/kconfig/Makefile (revision b75b0a81)
1# SPDX-License-Identifier: GPL-2.0
2# ===========================================================================
3# Kernel configuration targets
4# These targets are used from top-level makefile
5
6ifdef KBUILD_KCONFIG
7Kconfig := $(KBUILD_KCONFIG)
8else
9Kconfig := Kconfig
10endif
11
12ifeq ($(quiet),silent_)
13silent := -s
14endif
15
16export KCONFIG_DEFCONFIG_LIST :=
17ifneq ($(SRCARCH),um)
18kernel-release := $(shell uname -r)
19KCONFIG_DEFCONFIG_LIST := \
20	/lib/modules/$(kernel-release)/.config \
21	/etc/kernel-config \
22	/boot/config-$(kernel-release) \
23	arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG)
24endif
25
26# We need this, in case the user has it in its environment
27unexport CONFIG_
28
29config-prog	:= conf
30menuconfig-prog	:= mconf
31nconfig-prog	:= nconf
32gconfig-prog	:= gconf
33xconfig-prog	:= qconf
34
35define config_rule
36PHONY += $(1)
37$(1): $(obj)/$($(1)-prog)
38	$(Q)$$< $(silent) $(Kconfig)
39
40PHONY += build_$(1)
41build_$(1): $(obj)/$($(1)-prog)
42endef
43
44$(foreach c, config menuconfig nconfig gconfig xconfig, $(eval $(call config_rule,$(c))))
45
46PHONY += localmodconfig localyesconfig
47localyesconfig localmodconfig: $(obj)/conf
48	$(Q)$(PERL) $(srctree)/$(src)/streamline_config.pl --$@ $(srctree) $(Kconfig) > .tmp.config
49	$(Q)if [ -f .config ]; then 				\
50		cmp -s .tmp.config .config ||			\
51		(mv -f .config .config.old.1;			\
52		 mv -f .tmp.config .config;			\
53		 $< $(silent) --oldconfig $(Kconfig);		\
54		 mv -f .config.old.1 .config.old)		\
55	else							\
56		mv -f .tmp.config .config;			\
57		$< $(silent) --oldconfig $(Kconfig);		\
58	fi
59	$(Q)rm -f .tmp.config
60
61# These targets map 1:1 to the commandline options of 'conf'
62#
63# Note:
64#  syncconfig has become an internal implementation detail and is now
65#  deprecated for external use
66simple-targets := oldconfig allnoconfig allyesconfig allmodconfig \
67	alldefconfig randconfig listnewconfig olddefconfig syncconfig \
68	helpnewconfig yes2modconfig mod2yesconfig
69
70PHONY += $(simple-targets)
71
72$(simple-targets): $(obj)/conf
73	$(Q)$< $(silent) --$@ $(Kconfig)
74
75PHONY += savedefconfig defconfig
76
77savedefconfig: $(obj)/conf
78	$(Q)$< $(silent) --$@=defconfig $(Kconfig)
79
80defconfig: $(obj)/conf
81ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG)),)
82	@$(kecho) "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
83	$(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
84else
85	@$(kecho) "*** Default configuration is based on target '$(KBUILD_DEFCONFIG)'"
86	$(Q)$(MAKE) -f $(srctree)/Makefile $(KBUILD_DEFCONFIG)
87endif
88
89%_defconfig: $(obj)/conf
90	$(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)
91
92configfiles=$(wildcard $(srctree)/kernel/configs/$@ $(srctree)/arch/$(SRCARCH)/configs/$@)
93
94%.config: $(obj)/conf
95	$(if $(call configfiles),, $(error No configuration exists for this target on this architecture))
96	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh -m .config $(configfiles)
97	$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
98
99PHONY += tinyconfig
100tinyconfig:
101	$(Q)$(MAKE) -f $(srctree)/Makefile allnoconfig tiny.config
102
103# CHECK: -o cache_dir=<path> working?
104PHONY += testconfig
105testconfig: $(obj)/conf
106	$(Q)$(PYTHON3) -B -m pytest $(srctree)/$(src)/tests \
107	-o cache_dir=$(abspath $(obj)/tests/.cache) \
108	$(if $(findstring 1,$(KBUILD_VERBOSE)),--capture=no)
109clean-files += tests/.cache
110
111# Help text used by make help
112help:
113	@echo  '  config	  - Update current config utilising a line-oriented program'
114	@echo  '  nconfig         - Update current config utilising a ncurses menu based program'
115	@echo  '  menuconfig	  - Update current config utilising a menu based program'
116	@echo  '  xconfig	  - Update current config utilising a Qt based front-end'
117	@echo  '  gconfig	  - Update current config utilising a GTK+ based front-end'
118	@echo  '  oldconfig	  - Update current config utilising a provided .config as base'
119	@echo  '  localmodconfig  - Update current config disabling modules not loaded'
120	@echo  '                    except those preserved by LMC_KEEP environment variable'
121	@echo  '  localyesconfig  - Update current config converting local mods to core'
122	@echo  '                    except those preserved by LMC_KEEP environment variable'
123	@echo  '  defconfig	  - New config with default from ARCH supplied defconfig'
124	@echo  '  savedefconfig   - Save current config as ./defconfig (minimal config)'
125	@echo  '  allnoconfig	  - New config where all options are answered with no'
126	@echo  '  allyesconfig	  - New config where all options are accepted with yes'
127	@echo  '  allmodconfig	  - New config selecting modules when possible'
128	@echo  '  alldefconfig    - New config with all symbols set to default'
129	@echo  '  randconfig	  - New config with random answer to all options'
130	@echo  '  yes2modconfig	  - Change answers from yes to mod if possible'
131	@echo  '  mod2yesconfig	  - Change answers from mod to yes if possible'
132	@echo  '  listnewconfig   - List new options'
133	@echo  '  helpnewconfig   - List new options and help text'
134	@echo  '  olddefconfig	  - Same as oldconfig but sets new symbols to their'
135	@echo  '                    default value without prompting'
136	@echo  '  tinyconfig	  - Configure the tiniest possible kernel'
137	@echo  '  testconfig	  - Run Kconfig unit tests (requires python3 and pytest)'
138
139# ===========================================================================
140# object files used by all kconfig flavours
141common-objs	:= confdata.o expr.o lexer.lex.o parser.tab.o preprocess.o \
142		   symbol.o util.o
143
144$(obj)/lexer.lex.o: $(obj)/parser.tab.h
145HOSTCFLAGS_lexer.lex.o	:= -I $(srctree)/$(src)
146HOSTCFLAGS_parser.tab.o	:= -I $(srctree)/$(src)
147
148# conf: Used for defconfig, oldconfig and related targets
149hostprogs	+= conf
150conf-objs	:= conf.o $(common-objs)
151
152# nconf: Used for the nconfig target based on ncurses
153hostprogs	+= nconf
154nconf-objs	:= nconf.o nconf.gui.o $(common-objs)
155
156HOSTLDLIBS_nconf	= $(shell . $(obj)/nconf-cfg && echo $$libs)
157HOSTCFLAGS_nconf.o	= $(shell . $(obj)/nconf-cfg && echo $$cflags)
158HOSTCFLAGS_nconf.gui.o	= $(shell . $(obj)/nconf-cfg && echo $$cflags)
159
160$(obj)/nconf.o $(obj)/nconf.gui.o: $(obj)/nconf-cfg
161
162# mconf: Used for the menuconfig target based on lxdialog
163hostprogs	+= mconf
164lxdialog	:= $(addprefix lxdialog/, \
165		     checklist.o inputbox.o menubox.o textbox.o util.o yesno.o)
166mconf-objs	:= mconf.o $(lxdialog) $(common-objs)
167
168HOSTLDLIBS_mconf = $(shell . $(obj)/mconf-cfg && echo $$libs)
169$(foreach f, mconf.o $(lxdialog), \
170  $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/mconf-cfg && echo $$$$cflags)))
171
172$(addprefix $(obj)/, mconf.o $(lxdialog)): $(obj)/mconf-cfg
173
174# qconf: Used for the xconfig target based on Qt
175hostprogs	+= qconf
176qconf-cxxobjs	:= qconf.o qconf-moc.o
177qconf-objs	:= images.o $(common-objs)
178
179HOSTLDLIBS_qconf	= $(shell . $(obj)/qconf-cfg && echo $$libs)
180HOSTCXXFLAGS_qconf.o	= $(shell . $(obj)/qconf-cfg && echo $$cflags)
181HOSTCXXFLAGS_qconf-moc.o = $(shell . $(obj)/qconf-cfg && echo $$cflags)
182
183$(obj)/qconf.o: $(obj)/qconf-cfg
184
185quiet_cmd_moc = MOC     $@
186      cmd_moc = $(shell . $(obj)/qconf-cfg && echo $$moc) $< -o $@
187
188$(obj)/qconf-moc.cc: $(src)/qconf.h $(obj)/qconf-cfg FORCE
189	$(call if_changed,moc)
190
191targets += qconf-moc.cc
192
193# gconf: Used for the gconfig target based on GTK+
194hostprogs	+= gconf
195gconf-objs	:= gconf.o images.o $(common-objs)
196
197HOSTLDLIBS_gconf    = $(shell . $(obj)/gconf-cfg && echo $$libs)
198HOSTCFLAGS_gconf.o  = $(shell . $(obj)/gconf-cfg && echo $$cflags)
199
200$(obj)/gconf.o: $(obj)/gconf-cfg
201
202# check if necessary packages are available, and configure build flags
203filechk_conf_cfg = $(CONFIG_SHELL) $<
204
205$(obj)/%conf-cfg: $(src)/%conf-cfg.sh FORCE
206	$(call filechk,conf_cfg)
207
208clean-files += *conf-cfg
209