xref: /linux/scripts/kconfig/Makefile (revision feec5e1f74f5b735c0c5c02ec70673db1334173f)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds# ===========================================================================
31da177e4SLinus Torvalds# Kernel configuration targets
41da177e4SLinus Torvalds# These targets are used from top-level makefile
51da177e4SLinus Torvalds
661bee204SAl Viroifdef KBUILD_KCONFIG
761bee204SAl ViroKconfig := $(KBUILD_KCONFIG)
861bee204SAl Viroelse
9838a2e55SArnaud LacombeKconfig := Kconfig
1061bee204SAl Viroendif
11e703f75dSSam Ravnborg
12dd465996SMasahiro Yamadaifndef KBUILD_DEFCONFIG
13dd465996SMasahiro YamadaKBUILD_DEFCONFIG := defconfig
14dd465996SMasahiro Yamadaendif
15dd465996SMasahiro Yamada
160a1f00a1SMichal Marekifeq ($(quiet),silent_)
170a1f00a1SMichal Mareksilent := -s
180a1f00a1SMichal Marekendif
190a1f00a1SMichal Marek
20b75b0a81SMasahiro Yamadaexport KCONFIG_DEFCONFIG_LIST :=
21f02aa48dSMasahiro Yamadaifndef cross_compiling
22b75b0a81SMasahiro Yamadakernel-release := $(shell uname -r)
23f02aa48dSMasahiro YamadaKCONFIG_DEFCONFIG_LIST += \
24b75b0a81SMasahiro Yamada	/lib/modules/$(kernel-release)/.config \
25b75b0a81SMasahiro Yamada	/etc/kernel-config \
26f02aa48dSMasahiro Yamada	/boot/config-$(kernel-release)
27b75b0a81SMasahiro Yamadaendif
28f02aa48dSMasahiro YamadaKCONFIG_DEFCONFIG_LIST += arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG)
29b75b0a81SMasahiro Yamada
30c2838e6eSYann E. MORIN# We need this, in case the user has it in its environment
31c2838e6eSYann E. MORINunexport CONFIG_
32c2838e6eSYann E. MORIN
33f91e46b1SMasahiro Yamadaconfig-prog	:= conf
34f91e46b1SMasahiro Yamadamenuconfig-prog	:= mconf
35f91e46b1SMasahiro Yamadanconfig-prog	:= nconf
36f91e46b1SMasahiro Yamadagconfig-prog	:= gconf
37f91e46b1SMasahiro Yamadaxconfig-prog	:= qconf
381da177e4SLinus Torvalds
39f91e46b1SMasahiro Yamadadefine config_rule
40f91e46b1SMasahiro YamadaPHONY += $(1)
41f91e46b1SMasahiro Yamada$(1): $(obj)/$($(1)-prog)
42f91e46b1SMasahiro Yamada	$(Q)$$< $(silent) $(Kconfig)
431da177e4SLinus Torvalds
44f91e46b1SMasahiro YamadaPHONY += build_$(1)
45f91e46b1SMasahiro Yamadabuild_$(1): $(obj)/$($(1)-prog)
46f91e46b1SMasahiro Yamadaendef
471da177e4SLinus Torvalds
48f91e46b1SMasahiro Yamada$(foreach c, config menuconfig nconfig gconfig xconfig, $(eval $(call config_rule,$(c))))
491da177e4SLinus Torvalds
50f91e46b1SMasahiro YamadaPHONY += localmodconfig localyesconfig
512a616258SUlf Magnussonlocalyesconfig localmodconfig: $(obj)/conf
52c8138a57SMasahiro Yamada	$(Q)$(PERL) $(srctree)/$(src)/streamline_config.pl --$@ $(srctree) $(Kconfig) > .tmp.config
53a7c02602SSteven Rostedt	$(Q)if [ -f .config ]; then 				\
54a7c02602SSteven Rostedt		cmp -s .tmp.config .config ||			\
5503fa25daSSteven Rostedt		(mv -f .config .config.old.1;			\
5603fa25daSSteven Rostedt		 mv -f .tmp.config .config;			\
572a616258SUlf Magnusson		 $< $(silent) --oldconfig $(Kconfig);		\
58a7c02602SSteven Rostedt		 mv -f .config.old.1 .config.old)		\
59a7c02602SSteven Rostedt	else							\
60a7c02602SSteven Rostedt		mv -f .tmp.config .config;			\
612a616258SUlf Magnusson		$< $(silent) --oldconfig $(Kconfig);		\
62a7c02602SSteven Rostedt	fi
6303fa25daSSteven Rostedt	$(Q)rm -f .tmp.config
6403fa25daSSteven Rostedt
651cba0c30SMichal Marek# These targets map 1:1 to the commandline options of 'conf'
6679123b13SMasahiro Yamada#
6779123b13SMasahiro Yamada# Note:
6879123b13SMasahiro Yamada#  syncconfig has become an internal implementation detail and is now
6979123b13SMasahiro Yamada#  deprecated for external use
701cba0c30SMichal Mareksimple-targets := oldconfig allnoconfig allyesconfig allmodconfig \
715d8b42aaSLaura Abbott	alldefconfig randconfig listnewconfig olddefconfig syncconfig \
72c39afe62SJosh Triplett	helpnewconfig yes2modconfig mod2yesconfig mod2noconfig
735d8b42aaSLaura Abbott
741cba0c30SMichal MarekPHONY += $(simple-targets)
751da177e4SLinus Torvalds
761cba0c30SMichal Marek$(simple-targets): $(obj)/conf
7723cd88c9SMasahiro Yamada	$(Q)$< $(silent) --$@ $(Kconfig)
781da177e4SLinus Torvalds
790085b419SMasahiro YamadaPHONY += savedefconfig defconfig
80911a91c3SMasahiro Yamada
817cf3d73bSSam Ravnborgsavedefconfig: $(obj)/conf
8223cd88c9SMasahiro Yamada	$(Q)$< $(silent) --$@=defconfig $(Kconfig)
837cf3d73bSSam Ravnborg
841da177e4SLinus Torvaldsdefconfig: $(obj)/conf
85e0a26686SMasahiro Yamadaifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG)),)
860a1f00a1SMichal Marek	@$(kecho) "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
870a1f00a1SMichal Marek	$(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
88d2036f30SMichael Ellermanelse
89d2036f30SMichael Ellerman	@$(kecho) "*** Default configuration is based on target '$(KBUILD_DEFCONFIG)'"
90d2036f30SMichael Ellerman	$(Q)$(MAKE) -f $(srctree)/Makefile $(KBUILD_DEFCONFIG)
911da177e4SLinus Torvaldsendif
921da177e4SLinus Torvalds
931da177e4SLinus Torvalds%_defconfig: $(obj)/conf
940a1f00a1SMichal Marek	$(Q)$< $(silent) --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)
951da177e4SLinus Torvalds
96*feec5e1fSKees Cookconfigfiles = $(wildcard $(srctree)/kernel/configs/$(1) $(srctree)/arch/$(SRCARCH)/configs/$(1))
97*feec5e1fSKees Cookall-config-fragments = $(call configfiles,*.config)
98*feec5e1fSKees Cookconfig-fragments = $(call configfiles,$@)
993aaefce1SJosh Triplett
10063a91033SMasahiro Yamada%.config: $(obj)/conf
101*feec5e1fSKees Cook	$(if $(config-fragments),, $(error $@ fragment does not exists on this architecture))
102*feec5e1fSKees Cook	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh -m .config $(config-fragments)
1033266c806SMasahiro Yamada	$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
1043aaefce1SJosh Triplett
1050da1d4a0SJosh TriplettPHONY += tinyconfig
10663a91033SMasahiro Yamadatinyconfig:
107f8f0d064SMasahiro Yamada	$(Q)KCONFIG_ALLCONFIG=kernel/configs/tiny-base.config $(MAKE) -f $(srctree)/Makefile allnoconfig
108f8f0d064SMasahiro Yamada	$(Q)$(MAKE) -f $(srctree)/Makefile tiny.config
1090da1d4a0SJosh Triplett
110022a4bf6SMasahiro Yamada# CHECK: -o cache_dir=<path> working?
111022a4bf6SMasahiro YamadaPHONY += testconfig
112022a4bf6SMasahiro Yamadatestconfig: $(obj)/conf
11323cd88c9SMasahiro Yamada	$(Q)$(PYTHON3) -B -m pytest $(srctree)/$(src)/tests \
114022a4bf6SMasahiro Yamada	-o cache_dir=$(abspath $(obj)/tests/.cache) \
115022a4bf6SMasahiro Yamada	$(if $(findstring 1,$(KBUILD_VERBOSE)),--capture=no)
1161634f2bfSMasahiro Yamadaclean-files += tests/.cache
117022a4bf6SMasahiro Yamada
1181da177e4SLinus Torvalds# Help text used by make help
1191da177e4SLinus Torvaldshelp:
120*feec5e1fSKees Cook	@echo  'Configuration targets:'
1211da177e4SLinus Torvalds	@echo  '  config	  - Update current config utilising a line-oriented program'
122bb6d83ddSPetr Vorel	@echo  '  nconfig         - Update current config utilising a ncurses menu based program'
1231da177e4SLinus Torvalds	@echo  '  menuconfig	  - Update current config utilising a menu based program'
124092373c2SDiego Viola	@echo  '  xconfig	  - Update current config utilising a Qt based front-end'
12539c3f1baSDiego Viola	@echo  '  gconfig	  - Update current config utilising a GTK+ based front-end'
1261da177e4SLinus Torvalds	@echo  '  oldconfig	  - Update current config utilising a provided .config as base'
12703fa25daSSteven Rostedt	@echo  '  localmodconfig  - Update current config disabling modules not loaded'
128c027b02dSChangbin Du	@echo  '                    except those preserved by LMC_KEEP environment variable'
129281c9dadSSteven Rostedt	@echo  '  localyesconfig  - Update current config converting local mods to core'
130c027b02dSChangbin Du	@echo  '                    except those preserved by LMC_KEEP environment variable'
1310748cb3eSSam Ravnborg	@echo  '  defconfig	  - New config with default from ARCH supplied defconfig'
1327cf3d73bSSam Ravnborg	@echo  '  savedefconfig   - Save current config as ./defconfig (minimal config)'
133e11f0496SJesper Juhl	@echo  '  allnoconfig	  - New config where all options are answered with no'
1340748cb3eSSam Ravnborg	@echo  '  allyesconfig	  - New config where all options are accepted with yes'
1350748cb3eSSam Ravnborg	@echo  '  allmodconfig	  - New config selecting modules when possible'
1360748cb3eSSam Ravnborg	@echo  '  alldefconfig    - New config with all symbols set to default'
1370748cb3eSSam Ravnborg	@echo  '  randconfig	  - New config with random answer to all options'
13889b90609STetsuo Handa	@echo  '  yes2modconfig	  - Change answers from yes to mod if possible'
13989b90609STetsuo Handa	@echo  '  mod2yesconfig	  - Change answers from mod to yes if possible'
140c39afe62SJosh Triplett	@echo  '  mod2noconfig	  - Change answers from mod to no if possible'
141861b4ea4SSam Ravnborg	@echo  '  listnewconfig   - List new options'
1425d8b42aaSLaura Abbott	@echo  '  helpnewconfig   - List new options and help text'
143cedd55d4SMarc Herbert	@echo  '  olddefconfig	  - Same as oldconfig but sets new symbols to their'
144cedd55d4SMarc Herbert	@echo  '                    default value without prompting'
1450da1d4a0SJosh Triplett	@echo  '  tinyconfig	  - Configure the tiniest possible kernel'
146d6a0c8a1SPetr Vorel	@echo  '  testconfig	  - Run Kconfig unit tests (requires python3 and pytest)'
147*feec5e1fSKees Cook	@echo  ''
148*feec5e1fSKees Cook	@echo  'Configuration topic targets:'
149*feec5e1fSKees Cook	@$(foreach f, $(all-config-fragments), \
150*feec5e1fSKees Cook		if help=$$(grep -m1 '^# Help: ' $(f)); then \
151*feec5e1fSKees Cook			printf '  %-25s - %s\n' '$(notdir $(f))' "$${help#*: }"; \
152*feec5e1fSKees Cook		fi;)
1531da177e4SLinus Torvalds
1541da177e4SLinus Torvalds# ===========================================================================
1551da177e4SLinus Torvalds# object files used by all kconfig flavours
156a77a05dcSMasahiro Yamadacommon-objs	:= confdata.o expr.o lexer.lex.o menu.o parser.tab.o \
157a77a05dcSMasahiro Yamada		   preprocess.o symbol.o util.o
1581da177e4SLinus Torvalds
159769a1c02SMasahiro Yamada$(obj)/lexer.lex.o: $(obj)/parser.tab.h
1609cc342f6SMasahiro YamadaHOSTCFLAGS_lexer.lex.o	:= -I $(srctree)/$(src)
1619cc342f6SMasahiro YamadaHOSTCFLAGS_parser.tab.o	:= -I $(srctree)/$(src)
1621da177e4SLinus Torvalds
163558e78e3SMasahiro Yamada# conf: Used for defconfig, oldconfig and related targets
1645f2fb52fSMasahiro Yamadahostprogs	+= conf
165558e78e3SMasahiro Yamadaconf-objs	:= conf.o $(common-objs)
166558e78e3SMasahiro Yamada
1671c5af5cfSMasahiro Yamada# nconf: Used for the nconfig target based on ncurses
1685f2fb52fSMasahiro Yamadahostprogs	+= nconf
169558e78e3SMasahiro Yamadanconf-objs	:= nconf.o nconf.gui.o $(common-objs)
1707080e47bSArnaud Lacombe
1713122c844SMasahiro YamadaHOSTLDLIBS_nconf       = $(call read-file, $(obj)/nconf-libs)
1723122c844SMasahiro YamadaHOSTCFLAGS_nconf.o     = $(call read-file, $(obj)/nconf-cflags)
1733122c844SMasahiro YamadaHOSTCFLAGS_nconf.gui.o = $(call read-file, $(obj)/nconf-cflags)
1741c5af5cfSMasahiro Yamada
1753122c844SMasahiro Yamada$(obj)/nconf: | $(obj)/nconf-libs
1763122c844SMasahiro Yamada$(obj)/nconf.o $(obj)/nconf.gui.o: | $(obj)/nconf-cflags
1771c5af5cfSMasahiro Yamada
1781c5af5cfSMasahiro Yamada# mconf: Used for the menuconfig target based on lxdialog
1795f2fb52fSMasahiro Yamadahostprogs	+= mconf
18054b8ae66SMasahiro Yamadalxdialog	:= $(addprefix lxdialog/, \
18154b8ae66SMasahiro Yamada		     checklist.o inputbox.o menubox.o textbox.o util.o yesno.o)
18254b8ae66SMasahiro Yamadamconf-objs	:= mconf.o $(lxdialog) $(common-objs)
1831c5af5cfSMasahiro Yamada
1843122c844SMasahiro YamadaHOSTLDLIBS_mconf = $(call read-file, $(obj)/mconf-libs)
1851c5af5cfSMasahiro Yamada$(foreach f, mconf.o $(lxdialog), \
1863122c844SMasahiro Yamada  $(eval HOSTCFLAGS_$f = $$(call read-file, $(obj)/mconf-cflags)))
1871c5af5cfSMasahiro Yamada
1883122c844SMasahiro Yamada$(obj)/mconf: | $(obj)/mconf-libs
1893122c844SMasahiro Yamada$(addprefix $(obj)/, mconf.o $(lxdialog)): | $(obj)/mconf-cflags
1901da177e4SLinus Torvalds
1910b669a50SMasahiro Yamada# qconf: Used for the xconfig target based on Qt
1925f2fb52fSMasahiro Yamadahostprogs	+= qconf
1930e912c03SMasahiro Yamadaqconf-cxxobjs	:= qconf.o qconf-moc.o
1943b541978SMasahiro Yamadaqconf-objs	:= images.o $(common-objs)
1951da177e4SLinus Torvalds
1963122c844SMasahiro YamadaHOSTLDLIBS_qconf         = $(call read-file, $(obj)/qconf-libs)
1973122c844SMasahiro YamadaHOSTCXXFLAGS_qconf.o     = -std=c++11 -fPIC $(call read-file, $(obj)/qconf-cflags)
1983122c844SMasahiro YamadaHOSTCXXFLAGS_qconf-moc.o = -std=c++11 -fPIC $(call read-file, $(obj)/qconf-cflags)
1993122c844SMasahiro Yamada$(obj)/qconf: | $(obj)/qconf-libs
2003122c844SMasahiro Yamada$(obj)/qconf.o $(obj)/qconf-moc.o: | $(obj)/qconf-cflags
2010b669a50SMasahiro Yamada
2020b669a50SMasahiro Yamadaquiet_cmd_moc = MOC     $@
2033122c844SMasahiro Yamada      cmd_moc = $(call read-file, $(obj)/qconf-bin)/moc $< -o $@
2040b669a50SMasahiro Yamada
2053122c844SMasahiro Yamada$(obj)/qconf-moc.cc: $(src)/qconf.h FORCE | $(obj)/qconf-bin
206c3cd7cfaSMasahiro Yamada	$(call if_changed,moc)
207c3cd7cfaSMasahiro Yamada
2080e912c03SMasahiro Yamadatargets += qconf-moc.cc
2091da177e4SLinus Torvalds
210b464ef58SMasahiro Yamada# gconf: Used for the gconfig target based on GTK+
2115f2fb52fSMasahiro Yamadahostprogs	+= gconf
2123b541978SMasahiro Yamadagconf-objs	:= gconf.o images.o $(common-objs)
2131da177e4SLinus Torvalds
2143122c844SMasahiro YamadaHOSTLDLIBS_gconf   = $(call read-file, $(obj)/gconf-libs)
2153122c844SMasahiro YamadaHOSTCFLAGS_gconf.o = $(call read-file, $(obj)/gconf-cflags)
2161da177e4SLinus Torvalds
2173122c844SMasahiro Yamada$(obj)/gconf: | $(obj)/gconf-libs
2183122c844SMasahiro Yamada$(obj)/gconf.o: | $(obj)/gconf-cflags
2191da177e4SLinus Torvalds
2200b669a50SMasahiro Yamada# check if necessary packages are available, and configure build flags
221aedee9e8SPeter Foleycmd_conf_cfg = $< $(addprefix $(obj)/$*conf-, cflags libs bin); touch $(obj)/$*conf-bin
2220b669a50SMasahiro Yamada
2233122c844SMasahiro Yamada$(obj)/%conf-cflags $(obj)/%conf-libs $(obj)/%conf-bin: $(src)/%conf-cfg.sh
2243122c844SMasahiro Yamada	$(call cmd,conf_cfg)
2250b669a50SMasahiro Yamada
2263122c844SMasahiro Yamadaclean-files += *conf-cflags *conf-libs *conf-bin
227