Commit ecbed4b2 authored by Anton Midyukov's avatar Anton Midyukov

image.in/functions.mk: protect the code from spontaneous execution

The new make-4.4 does not reset '$(1)', '$(2)', etc. when do recursively expanding. So the functions fire spontaneously. The reason for recursive expanding might be to use $(shell ...). To protect the code from spontaneous execution, we add a match check '$(0)' to the function name. The '$(0)' variable must always have the name of our function at the time of the call. If this is not the case, then we are out of the $(call ...) context. From make documentation: | The syntax of the 'call' function is: | | $(call VARIABLE,PARAM,PARAM,...) | | When 'make' expands this function, it assigns each PARAM to temporary | variables '$(1)', '$(2)', etc. The variable '$(0)' will contain | VARIABLE. Fix ALT bug 44561 See also: https://github.com/osboot/make-initrd/commit/60afcd997affe150fe1153006ffcc1adac735710
parent 88622c4d
......@@ -12,28 +12,46 @@ ARCH ?= $(shell arch | sed 's/i686/i586/; s/armv.*/arm/')
DATE ?= $(shell date +%Y%m%d)
# prefix pkglist name with its directory to form a path (relative/absolute)
rlist = $(1:%=lists/%)
list = $(addprefix $(PKGDIR)/,$(call rlist,$(1)))
define rlist
$(if $(filter rlist,$(0)),$(1:%=lists/%))
endef
define list
$(if $(filter list,$(0)),$(addprefix $(PKGDIR)/,$(call rlist,$(1))))
endef
# prefix/suffix group name to form a path (relative/absolute)
rgroup = $(1:%=groups/%.directory)
group = $(addprefix $(PKGDIR)/,$(call rgroup,$(1)))
define rgroup
$(if $(filter rgroup,$(0)),$(1:%=groups/%.directory))
endef
define group
$(if $(filter group,$(0)),$(addprefix $(PKGDIR)/,$(call rgroup,$(1))))
endef
# prefix/suffix pkg profile name to form a path (relative/absolute)
rprofile = $(1:%=profiles/%.directory)
profile = $(addprefix $(PKGDIR)/,$(call rprofile,$(1)))
define rprofile
$(if $(filter rprofile,$(0)),$(1:%=profiles/%.directory))
endef
define profile
$(if $(filter profile,$(0)),$(addprefix $(PKGDIR)/,$(call rprofile,$(1))))
endef
# map first argument (a function) onto second one (an argument list)
map = $(foreach a,$(2),$(call $(1),$(a)))
define map
$(if $(filter map,$(0)),$(foreach a,$(2),$(call $(1),$(a))))
endef
# happens at least twice, and variables are the same by design
groups2lists = $(shell $(groups2lists_body))
define groups2lists_body
{ if [ -n "$(THE_GROUPS)$(MAIN_GROUPS)" ]; then \
sed -rn 's,^X-Alterator-PackageList=(.*)$$,\1,p' \
$(call map,group,$(THE_GROUPS) $(MAIN_GROUPS)) | \
sed 's/;/\n/g'; \
fi; }
define groups2lists
$(if $(filter groups2lists,$(0)),$(shell \
if [ -n "$(THE_GROUPS)$(MAIN_GROUPS)" ]; then \
sed -rn 's,^X-Alterator-PackageList=(.*)$$,\1,p' \
$(call map,group,$(THE_GROUPS) $(MAIN_GROUPS)) | \
sed 's/;/\n/g'; \
fi; \
))
endef
# kernel package list generation; see also #24669
......@@ -41,15 +59,21 @@ NULL :=
SPACE := $(NULL) # the officially documented way of getting a space
COMMA := ,
list2re = $(subst $(SPACE),|,$(strip $(1)))
define list2re
$(if $(filter list2re,$(0)),$(subst $(SPACE),|,$(strip $(1))))
endef
# args: KFLAVOURS, KMODULES
# NB: $(2) could be empty
kpackages = $(and $(1), \
^kernel-(image|modules-($(call list2re,$(2))))-($(call list2re,$(1)))$$)
define kpackages
$(if $(filter kpackages,$(0)),$(and $(1), \
^kernel-(image|modules-($(call list2re,$(2))))-($(call list2re,$(1)))$$))
endef
# arg: branding subpackages
branding = $(and $(1),^branding-$(BRANDING)-($(call list2re,$(1)))$$)
define branding
$(if $(filter branding,$(0)),$(and $(1),^branding-$(BRANDING)-($(call list2re,$(1)))$$))
endef
endif
endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment