lua-iconv: new package
[buildroot-gz.git] / package / pkg-kconfig.mk
blobc86c3408398ca92e3af178db681d92be9afa951a
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
7 # features.
9 # See the Buildroot documentation for details on the usage of this
10 # infrastructure.
12 ################################################################################
14 ################################################################################
15 # inner-kconfig-package -- generates the make targets needed to support a
16 # kconfig package
18 # argument 1 is the lowercase package name
19 # argument 2 is the uppercase package name, including a HOST_ prefix
20 # for host packages
21 # argument 3 is the uppercase package name, without the HOST_ prefix
22 # for host packages
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
29 # make targets.
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))
34 # Default values
35 $(2)_KCONFIG_EDITORS ?= menuconfig
36 $(2)_KCONFIG_OPTS ?=
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)"; \
56 exit 1; \
57 fi; \
58 done
60 # The specified source configuration file and any additional configuration file
61 # fragments are merged together to .config, after the package has been patched.
62 # Since the file could be a defconfig file it needs to be expanded to a
63 # full .config first. We use 'make oldconfig' because this can be safely
64 # done even when the package does not support defconfigs.
65 $$($(2)_DIR)/.config: $$($(2)_KCONFIG_FILE) $$($(2)_KCONFIG_FRAGMENT_FILES)
66 support/kconfig/merge_config.sh -m -O $$(@D) \
67 $$($(2)_KCONFIG_FILE) $$($(2)_KCONFIG_FRAGMENT_FILES)
68 @yes "" | $$($(2)_MAKE_ENV) $$(MAKE) -C $$($(2)_DIR) \
69 $$($(2)_KCONFIG_OPTS) oldconfig
71 # In order to get a usable, consistent configuration, some fixup may be needed.
72 # The exact rules are specified by the package .mk file.
73 define $(2)_FIXUP_DOT_CONFIG
74 $$($(2)_KCONFIG_FIXUP_CMDS)
75 @yes "" | $$($(2)_MAKE_ENV) $$(MAKE) -C $$($(2)_DIR) \
76 $$($(2)_KCONFIG_OPTS) oldconfig
77 $$(Q)touch $$($(2)_DIR)/.stamp_kconfig_fixup_done
78 endef
80 $$($(2)_DIR)/.stamp_kconfig_fixup_done: $$($(2)_DIR)/.config
81 $$(call $(2)_FIXUP_DOT_CONFIG)
83 # Before running configure, the configuration file should be present and fixed
84 $$($(2)_TARGET_CONFIGURE): $$($(2)_DIR)/.stamp_kconfig_fixup_done
86 # Only enable the foo-*config targets when the package is actually enabled.
87 # Note: the variable $(2)_KCONFIG_VAR is not related to the kconfig
88 # infrastructure, but defined by pkg-generic.mk. The generic infrastructure is
89 # already called above, so we can effectively use this variable.
90 ifeq ($$($$($(2)_KCONFIG_VAR)),y)
92 # FOO_KCONFIG_FILE is required
93 ifeq ($$($(2)_KCONFIG_FILE),)
94 $$(error Internal error: no value specified for $(2)_KCONFIG_FILE)
95 endif
97 # Configuration editors (menuconfig, ...)
99 # We need to apply the configuration fixups right after a configuration
100 # editor exits, so that it is possible to save the configuration right
101 # after exiting an editor, and so the user always sees a .config file
102 # that is clean wrt. our requirements.
104 # Because commands in $(1)_FIXUP_KCONFIG are probably using $(@D), we
105 # fake it for the configurators (otherwise it is set to just '.', i.e.
106 # the current directory where make is run, which happens to be in
107 # $(TOPDIR), because the target of the rule is not an actual file, so
108 # does not have any path component).
110 $$(addprefix $(1)-,$$($(2)_KCONFIG_EDITORS)): @D=$$($(2)_DIR)
111 $$(addprefix $(1)-,$$($(2)_KCONFIG_EDITORS)): $$($(2)_DIR)/.stamp_kconfig_fixup_done
112 $$($(2)_MAKE_ENV) $$(MAKE) -C $$($(2)_DIR) \
113 $$($(2)_KCONFIG_OPTS) $$(subst $(1)-,,$$@)
114 rm -f $$($(2)_DIR)/.stamp_{kconfig_fixup_done,configured,built}
115 rm -f $$($(2)_DIR)/.stamp_{target,staging,images}_installed
116 $$(call $(2)_FIXUP_DOT_CONFIG)
118 # Saving back the configuration
120 # Ideally, that should directly depend on $$($(2)_DIR)/.stamp_kconfig_fixup_done,
121 # but that breaks the use-case in PR-8156 (from a clean tree):
122 # make menuconfig <- enable kernel, use an in-tree defconfig, save and exit
123 # make linux-menuconfig <- enable/disable whatever option, save and exit
124 # make menuconfig <- change to use a custom defconfig file, set a path, save and exit
125 # make linux-update-config <- should save to the new custom defconfig file
127 # Because of that use-case, saving the configuration can *not* directly
128 # depend on the stamp file, because it itself depends on the .config,
129 # which in turn depends on the (newly-set an non-existent) custom
130 # defconfig file.
132 # Instead, we use an PHONY rule that will catch that situation.
134 $(1)-check-configuration-done:
135 @if [ ! -f $$($(2)_DIR)/.stamp_kconfig_fixup_done ]; then \
136 echo "$(1) is not yet configured"; \
137 exit 1; \
140 $(1)-savedefconfig: $(1)-check-configuration-done
141 $$($(2)_MAKE_ENV) $$(MAKE) -C $$($(2)_DIR) \
142 $$($(2)_KCONFIG_OPTS) savedefconfig
144 # Target to copy back the configuration to the source configuration file
145 # Even though we could use 'cp --preserve-timestamps' here, the separate
146 # cp and 'touch --reference' is used for symmetry with $(1)-update-defconfig.
147 $(1)-update-config: $(1)-check-configuration-done
148 @$$(if $$($(2)_KCONFIG_FRAGMENT_FILES), \
149 echo "Unable to perform $(1)-update-config when fragment files are set"; exit 1)
150 cp -f $$($(2)_DIR)/.config $$($(2)_KCONFIG_FILE)
151 touch --reference $$($(2)_DIR)/.config $$($(2)_KCONFIG_FILE)
153 # Note: make sure the timestamp of the stored configuration is not newer than
154 # the .config to avoid a useless rebuild. Note that, contrary to
155 # $(1)-update-config, the reference for 'touch' is _not_ the file from which
156 # we copy.
157 $(1)-update-defconfig: $(1)-savedefconfig
158 @$$(if $$($(2)_KCONFIG_FRAGMENT_FILES), \
159 echo "Unable to perform $(1)-update-defconfig when fragment files are set"; exit 1)
160 cp -f $$($(2)_DIR)/defconfig $$($(2)_KCONFIG_FILE)
161 touch --reference $$($(2)_DIR)/.config $$($(2)_KCONFIG_FILE)
163 endif # package enabled
165 .PHONY: \
166 $(1)-update-config \
167 $(1)-update-defconfig \
168 $(1)-savedefconfig \
169 $(1)-check-configuration-done \
170 $$(addprefix $(1)-,$$($(2)_KCONFIG_EDITORS))
172 endef # inner-kconfig-package
174 ################################################################################
175 # kconfig-package -- the target generator macro for kconfig packages
176 ################################################################################
178 kconfig-package = $(call inner-kconfig-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)