diff options
author | Martin Roth <gaumless@gmail.com> | 2015-07-03 12:54:14 -0600 |
---|---|---|
committer | Martin Roth <gaumless@gmail.com> | 2015-07-11 22:11:29 +0200 |
commit | 47abc54ec3eea1a660cfbe3bb935ef6d3ace9de0 (patch) | |
tree | ead8ca7672039495e666c3a8842d23789dd4a0fe | |
parent | 8cce701b56d8c6f780a3d77639dc3328acfacfbe (diff) | |
download | coreboot-47abc54ec3eea1a660cfbe3bb935ef6d3ace9de0.tar.xz |
Makefile.inc: Add math macros
Add macros to standardize math done in the Makefiles in a posix
compliant manner.
int-multiply takes an arbitrary list of values to multiply, the same as
the int-addition macro.
The other macros only work on two values at a time.
Change-Id: I3b754b9bcde26f33edc4f945d5af3d5444f383c7
Signed-off-by: Martin Roth <gaumless@gmail.com>
Reviewed-on: http://review.coreboot.org/10874
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
-rw-r--r-- | Makefile.inc | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/Makefile.inc b/Makefile.inc index dbd5229259..3995fbc1d8 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -72,15 +72,31 @@ $(foreach supported_arch,$(ARCH_SUPPORTED), \ $(eval $(call define_class,rmodules_$(supported_arch),$(supported_arch)))) ####################################################################### -# Helper functions for various file placement matters +# Helper functions for math and various file placement matters. +# macros work on all formats understood by printf(1) +# values are space separated if using more than one value # -# int-add: adds an arbitrary number of space-separated integers in -# all formats understood by printf(1) -# int-align: align $1 to $2 units -# file-size: returns the filesize of the given file +# int-add: adds an arbitrary length list of integers +# int-subtract: subtracts the the second of two integers from the first +# int-multiply: multiplies an arbitrary length list of integers +# int-divide: divides the first integer by the second +# int-remainder: arithmetic remainder of the first number divided by the second +# int-lt: 1 if the first value is less than the second. 0 otherwise +# int-gt: 1 if the first values is greater than the second. 0 otherwise +# int-eq: 1 if the two values are equal. 0 otherwise +# int-align: align $1 to $2 units +# file-size: returns the filesize of the given file _toint=$(shell printf "%d" $1) _int-add2=$(shell expr $(call _toint,$1) + $(call _toint,$2)) int-add=$(if $(filter 1,$(words $1)),$(strip $1),$(call int-add,$(call _int-add2,$(word 1,$1),$(word 2,$1)) $(wordlist 3,$(words $1),$1))) +int-subtract=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) - $(call _toint,$(word 2,$1)))) +_int-multiply2=$(shell expr $(call _toint,$1) \* $(call _toint,$2)) +int-multiply=$(if $(filter 1,$(words $1)),$(strip $1),$(call int-multiply,$(call _int-multiply2,$(word 1,$1),$(word 2,$1)) $(wordlist 3,$(words $1),$1))) +int-divide=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) / $(call _toint,$(word 2,$1)))) +int-remainder=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) % $(call _toint,$(word 2,$1)))) +int-lt=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) \< $(call _toint,$(word 2,$1)))) +int-gt=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) \> $(call _toint,$(word 2,$1)))) +int-eq=$(if $(filter 1,$(words $1)),$(strip $1),$(shell expr $(call _toint,$(word 1,$1)) = $(call _toint,$(word 2,$1)))) int-align=$(shell A=$(call _toint,$1) B=$(call _toint,$2); expr $$A + \( \( $$B - \( $$A % $$B \) \) % $$B \) ) file-size=$(shell cat $1 | wc -c) |