[PATCH v2] image: fix device profile specific COMPILE targets
Michael Pratt
mcpratt at pm.me
Wed Dec 7 06:13:22 PST 2022
Commit a01d23e75 ("image: always rebuild kernel loaders")
is a step in the right direction, but exposed some issues
and regressions in the makefile.
1. Some of the files made by device specific COMPILE targets
start with an "append" command (i.e. >> instead of > redirection)
and if the file already exists, the target file is an
input to itself before the first recipe input to the file.
2. Some of the device specific COMPILE targets,
like the lzma-loader have multiple steps
and the uImage target requires the bin or ELF target first,
so the two COMPILE targets cannot be run in parallel.
3. A side-effect of FORCE, is that all COMPILE targets
will be built, even for devices in a build that are not selected,
causing for example, the lzma-loader for some devices
to be built when the image for that device is not built.
4. By making the COMPILE targets a prerequisite of
the "target/compile" phase of the build, it is being built
again in the "target/install" phase of the build, since
the compile phase is a prerequisite of the install phase
and the FORCE target is used on each file in each submake,
but COMPILE targets are not needed before "target/install".
This commit resolves these issues by calling COMPILE targets
only in "target/install", using pattern substitution to list
prerequisites between COMPILE targets in order, deleting
the target before building it, and using device profile
selection to determine if the COMPILE targets are FORCE built.
Because of the nature of defining prerequisites in Make,
(reverse dependency before dependency)
the entire list of COMPILE targets is reversed
in order to list prerequisites between them
without having to work with individual words.
Fixes: a01d23e75 ("image: always rebuild kernel loaders")
Fixes: a7fb589e8 ("image: always rebuild kernel loaders")
Signed-off-by: Michael Pratt <mcpratt at pm.me>
---
include/image.mk | 8 ++++++--
rules.mk | 2 ++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/include/image.mk b/include/image.mk
index e9dc53f82e..c09dba3f2c 100644
--- a/include/image.mk
+++ b/include/image.mk
@@ -517,9 +517,13 @@ endef
endif
define Device/Build/compile
- $$(_COMPILE_TARGET): $(KDIR)/$(1)
+ $$(_TARGET): $(KDIR)/$(1)
$(eval $(call Device/Export,$(KDIR)/$(1)))
- $(KDIR)/$(1): FORCE
+
+ $(patsubst %$(1),%$(1):,$(call reverse,$(foreach compile,$(COMPILE),$(KDIR)/$(compile))))
+
+ $(KDIR)/$(1): $(if $(_PROFILE_SET),FORCE)
+ rm -f $(KDIR)/$(1)
$$(call concat_cmd,$(COMPILE/$(1)))
endef
diff --git a/rules.mk b/rules.mk
index 2de43d490d..782f84d625 100644
--- a/rules.mk
+++ b/rules.mk
@@ -53,6 +53,8 @@ __tr_template = $(__tr_head)$$(1)$(__tr_tail)
$(eval toupper = $(call __tr_template,$(chars_lower),$(chars_upper)))
$(eval tolower = $(call __tr_template,$(chars_upper),$(chars_lower)))
+reverse = $(if $(word 2,$(1)),$(call reverse,$(wordlist 2,$(words $(1)),$(1))) $(firstword $(1)),$(1))
+
version_abbrev = $(if $(if $(CHECK),,$(DUMP)),$(1),$(shell printf '%.8s' $(1)))
_SINGLE=export MAKEFLAGS=$(space);
--
2.30.2
More information about the openwrt-devel
mailing list