8361064e2bd26e2b6c3e21d5202f117297a83bab
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / pkg-kconfig.mk
1 ################################################################################
2 # Kconfig package infrastructure
3 #
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.
8 #
9 # See the Buildroot documentation for details on the usage of this
10 # infrastructure.
11 #
12 ################################################################################
13
14 ################################################################################
15 # inner-kconfig-package -- generates the make targets needed to support a
16 # kconfig package
17 #
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 ################################################################################
25
26 define inner-kconfig-package
27
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))
33
34 # Default values
35 $(2)_KCONFIG_EDITORS ?= menuconfig
36 $(2)_KCONFIG_OPTS ?=
37 $(2)_KCONFIG_FIXUP_CMDS ?=
38
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
42
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
52
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
59         $$(Q)touch $$@
60
61 # Before running configure, the configuration file should be present and fixed
62 $$($(2)_TARGET_CONFIGURE): $$($(2)_DIR)/.stamp_kconfig_fixup_done
63
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)
69
70 # FOO_KCONFIG_FILE is required
71 ifndef $(2)_KCONFIG_FILE
72 $$(error Internal error: no value specified for $(2)_KCONFIG_FILE)
73 endif
74
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
81
82 $(1)-savedefconfig: $$($(2)_DIR)/.stamp_kconfig_fixup_done
83         $$($(2)_MAKE_ENV) $$(MAKE) -C $$($(2)_DIR) \
84                 $$($(2)_KCONFIG_OPTS) savedefconfig
85
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)
92
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
96 # we copy.
97 $(1)-update-defconfig: $(1)-savedefconfig
98         cp -f $$($(2)_DIR)/defconfig $$($(2)_KCONFIG_FILE)
99         touch --reference $$($(2)_DIR)/.config $$($(2)_KCONFIG_FILE)
100
101 endif # package enabled
102
103 .PHONY: \
104         $(1)-update-config \
105         $(1)-update-defconfig \
106         $(1)-savedefconfig \
107         $$(addprefix $(1)-,$$($(2)_KCONFIG_EDITORS))
108
109 endef # inner-kconfig-package
110
111 ################################################################################
112 # kconfig-package -- the target generator macro for kconfig packages
113 ################################################################################
114
115 kconfig-package = $(call inner-kconfig-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)