18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci# ===========================================================================
38c2ecf20Sopenharmony_ci# Kernel configuration targets
48c2ecf20Sopenharmony_ci# These targets are used from top-level makefile
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ciPHONY += xconfig gconfig menuconfig config localmodconfig localyesconfig \
78c2ecf20Sopenharmony_ci	build_menuconfig build_nconfig build_gconfig build_xconfig
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciifdef KBUILD_KCONFIG
108c2ecf20Sopenharmony_ciKconfig := $(KBUILD_KCONFIG)
118c2ecf20Sopenharmony_cielse
128c2ecf20Sopenharmony_ciKconfig := Kconfig
138c2ecf20Sopenharmony_ciendif
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciifeq ($(quiet),silent_)
168c2ecf20Sopenharmony_cisilent := -s
178c2ecf20Sopenharmony_ciendif
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci# We need this, in case the user has it in its environment
208c2ecf20Sopenharmony_ciunexport CONFIG_
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cixconfig: $(obj)/qconf
238c2ecf20Sopenharmony_ci	$(Q)$< $(silent) $(Kconfig)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cigconfig: $(obj)/gconf
268c2ecf20Sopenharmony_ci	$(Q)$< $(silent) $(Kconfig)
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cimenuconfig: $(obj)/mconf
298c2ecf20Sopenharmony_ci	$(Q)$< $(silent) $(Kconfig)
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciconfig: $(obj)/conf
328c2ecf20Sopenharmony_ci	$(Q)$< $(silent) --oldaskconfig $(Kconfig)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cinconfig: $(obj)/nconf
358c2ecf20Sopenharmony_ci	$(Q)$< $(silent) $(Kconfig)
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cibuild_menuconfig: $(obj)/mconf
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cibuild_nconfig: $(obj)/nconf
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cibuild_gconfig: $(obj)/gconf
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cibuild_xconfig: $(obj)/qconf
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cilocalyesconfig localmodconfig: $(obj)/conf
468c2ecf20Sopenharmony_ci	$(Q)$(PERL) $(srctree)/$(src)/streamline_config.pl --$@ $(srctree) $(Kconfig) > .tmp.config
478c2ecf20Sopenharmony_ci	$(Q)if [ -f .config ]; then 				\
488c2ecf20Sopenharmony_ci		cmp -s .tmp.config .config ||			\
498c2ecf20Sopenharmony_ci		(mv -f .config .config.old.1;			\
508c2ecf20Sopenharmony_ci		 mv -f .tmp.config .config;			\
518c2ecf20Sopenharmony_ci		 $< $(silent) --oldconfig $(Kconfig);		\
528c2ecf20Sopenharmony_ci		 mv -f .config.old.1 .config.old)		\
538c2ecf20Sopenharmony_ci	else							\
548c2ecf20Sopenharmony_ci		mv -f .tmp.config .config;			\
558c2ecf20Sopenharmony_ci		$< $(silent) --oldconfig $(Kconfig);		\
568c2ecf20Sopenharmony_ci	fi
578c2ecf20Sopenharmony_ci	$(Q)rm -f .tmp.config
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci# These targets map 1:1 to the commandline options of 'conf'
608c2ecf20Sopenharmony_ci#
618c2ecf20Sopenharmony_ci# Note:
628c2ecf20Sopenharmony_ci#  syncconfig has become an internal implementation detail and is now
638c2ecf20Sopenharmony_ci#  deprecated for external use
648c2ecf20Sopenharmony_cisimple-targets := oldconfig allnoconfig allyesconfig allmodconfig \
658c2ecf20Sopenharmony_ci	alldefconfig randconfig listnewconfig olddefconfig syncconfig \
668c2ecf20Sopenharmony_ci	helpnewconfig yes2modconfig mod2yesconfig
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ciPHONY += $(simple-targets)
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci$(simple-targets): $(obj)/conf
718c2ecf20Sopenharmony_ci	$(Q)$< $(silent) --$@ $(Kconfig)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ciPHONY += savedefconfig defconfig
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cisavedefconfig: $(obj)/conf
768c2ecf20Sopenharmony_ci	$(Q)$< $(silent) --$@=defconfig $(Kconfig)
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_cidefconfig: $(obj)/conf
798c2ecf20Sopenharmony_ciifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG)),)
808c2ecf20Sopenharmony_ci	@$(kecho) "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
818c2ecf20Sopenharmony_ci	$(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
828c2ecf20Sopenharmony_cielse
838c2ecf20Sopenharmony_ci	@$(kecho) "*** Default configuration is based on target '$(KBUILD_DEFCONFIG)'"
848c2ecf20Sopenharmony_ci	$(Q)$(MAKE) -f $(srctree)/Makefile $(KBUILD_DEFCONFIG)
858c2ecf20Sopenharmony_ciendif
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci%_defconfig: $(obj)/conf
888c2ecf20Sopenharmony_ci	$(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ciconfigfiles=$(wildcard $(srctree)/kernel/configs/$@ $(srctree)/arch/$(SRCARCH)/configs/$@)
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci%.config: $(obj)/conf
938c2ecf20Sopenharmony_ci	$(if $(call configfiles),, $(error No configuration exists for this target on this architecture))
948c2ecf20Sopenharmony_ci	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh -m .config $(configfiles)
958c2ecf20Sopenharmony_ci	$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ciPHONY += kvmconfig
988c2ecf20Sopenharmony_cikvmconfig: kvm_guest.config
998c2ecf20Sopenharmony_ci	@echo >&2 "WARNING: 'make $@' will be removed after Linux 5.10"
1008c2ecf20Sopenharmony_ci	@echo >&2 "         Please use 'make $<' instead."
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ciPHONY += xenconfig
1038c2ecf20Sopenharmony_cixenconfig: xen.config
1048c2ecf20Sopenharmony_ci	@echo >&2 "WARNING: 'make $@' will be removed after Linux 5.10"
1058c2ecf20Sopenharmony_ci	@echo >&2 "         Please use 'make $<' instead."
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ciPHONY += tinyconfig
1088c2ecf20Sopenharmony_citinyconfig:
1098c2ecf20Sopenharmony_ci	$(Q)$(MAKE) -f $(srctree)/Makefile allnoconfig tiny.config
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci# CHECK: -o cache_dir=<path> working?
1128c2ecf20Sopenharmony_ciPHONY += testconfig
1138c2ecf20Sopenharmony_citestconfig: $(obj)/conf
1148c2ecf20Sopenharmony_ci	$(Q)$(PYTHON3) -B -m pytest $(srctree)/$(src)/tests \
1158c2ecf20Sopenharmony_ci	-o cache_dir=$(abspath $(obj)/tests/.cache) \
1168c2ecf20Sopenharmony_ci	$(if $(findstring 1,$(KBUILD_VERBOSE)),--capture=no)
1178c2ecf20Sopenharmony_ciclean-files += tests/.cache
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci# Help text used by make help
1208c2ecf20Sopenharmony_cihelp:
1218c2ecf20Sopenharmony_ci	@echo  '  config	  - Update current config utilising a line-oriented program'
1228c2ecf20Sopenharmony_ci	@echo  '  nconfig         - Update current config utilising a ncurses menu based program'
1238c2ecf20Sopenharmony_ci	@echo  '  menuconfig	  - Update current config utilising a menu based program'
1248c2ecf20Sopenharmony_ci	@echo  '  xconfig	  - Update current config utilising a Qt based front-end'
1258c2ecf20Sopenharmony_ci	@echo  '  gconfig	  - Update current config utilising a GTK+ based front-end'
1268c2ecf20Sopenharmony_ci	@echo  '  oldconfig	  - Update current config utilising a provided .config as base'
1278c2ecf20Sopenharmony_ci	@echo  '  localmodconfig  - Update current config disabling modules not loaded'
1288c2ecf20Sopenharmony_ci	@echo  '                    except those preserved by LMC_KEEP environment variable'
1298c2ecf20Sopenharmony_ci	@echo  '  localyesconfig  - Update current config converting local mods to core'
1308c2ecf20Sopenharmony_ci	@echo  '                    except those preserved by LMC_KEEP environment variable'
1318c2ecf20Sopenharmony_ci	@echo  '  defconfig	  - New config with default from ARCH supplied defconfig'
1328c2ecf20Sopenharmony_ci	@echo  '  savedefconfig   - Save current config as ./defconfig (minimal config)'
1338c2ecf20Sopenharmony_ci	@echo  '  allnoconfig	  - New config where all options are answered with no'
1348c2ecf20Sopenharmony_ci	@echo  '  allyesconfig	  - New config where all options are accepted with yes'
1358c2ecf20Sopenharmony_ci	@echo  '  allmodconfig	  - New config selecting modules when possible'
1368c2ecf20Sopenharmony_ci	@echo  '  alldefconfig    - New config with all symbols set to default'
1378c2ecf20Sopenharmony_ci	@echo  '  randconfig	  - New config with random answer to all options'
1388c2ecf20Sopenharmony_ci	@echo  '  yes2modconfig	  - Change answers from yes to mod if possible'
1398c2ecf20Sopenharmony_ci	@echo  '  mod2yesconfig	  - Change answers from mod to yes if possible'
1408c2ecf20Sopenharmony_ci	@echo  '  listnewconfig   - List new options'
1418c2ecf20Sopenharmony_ci	@echo  '  helpnewconfig   - List new options and help text'
1428c2ecf20Sopenharmony_ci	@echo  '  olddefconfig	  - Same as oldconfig but sets new symbols to their'
1438c2ecf20Sopenharmony_ci	@echo  '                    default value without prompting'
1448c2ecf20Sopenharmony_ci	@echo  '  tinyconfig	  - Configure the tiniest possible kernel'
1458c2ecf20Sopenharmony_ci	@echo  '  testconfig	  - Run Kconfig unit tests (requires python3 and pytest)'
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci# ===========================================================================
1488c2ecf20Sopenharmony_ci# object files used by all kconfig flavours
1498c2ecf20Sopenharmony_cicommon-objs	:= confdata.o expr.o lexer.lex.o parser.tab.o preprocess.o \
1508c2ecf20Sopenharmony_ci		   symbol.o util.o
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci$(obj)/lexer.lex.o: $(obj)/parser.tab.h
1538c2ecf20Sopenharmony_ciHOSTCFLAGS_lexer.lex.o	:= -I $(srctree)/$(src)
1548c2ecf20Sopenharmony_ciHOSTCFLAGS_parser.tab.o	:= -I $(srctree)/$(src)
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci# conf: Used for defconfig, oldconfig and related targets
1578c2ecf20Sopenharmony_cihostprogs	+= conf
1588c2ecf20Sopenharmony_ciconf-objs	:= conf.o $(common-objs)
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci# nconf: Used for the nconfig target based on ncurses
1618c2ecf20Sopenharmony_cihostprogs	+= nconf
1628c2ecf20Sopenharmony_cinconf-objs	:= nconf.o nconf.gui.o $(common-objs)
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ciHOSTLDLIBS_nconf	= $(shell . $(obj)/nconf-cfg && echo $$libs)
1658c2ecf20Sopenharmony_ciHOSTCFLAGS_nconf.o	= $(shell . $(obj)/nconf-cfg && echo $$cflags)
1668c2ecf20Sopenharmony_ciHOSTCFLAGS_nconf.gui.o	= $(shell . $(obj)/nconf-cfg && echo $$cflags)
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci$(obj)/nconf.o $(obj)/nconf.gui.o: $(obj)/nconf-cfg
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci# mconf: Used for the menuconfig target based on lxdialog
1718c2ecf20Sopenharmony_cihostprogs	+= mconf
1728c2ecf20Sopenharmony_cilxdialog	:= $(addprefix lxdialog/, \
1738c2ecf20Sopenharmony_ci		     checklist.o inputbox.o menubox.o textbox.o util.o yesno.o)
1748c2ecf20Sopenharmony_cimconf-objs	:= mconf.o $(lxdialog) $(common-objs)
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ciHOSTLDLIBS_mconf = $(shell . $(obj)/mconf-cfg && echo $$libs)
1778c2ecf20Sopenharmony_ci$(foreach f, mconf.o $(lxdialog), \
1788c2ecf20Sopenharmony_ci  $(eval HOSTCFLAGS_$f = $$(shell . $(obj)/mconf-cfg && echo $$$$cflags)))
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci$(addprefix $(obj)/, mconf.o $(lxdialog)): $(obj)/mconf-cfg
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci# qconf: Used for the xconfig target based on Qt
1838c2ecf20Sopenharmony_cihostprogs	+= qconf
1848c2ecf20Sopenharmony_ciqconf-cxxobjs	:= qconf.o qconf-moc.o
1858c2ecf20Sopenharmony_ciqconf-objs	:= images.o $(common-objs)
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ciHOSTLDLIBS_qconf	= $(shell . $(obj)/qconf-cfg && echo $$libs)
1888c2ecf20Sopenharmony_ciHOSTCXXFLAGS_qconf.o	= $(shell . $(obj)/qconf-cfg && echo $$cflags)
1898c2ecf20Sopenharmony_ciHOSTCXXFLAGS_qconf-moc.o = $(shell . $(obj)/qconf-cfg && echo $$cflags)
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci$(obj)/qconf.o: $(obj)/qconf-cfg
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ciquiet_cmd_moc = MOC     $@
1948c2ecf20Sopenharmony_ci      cmd_moc = $(shell . $(obj)/qconf-cfg && echo $$moc) $< -o $@
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci$(obj)/qconf-moc.cc: $(src)/qconf.h $(obj)/qconf-cfg FORCE
1978c2ecf20Sopenharmony_ci	$(call if_changed,moc)
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_citargets += qconf-moc.cc
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci# gconf: Used for the gconfig target based on GTK+
2028c2ecf20Sopenharmony_cihostprogs	+= gconf
2038c2ecf20Sopenharmony_cigconf-objs	:= gconf.o images.o $(common-objs)
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ciHOSTLDLIBS_gconf    = $(shell . $(obj)/gconf-cfg && echo $$libs)
2068c2ecf20Sopenharmony_ciHOSTCFLAGS_gconf.o  = $(shell . $(obj)/gconf-cfg && echo $$cflags)
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci$(obj)/gconf.o: $(obj)/gconf-cfg
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci# check if necessary packages are available, and configure build flags
2118c2ecf20Sopenharmony_cifilechk_conf_cfg = $(CONFIG_SHELL) $<
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci$(obj)/%conf-cfg: $(src)/%conf-cfg.sh FORCE
2148c2ecf20Sopenharmony_ci	$(call filechk,conf_cfg)
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ciclean-files += *conf-cfg
217