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 ?=
39 # The config file could be in-tree, so before depending on it the package should
40 # be extracted (and patched) first
41 $$($(2)_KCONFIG_FILE): | $(1)-patch
43 # The .config file is obtained by copying it from the specified source
44 # configuration file, after the package has been patched.
45 # Since the file could be a defconfig file it needs to be expanded to a
46 # full .config first. We use 'make oldconfig' because this can be safely
47 # done even when the package does not support defconfigs.
48 $$($(2)_DIR)/.config: $$($(2)_KCONFIG_FILE)
49 $$(INSTALL) -m 0644 $$($(2)_KCONFIG_FILE) $$($(2)_DIR)/.config
50 @yes "" | $$($(2)_MAKE_ENV) $$(MAKE) -C $$($(2)_DIR) \
51 $$($(2)_KCONFIG_OPTS) oldconfig
53 # In order to get a usable, consistent configuration, some fixup may be needed.
54 # The exact rules are specified by the package .mk file.
55 $$($(2)_DIR)/.stamp_kconfig_fixup_done: $$($(2)_DIR)/.config
56 $$($(2)_KCONFIG_FIXUP_CMDS)
57 @yes "" | $$($(2)_MAKE_ENV) $$(MAKE) -C $$($(2)_DIR) \
58 $$($(2)_KCONFIG_OPTS) oldconfig
61 # Before running configure, the configuration file should be present and fixed
62 $$($(2)_TARGET_CONFIGURE): $$($(2)_DIR)/.stamp_kconfig_fixup_done
64 # Only enable the foo-*config targets when the package is actually enabled.
65 # Note: the variable $(2)_KCONFIG_VAR is not related to the kconfig
66 # infrastructure, but defined by pkg-generic.mk. The generic infrastructure is
67 # already called above, so we can effectively use this variable.
68 ifeq ($$($$($(2)_KCONFIG_VAR)),y)
70 # FOO_KCONFIG_FILE is required
71 ifndef $(2)_KCONFIG_FILE
72 $$(error Internal error: no value specified for $(2)_KCONFIG_FILE)
75 # Configuration editors (menuconfig, ...)
76 $$(addprefix $(1)-,$$($(2)_KCONFIG_EDITORS)): $$($(2)_DIR)/.stamp_kconfig_fixup_done
77 $$($(2)_MAKE_ENV) $$(MAKE) -C $$($(2)_DIR) \
78 $$($(2)_KCONFIG_OPTS) $$(subst $(1)-,,$$@)
79 rm -f $$($(2)_DIR)/.stamp_{kconfig_fixup_done,configured,built}
80 rm -f $$($(2)_DIR)/.stamp_{target,staging,images}_installed
82 $(1)-savedefconfig: $$($(2)_DIR)/.stamp_kconfig_fixup_done
83 $$($(2)_MAKE_ENV) $$(MAKE) -C $$($(2)_DIR) \
84 $$($(2)_KCONFIG_OPTS) savedefconfig
86 # Target to copy back the configuration to the source configuration file
87 # Even though we could use 'cp --preserve-timestamps' here, the separate
88 # cp and 'touch --reference' is used for symmetry with $(1)-update-defconfig.
89 $(1)-update-config: $$($(2)_DIR)/.stamp_kconfig_fixup_done
90 cp -f $$($(2)_DIR)/.config $$($(2)_KCONFIG_FILE)
91 touch --reference $$($(2)_DIR)/.config $$($(2)_KCONFIG_FILE)
93 # Note: make sure the timestamp of the stored configuration is not newer than
94 # the .config to avoid a useless rebuild. Note that, contrary to
95 # $(1)-update-config, the reference for 'touch' is _not_ the file from which
97 $(1)-update-defconfig: $(1)-savedefconfig
98 cp -f $$($(2)_DIR)/defconfig $$($(2)_KCONFIG_FILE)
99 touch --reference $$($(2)_DIR)/.config $$($(2)_KCONFIG_FILE)
101 endif # package enabled
105 $(1)-update-defconfig \
107 $$(addprefix $(1)-,$$($(2)_KCONFIG_EDITORS))
109 endef # inner-kconfig-package
111 ################################################################################
112 # kconfig-package -- the target generator macro for kconfig packages
113 ################################################################################
115 kconfig-package = $(call inner-kconfig-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)