1 ################################################################################
2 # Kconfig package infrastructure
4 # This file implements an infrastructure that eases development of
5 # package .mk files for packages that use kconfig for configuration files.
6 # It is based on the generic-package infrastructure, and inherits all of its
9 # See the Buildroot documentation for details on the usage of this
12 ################################################################################
14 ################################################################################
15 # inner-kconfig-package -- generates the make targets needed to support a
18 # argument 1 is the lowercase package name
19 # argument 2 is the uppercase package name, including a HOST_ prefix
21 # argument 3 is the uppercase package name, without the HOST_ prefix
23 # argument 4 is the type (target or host)
24 ################################################################################
26 define inner-kconfig-package
28 # Call the generic package infrastructure to generate the necessary
30 # Note: this must be done _before_ attempting to use $$($(2)_DIR) in a
31 # dependency expression
32 $(call inner-generic-package
,$(1),$(2),$(3),$(4))
35 $(2)_KCONFIG_EDITORS ?
= menuconfig
37 $(2)_KCONFIG_FIXUP_CMDS ?
=
38 $(2)_KCONFIG_FRAGMENT_FILES ?
=
40 # The config file as well as the fragments could be in-tree, so before
41 # depending on them the package should be extracted (and patched) first.
43 # Since those files only have a order-only dependency, make would treat
44 # any missing one as a "force" target:
45 # https://www.gnu.org/software/make/manual/make.html#Force-Targets
46 # and would forcibly any rule that depend on those files, causing a
47 # rebuild of the kernel each time make is called.
49 # So, we provide a recipe that checks all of those files exist, to
50 # overcome that standard make behaviour.
52 $$($(2)_KCONFIG_FILE
) $$($(2)_KCONFIG_FRAGMENT_FILES
): |
$(1)-patch
53 for f in
$$($(2)_KCONFIG_FILE
) $$($(2)_KCONFIG_FRAGMENT_FILES
); do \
54 if
[ ! -f
"$$$${f}" ]; then \
55 printf
"Kconfig fragment '%s' for '%s' does not exist\n" "$$$${f}" "$(1)"; \
61 $$($(2)_MAKE_ENV
) $$(MAKE
) -C
$$($(2)_DIR
) $$($(2)_KCONFIG_OPTS
)
63 # $(2)_KCONFIG_MAKE may already rely on shell expansion. As the $() syntax
64 # of the shell conflicts with Make's own syntax, this means that backticks
65 # are used with those shell constructs. Unfortunately, the backtick syntax
66 # does not nest, and we need to use Make instead of the shell to handle
69 # A recursively expanded variable is necessary, to be sure that the shell
70 # command is called when the rule is processed during the build and not
71 # when the rule is created when parsing all packages.
72 $(2)_KCONFIG_RULES
= \
73 $$(shell $$($(2)_KCONFIG_MAKE
) -pn config
2>/dev
/null | \
74 sed
's/^\([_0-9a-zA-Z]*config\):.*/\1/ p; d')
76 # The correct way to regenerate a .config file is to use 'make olddefconfig'.
77 # For historical reasons, the target name is 'oldnoconfig' between Linux kernel
78 # versions 2.6.36 and 3.6, and remains as an alias in later versions.
79 # In older versions, and in some other projects that use kconfig, the target is
80 # not supported at all, and we use 'yes "" | make oldconfig' as a fallback
81 # only, as this can fail in complex cases.
82 define $(2)_REGEN_DOT_CONFIG
83 $$(if
$$(filter olddefconfig
,$$($(2)_KCONFIG_RULES
)),
84 $$(Q
)$$($(2)_KCONFIG_MAKE
) olddefconfig
,
85 $$(if
$$(filter oldnoconfig
,$$($(2)_KCONFIG_RULES
)),
86 $$(Q
)$$($(2)_KCONFIG_MAKE
) oldnoconfig
,
87 $$(Q
)(yes
"" |
$$($(2)_KCONFIG_MAKE
) oldconfig
)))
90 # The specified source configuration file and any additional configuration file
91 # fragments are merged together to .config, after the package has been patched.
92 # Since the file could be a defconfig file it needs to be expanded to a
94 $$($(2)_DIR
)/.config
: $$($(2)_KCONFIG_FILE
) $$($(2)_KCONFIG_FRAGMENT_FILES
)
95 $$(Q
)$$(if
$$($(2)_KCONFIG_DEFCONFIG
), \
96 $$($(2)_KCONFIG_MAKE
) $$($(2)_KCONFIG_DEFCONFIG
), \
97 cp
$$($(2)_KCONFIG_FILE
) $$(@
))
98 $$(Q
)support
/kconfig
/merge_config.sh
-m
-O
$$(@D
) \
99 $$(@
) $$($(2)_KCONFIG_FRAGMENT_FILES
)
100 $$($(2)_REGEN_DOT_CONFIG
)
102 # If _KCONFIG_FILE or _KCONFIG_FRAGMENT_FILES exists, this dependency is
103 # already implied, but if we only have a _KCONFIG_DEFCONFIG we have to add
104 # it explicitly. It doesn't hurt to always have it though.
105 $$($(2)_DIR
)/.config
: |
$(1)-patch
107 # In order to get a usable, consistent configuration, some fixup may be needed.
108 # The exact rules are specified by the package .mk file.
109 define $(2)_FIXUP_DOT_CONFIG
110 $$($(2)_KCONFIG_FIXUP_CMDS
)
111 $$($(2)_REGEN_DOT_CONFIG
)
112 $$(Q
)touch
$$($(2)_DIR
)/.stamp_kconfig_fixup_done
115 $$($(2)_DIR
)/.stamp_kconfig_fixup_done
: $$($(2)_DIR
)/.config
116 $$($(2)_FIXUP_DOT_CONFIG
)
118 # Before running configure, the configuration file should be present and fixed
119 $$($(2)_TARGET_CONFIGURE
): $$($(2)_DIR
)/.stamp_kconfig_fixup_done
121 # Only enable the foo-*config targets when the package is actually enabled.
122 # Note: the variable $(2)_KCONFIG_VAR is not related to the kconfig
123 # infrastructure, but defined by pkg-generic.mk. The generic infrastructure is
124 # already called above, so we can effectively use this variable.
125 ifeq ($$($$($(2)_KCONFIG_VAR
)),y
)
127 ifeq ($$(BR_BUILDING
),y
)
128 # Either FOO_KCONFIG_FILE or FOO_KCONFIG_DEFCONFIG is required...
129 ifeq ($$(or
$$($(2)_KCONFIG_FILE
),$$($(2)_KCONFIG_DEFCONFIG
)),)
130 $$(error Internal error
: no value specified for
$(2)_KCONFIG_FILE or
$(2)_KCONFIG_DEFCONFIG
)
133 ifneq ($$(and
$$($(2)_KCONFIG_FILE
),$$($(2)_KCONFIG_DEFCONFIG
)),)
134 $$(error Internal error
: $(2)_KCONFIG_FILE and
$(2)_KCONFIG_DEFCONFIG are mutually exclusive but both are defined
)
138 # For the configurators, we do want to use the system-provided host
139 # tools, not the ones we build. This is particularly true for
140 # pkg-config; if we use our pkg-config (from host-pkgconf), then it
141 # would not look for the .pc from the host, but we do need them,
142 # especially to find ncurses, GTK+, Qt (resp. for menuconfig and
143 # nconfig, gconfig, xconfig).
144 # So we simply remove our PATH and PKG_CONFIG_* variables.
145 $(2)_CONFIGURATOR_MAKE_ENV
= \
146 $$(filter-out PATH
=% PKG_CONFIG
=% PKG_CONFIG_SYSROOT_DIR
=% PKG_CONFIG_LIBDIR
=%,$$($(2)_MAKE_ENV
)) \
147 PKG_CONFIG_PATH
="$(HOST_PKG_CONFIG_PATH)"
149 # Configuration editors (menuconfig, ...)
151 # We need to apply the configuration fixups right after a configuration
152 # editor exits, so that it is possible to save the configuration right
153 # after exiting an editor, and so the user always sees a .config file
154 # that is clean wrt. our requirements.
156 # Because commands in $(1)_FIXUP_KCONFIG are probably using $(@D), we
157 # need to have a valid @D set. But, because the configurators rules are
158 # not real files and do not contain the path to the package build dir,
159 # @D would be just '.' in this case. So, we use an intermediate rule
160 # with a stamp-like file which path is in the package build dir, so we
161 # end up having a valid @D.
163 $$(addprefix $(1)-,$$($(2)_KCONFIG_EDITORS
)): $(1)-%: $$($(2)_DIR
)/.kconfig_editor_
%
164 $$($(2)_DIR
)/.kconfig_editor_
%: $$($(2)_DIR
)/.stamp_kconfig_fixup_done
165 $$($(2)_CONFIGURATOR_MAKE_ENV
) $$(MAKE
) -C
$$($(2)_DIR
) \
166 $$($(2)_KCONFIG_OPTS
) $$(*)
167 rm -f
$$($(2)_DIR
)/.stamp_
{kconfig_fixup_done
,configured
,built
}
168 rm -f
$$($(2)_DIR
)/.stamp_
{target
,staging
,images
}_installed
169 $$($(2)_FIXUP_DOT_CONFIG
)
171 # Saving back the configuration
173 # Ideally, that should directly depend on $$($(2)_DIR)/.stamp_kconfig_fixup_done,
174 # but that breaks the use-case in PR-8156 (from a clean tree):
175 # make menuconfig <- enable kernel, use an in-tree defconfig, save and exit
176 # make linux-menuconfig <- enable/disable whatever option, save and exit
177 # make menuconfig <- change to use a custom defconfig file, set a path, save and exit
178 # make linux-update-config <- should save to the new custom defconfig file
180 # Because of that use-case, saving the configuration can *not* directly
181 # depend on the stamp file, because it itself depends on the .config,
182 # which in turn depends on the (newly-set an non-existent) custom
185 # Instead, we use an PHONY rule that will catch that situation.
187 $(1)-check-configuration-done
:
188 @if
[ ! -f
$$($(2)_DIR
)/.stamp_kconfig_fixup_done
]; then \
189 echo
"$(1) is not yet configured"; \
193 $(1)-savedefconfig
: $(1)-check-configuration-done
194 $$($(2)_MAKE_ENV
) $$(MAKE
) -C
$$($(2)_DIR
) \
195 $$($(2)_KCONFIG_OPTS
) savedefconfig
197 # Target to copy back the configuration to the source configuration file
198 # Even though we could use 'cp --preserve-timestamps' here, the separate
199 # cp and 'touch --reference' is used for symmetry with $(1)-update-defconfig.
200 $(1)-update-config
: $(1)-check-configuration-done
201 @
$$(if
$$($(2)_KCONFIG_FRAGMENT_FILES
), \
202 echo
"Unable to perform $(1)-update-config when fragment files are set"; exit
1)
203 @
$$(if
$$($(2)_KCONFIG_DEFCONFIG
), \
204 echo
"Unable to perform $(1)-update-config when using a defconfig rule"; exit
1)
205 cp
-f
$$($(2)_DIR
)/.config
$$($(2)_KCONFIG_FILE
)
206 touch
--reference
$$($(2)_DIR
)/.config
$$($(2)_KCONFIG_FILE
)
208 # Note: make sure the timestamp of the stored configuration is not newer than
209 # the .config to avoid a useless rebuild. Note that, contrary to
210 # $(1)-update-config, the reference for 'touch' is _not_ the file from which
212 $(1)-update-defconfig
: $(1)-savedefconfig
213 @
$$(if
$$($(2)_KCONFIG_FRAGMENT_FILES
), \
214 echo
"Unable to perform $(1)-update-defconfig when fragment files are set"; exit
1)
215 @
$$(if
$$($(2)_KCONFIG_DEFCONFIG
), \
216 echo
"Unable to perform $(1)-update-defconfig when using a defconfig rule"; exit
1)
217 cp
-f
$$($(2)_DIR
)/defconfig
$$($(2)_KCONFIG_FILE
)
218 touch
--reference
$$($(2)_DIR
)/.config
$$($(2)_KCONFIG_FILE
)
220 endif # package enabled
224 $(1)-update-defconfig \
226 $(1)-check-configuration-done \
227 $$($(2)_DIR
)/.kconfig_editor_
% \
228 $$(addprefix $(1)-,$$($(2)_KCONFIG_EDITORS
))
230 endef # inner-kconfig-package
232 ################################################################################
233 # kconfig-package -- the target generator macro for kconfig packages
234 ################################################################################
236 kconfig-package
= $(call inner-kconfig-package
,$(pkgname
),$(call UPPERCASE
,$(pkgname
)),$(call UPPERCASE
,$(pkgname
)),target
)