sngrep: fix error if gnutls and openssl are both enabled
[buildroot-gz.git] / package / pkg-kconfig.mk
blob215f01b430627b38bbf450fa691f47f306f18dfe
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 ?=
39 $(2)_KCONFIG_DOTCONFIG ?= .config
41 # The config file as well as the fragments could be in-tree, so before
42 # depending on them the package should be extracted (and patched) first.
44 # Since those files only have a order-only dependency, make would treat
45 # any missing one as a "force" target:
46 # https://www.gnu.org/software/make/manual/make.html#Force-Targets
47 # and would forcibly any rule that depend on those files, causing a
48 # rebuild of the kernel each time make is called.
50 # So, we provide a recipe that checks all of those files exist, to
51 # overcome that standard make behaviour.
53 $$($(2)_KCONFIG_FILE) $$($(2)_KCONFIG_FRAGMENT_FILES): | $(1)-patch
54 for f in $$($(2)_KCONFIG_FILE) $$($(2)_KCONFIG_FRAGMENT_FILES); do \
55 if [ ! -f "$$$${f}" ]; then \
56 printf "Kconfig fragment '%s' for '%s' does not exist\n" "$$$${f}" "$(1)"; \
57 exit 1; \
58 fi; \
59 done
61 $(2)_KCONFIG_MAKE = \
62 $$($(2)_MAKE_ENV) $$(MAKE) -C $$($(2)_DIR) $$($(2)_KCONFIG_OPTS)
64 # $(2)_KCONFIG_MAKE may already rely on shell expansion. As the $() syntax
65 # of the shell conflicts with Make's own syntax, this means that backticks
66 # are used with those shell constructs. Unfortunately, the backtick syntax
67 # does not nest, and we need to use Make instead of the shell to handle
68 # conditions.
70 # A recursively expanded variable is necessary, to be sure that the shell
71 # command is called when the rule is processed during the build and not
72 # when the rule is created when parsing all packages.
73 $(2)_KCONFIG_RULES = \
74 $$(shell $$($(2)_KCONFIG_MAKE) -pn config 2>/dev/null | \
75 sed 's/^\([_0-9a-zA-Z]*config\):.*/\1/ p; d')
77 # The correct way to regenerate a .config file is to use 'make olddefconfig'.
78 # For historical reasons, the target name is 'oldnoconfig' between Linux kernel
79 # versions 2.6.36 and 3.6, and remains as an alias in later versions.
80 # In older versions, and in some other projects that use kconfig, the target is
81 # not supported at all, and we use 'yes "" | make oldconfig' as a fallback
82 # only, as this can fail in complex cases.
83 define $(2)_REGEN_DOT_CONFIG
84 $$(if $$(filter olddefconfig,$$($(2)_KCONFIG_RULES)),
85 $$(Q)$$($(2)_KCONFIG_MAKE) olddefconfig,
86 $$(if $$(filter oldnoconfig,$$($(2)_KCONFIG_RULES)),
87 $$(Q)$$($(2)_KCONFIG_MAKE) oldnoconfig,
88 $$(Q)(yes "" | $$($(2)_KCONFIG_MAKE) oldconfig)))
89 endef
91 # The specified source configuration file and any additional configuration file
92 # fragments are merged together to .config, after the package has been patched.
93 # Since the file could be a defconfig file it needs to be expanded to a
94 # full .config first.
95 $$($(2)_DIR)/$$($(2)_KCONFIG_DOTCONFIG): $$($(2)_KCONFIG_FILE) $$($(2)_KCONFIG_FRAGMENT_FILES)
96 $$(Q)$$(if $$($(2)_KCONFIG_DEFCONFIG), \
97 $$($(2)_KCONFIG_MAKE) $$($(2)_KCONFIG_DEFCONFIG), \
98 $$(INSTALL) -m 0644 -D $$($(2)_KCONFIG_FILE) $$(@))
99 $$(Q)support/kconfig/merge_config.sh -m -O $$(@D) \
100 $$(@) $$($(2)_KCONFIG_FRAGMENT_FILES)
101 $$($(2)_REGEN_DOT_CONFIG)
103 # If _KCONFIG_FILE or _KCONFIG_FRAGMENT_FILES exists, this dependency is
104 # already implied, but if we only have a _KCONFIG_DEFCONFIG we have to add
105 # it explicitly. It doesn't hurt to always have it though.
106 $$($(2)_DIR)/$$($(2)_KCONFIG_DOTCONFIG): | $(1)-patch
108 # In order to get a usable, consistent configuration, some fixup may be needed.
109 # The exact rules are specified by the package .mk file.
110 define $(2)_FIXUP_DOT_CONFIG
111 $$($(2)_KCONFIG_FIXUP_CMDS)
112 $$($(2)_REGEN_DOT_CONFIG)
113 $$(Q)touch $$($(2)_DIR)/.stamp_kconfig_fixup_done
114 endef
116 $$($(2)_DIR)/.stamp_kconfig_fixup_done: $$($(2)_DIR)/$$($(2)_KCONFIG_DOTCONFIG)
117 $$($(2)_FIXUP_DOT_CONFIG)
119 # Before running configure, the configuration file should be present and fixed
120 $$($(2)_TARGET_CONFIGURE): $$($(2)_DIR)/.stamp_kconfig_fixup_done
122 # Force olddefconfig again on -reconfigure
123 $(1)-clean-for-reconfigure: $(1)-clean-kconfig-for-reconfigure
125 $(1)-clean-kconfig-for-reconfigure:
126 rm -f $$($(2)_DIR)/.stamp_kconfig_fixup_done
128 # Only enable the foo-*config targets when the package is actually enabled.
129 # Note: the variable $(2)_KCONFIG_VAR is not related to the kconfig
130 # infrastructure, but defined by pkg-generic.mk. The generic infrastructure is
131 # already called above, so we can effectively use this variable.
132 ifeq ($$($$($(2)_KCONFIG_VAR)),y)
134 ifeq ($$(BR_BUILDING),y)
135 # Either FOO_KCONFIG_FILE or FOO_KCONFIG_DEFCONFIG is required...
136 ifeq ($$(or $$($(2)_KCONFIG_FILE),$$($(2)_KCONFIG_DEFCONFIG)),)
137 $$(error Internal error: no value specified for $(2)_KCONFIG_FILE or $(2)_KCONFIG_DEFCONFIG)
138 endif
139 # ... but not both:
140 ifneq ($$(and $$($(2)_KCONFIG_FILE),$$($(2)_KCONFIG_DEFCONFIG)),)
141 $$(error Internal error: $(2)_KCONFIG_FILE and $(2)_KCONFIG_DEFCONFIG are mutually exclusive but both are defined)
142 endif
143 endif
145 # For the configurators, we do want to use the system-provided host
146 # tools, not the ones we build. This is particularly true for
147 # pkg-config; if we use our pkg-config (from host-pkgconf), then it
148 # would not look for the .pc from the host, but we do need them,
149 # especially to find ncurses, GTK+, Qt (resp. for menuconfig and
150 # nconfig, gconfig, xconfig).
151 # So we simply remove our PATH and PKG_CONFIG_* variables.
152 $(2)_CONFIGURATOR_MAKE_ENV = \
153 $$(filter-out PATH=% PKG_CONFIG=% PKG_CONFIG_SYSROOT_DIR=% PKG_CONFIG_LIBDIR=%,$$($(2)_MAKE_ENV)) \
154 PKG_CONFIG_PATH="$(HOST_PKG_CONFIG_PATH)"
156 # Configuration editors (menuconfig, ...)
158 # We need to apply the configuration fixups right after a configuration
159 # editor exits, so that it is possible to save the configuration right
160 # after exiting an editor, and so the user always sees a .config file
161 # that is clean wrt. our requirements.
163 # Because commands in $(1)_FIXUP_KCONFIG are probably using $(@D), we
164 # need to have a valid @D set. But, because the configurators rules are
165 # not real files and do not contain the path to the package build dir,
166 # @D would be just '.' in this case. So, we use an intermediate rule
167 # with a stamp-like file which path is in the package build dir, so we
168 # end up having a valid @D.
170 $$(addprefix $(1)-,$$($(2)_KCONFIG_EDITORS)): $(1)-%: $$($(2)_DIR)/.kconfig_editor_%
171 $$($(2)_DIR)/.kconfig_editor_%: $$($(2)_DIR)/.stamp_kconfig_fixup_done
172 $$($(2)_CONFIGURATOR_MAKE_ENV) $$(MAKE) -C $$($(2)_DIR) \
173 $$($(2)_KCONFIG_OPTS) $$(*)
174 rm -f $$($(2)_DIR)/.stamp_{kconfig_fixup_done,configured,built}
175 rm -f $$($(2)_DIR)/.stamp_{target,staging,images}_installed
176 $$($(2)_FIXUP_DOT_CONFIG)
178 # Saving back the configuration
180 # Ideally, that should directly depend on $$($(2)_DIR)/.stamp_kconfig_fixup_done,
181 # but that breaks the use-case in PR-8156 (from a clean tree):
182 # make menuconfig <- enable kernel, use an in-tree defconfig, save and exit
183 # make linux-menuconfig <- enable/disable whatever option, save and exit
184 # make menuconfig <- change to use a custom defconfig file, set a path, save and exit
185 # make linux-update-config <- should save to the new custom defconfig file
187 # Because of that use-case, saving the configuration can *not* directly
188 # depend on the stamp file, because it itself depends on the .config,
189 # which in turn depends on the (newly-set an non-existent) custom
190 # defconfig file.
192 # Instead, we use an PHONY rule that will catch that situation.
194 $(1)-check-configuration-done:
195 @if [ ! -f $$($(2)_DIR)/.stamp_kconfig_fixup_done ]; then \
196 echo "$(1) is not yet configured"; \
197 exit 1; \
200 $(1)-savedefconfig: $(1)-check-configuration-done
201 $$($(2)_MAKE_ENV) $$(MAKE) -C $$($(2)_DIR) \
202 $$($(2)_KCONFIG_OPTS) savedefconfig
204 # Target to copy back the configuration to the source configuration file
205 # Even though we could use 'cp --preserve-timestamps' here, the separate
206 # cp and 'touch --reference' is used for symmetry with $(1)-update-defconfig.
207 $(1)-update-config: $(1)-check-configuration-done
208 @$$(if $$($(2)_KCONFIG_FRAGMENT_FILES), \
209 echo "Unable to perform $(1)-update-config when fragment files are set"; exit 1)
210 @$$(if $$($(2)_KCONFIG_DEFCONFIG), \
211 echo "Unable to perform $(1)-update-config when using a defconfig rule"; exit 1)
212 cp -f $$($(2)_DIR)/$$($(2)_KCONFIG_DOTCONFIG) $$($(2)_KCONFIG_FILE)
213 touch --reference $$($(2)_DIR)/$$($(2)_KCONFIG_DOTCONFIG) $$($(2)_KCONFIG_FILE)
215 # Note: make sure the timestamp of the stored configuration is not newer than
216 # the .config to avoid a useless rebuild. Note that, contrary to
217 # $(1)-update-config, the reference for 'touch' is _not_ the file from which
218 # we copy.
219 $(1)-update-defconfig: $(1)-savedefconfig
220 @$$(if $$($(2)_KCONFIG_FRAGMENT_FILES), \
221 echo "Unable to perform $(1)-update-defconfig when fragment files are set"; exit 1)
222 @$$(if $$($(2)_KCONFIG_DEFCONFIG), \
223 echo "Unable to perform $(1)-update-defconfig when using a defconfig rule"; exit 1)
224 cp -f $$($(2)_DIR)/defconfig $$($(2)_KCONFIG_FILE)
225 touch --reference $$($(2)_DIR)/$$($(2)_KCONFIG_DOTCONFIG) $$($(2)_KCONFIG_FILE)
227 endif # package enabled
229 .PHONY: \
230 $(1)-update-config \
231 $(1)-update-defconfig \
232 $(1)-savedefconfig \
233 $(1)-check-configuration-done \
234 $$($(2)_DIR)/.kconfig_editor_% \
235 $$(addprefix $(1)-,$$($(2)_KCONFIG_EDITORS))
237 endef # inner-kconfig-package
239 ################################################################################
240 # kconfig-package -- the target generator macro for kconfig packages
241 ################################################################################
243 kconfig-package = $(call inner-kconfig-package,$(pkgname),$(call UPPERCASE,$(pkgname)),$(call UPPERCASE,$(pkgname)),target)