prplos/include/overlay-feed/helpers.mk
Nikolai Merinov 469e1eb8a8 BuildSystem: Provide Overlay Feeds base infrastructure implementation
Problem: OpenWRT Build system provide no way to extend package from 3rd party feed.
As a result in order to manage CVE patches or small modification to a single package
we should make copy of package in feeds that we own and monitor any changes in the
package original feed to not miss upstream updates.

Solution: Include all $(PKG_DIR_NAME)/Makefile.append files as part of first
$(eval $(call BuildPackage,packagename)) call in original $(PKG_DIR_NAME)/Makefile.
Add append directories to PKG_FILE_DEPENDS in order to invalidate build when
append files changed.
Together with this change provide several useful functions and variables:

Variable $(THISDIR) -- defined in context of Makefile.append files to and points to
the directory where Makefile.append recipe. Can be used to find additional patches,
config fragments, etc.

Variable $(OVERLAY_PATCHES) -- can be used to provide additional patch files for package
sources in the following manner:

    OVERLAY_PATCHES := $(OVERLAY_PATCHES) $(THISDIR)/patches/filename.patch
    OVERLAY_PATCHES := $(OVERLAY_PATCHES) $(wildcard $(THISDIR)/patches/*.patch)

Variable $(newline) -- contains single "\n" symbol. Required to append/prepend
OpenWRT multiline variables with additional line.

Functions (append,VARNAME,value[,override]) -- used to append "value" string to variable VARNAME.
Behave like "+=" with two exceptions:
 1. Append "value" without extra space before the value
 2. The "value" expanded immediately before the assignment, while VARNAME is treated
    as recursive expand variable. Such behavior allow you to use $(THISDIR) variable
    together with "append" function. For example the following call will expand
    $(THISDIR) immediately:

    $(call append,Package/helloworld/config,$(newline)source "$(THISDIR)/Config.in")

Function (prepend,VARNAME,value[,override]) -- used to prepend "value" string to variable VARNAME.
Shares "append" function behavior regards expansion time. In order to append string
with delayed expansion time you can replace $(...) with $$(...). For exaple the
following call will delay $(Build/IncludeOverlay) expansion:

    $(call prepend,BuildPackage,$$(Build/IncludeOverlay)$(newline))

Function (remove,VARNAME,value[,override]) -- behave like "filter-out" function, but allow to
control expansion time of the passed "value".

Function (rewrite,VARNAME,value[,override]) -- generalized function that allow arbitrary change
of VARNAME variable value controlling "value" expansion time.

All this functions support optional last argument that allow to modify "override VARNAME" instead
of non-override version of VARNAME.

References: PCF-1615
Signed-off-by: Ivan Efimov <i.efimov@inango-systems.com>
Signed-off-by: Nicolai Scurtu <n.scurtu@inango-systems.com>
Signed-off-by: Vadym Omelchuk <v.omelchuk@inango-systems.com>
Signed-off-by: Vladimir Shulika <v.shulika@inango-systems.com>
Signed-off-by: Nikolai Merinov <n.merinov@inango-systems.com>
2025-09-15 13:46:17 +03:00

23 lines
292 B
Makefile

define rewrite
$(eval $(3) define $(1)
$(2)
endef)
endef
define prepend
$(call rewrite,$(1),$(2)$(value $(1)),$(3))
endef
define append
$(call rewrite,$(1),$(value $(1))$(2),$(3))
endef
define remove
$(call rewrite,$(1),$(filter-out $(2),$(value $(1))),$(3))
endef
define newline
endef