Makefile 8.5 KB

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