aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorTony Ambardar <itugrok@yahoo.com>2023-11-11 04:29:26 -0800
committerHauke Mehrtens <hauke@hauke-m.de>2023-11-26 18:37:20 +0100
commitb16e14a220fcab19e3145328057e7188f00b6a17 (patch)
tree7412f17f418fa7c01575843d11563790242e4742 /include
parentc66511bc488c3665d47dd60baf981ca1c385c221 (diff)
downloadupstream-b16e14a220fcab19e3145328057e7188f00b6a17.tar.gz
upstream-b16e14a220fcab19e3145328057e7188f00b6a17.tar.bz2
upstream-b16e14a220fcab19e3145328057e7188f00b6a17.zip
image: use helper function for size units
Add the make function 'exp_units' for helping evaluate k/m/g size units in expressions, and use this to consistently replace many ad hoc substitutions like '$(subst k,* 1024,$(subst m, * 1024k,$(IMAGE_SIZE)))' in makefiles. Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
Diffstat (limited to 'include')
-rw-r--r--include/image-commands.mk8
-rw-r--r--include/image.mk2
2 files changed, 6 insertions, 4 deletions
diff --git a/include/image-commands.mk b/include/image-commands.mk
index d07c8827619..0f292d15ee3 100644
--- a/include/image-commands.mk
+++ b/include/image-commands.mk
@@ -215,7 +215,7 @@ endef
define Build/check-size
@imagesize="$$(stat -c%s $@)"; \
- limitsize="$$(($(subst k,* 1024,$(subst m, * 1024k,$(if $(1),$(1),$(IMAGE_SIZE))))))"; \
+ limitsize="$$(($(call exp_units,$(if $(1),$(1),$(IMAGE_SIZE)))))"; \
[ $$limitsize -ge $$imagesize ] || { \
$(call ERROR_MESSAGE, WARNING: Image file $@ is too big: $$imagesize > $$limitsize); \
rm -f $@; \
@@ -466,8 +466,8 @@ endef
define Build/pad-offset
let \
size="$$(stat -c%s $@)" \
- pad="$(subst k,* 1024,$(word 1, $(1)))" \
- offset="$(subst k,* 1024,$(word 2, $(1)))" \
+ pad="$(call exp_units,$(word 1, $(1)))" \
+ offset="$(call exp_units,$(word 2, $(1)))" \
pad="(pad - ((size + offset) % pad)) % pad" \
newsize='size + pad'; \
dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
@@ -629,7 +629,7 @@ endef
define Build/zyxel-ras-image
let \
- newsize="$(subst k,* 1024,$(RAS_ROOTFS_SIZE))"; \
+ newsize="$(call exp_units,$(RAS_ROOTFS_SIZE))"; \
$(STAGING_DIR_HOST)/bin/mkrasimage \
-b $(RAS_BOARD) \
-v $(RAS_VERSION) \
diff --git a/include/image.mk b/include/image.mk
index 4ebff2e9ae0..ef52337deea 100644
--- a/include/image.mk
+++ b/include/image.mk
@@ -20,6 +20,8 @@ include $(INCLUDE_DIR)/rootfs.mk
override MAKE:=$(_SINGLE)$(SUBMAKE)
override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE)
+exp_units = $(subst k, * 1024,$(subst m, * 1024k,$(subst g, * 1024m,$(1))))
+
target_params = $(subst +,$(space),$*)
param_get = $(patsubst $(1)=%,%,$(filter $(1)=%,$(2)))
param_get_default = $(firstword $(call param_get,$(1),$(2)) $(3))