From 83a4e8c552ecceb190e2805eac8dd7a6b520e30a Mon Sep 17 00:00:00 2001 From: Alfred Neumayer Date: Thu, 15 Oct 2020 18:17:38 +0200 Subject: [PATCH] definitions.mk: Backport math functions/defines Used by some Sony components (macaddrsetup) to determine which init.rc to ship. Change-Id: I2db958a997e399237fc1d93120d4e6b1fa1fa4a3 --- core/definitions.mk | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/core/definitions.mk b/core/definitions.mk index bca474e732d..c7bd23a47e6 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -2893,6 +2893,43 @@ $(strip $(if $(filter $(TARGET_ARCH),$(1)),$(TARGET_ARCH),\ $(if $(filter $(TARGET_2ND_ARCH),$(1)),$(TARGET_2ND_ARCH),$(if $(1),none)))) endef +########################################################### +# Basic math functions for positive integers <= 100 +# +# (SDK versions for example) +########################################################### +__MATH_NUMBERS := 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \ + 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \ + 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \ + 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 \ + 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 +# Returns true if $(1) is a positive integer <= 100, otherwise returns nothing. +define math_is_number +$(strip \ + $(if $(1),,$(error Argument missing)) \ + $(if $(word 2,$(1)),$(error Multiple words in a single argument: $(1))) \ + $(if $(filter $(1),$(__MATH_NUMBERS)),true)) +endef + +define _math_check_valid +$(if $(call math_is_number,$(1)),,$(error Only positive integers <= 100 are supported (not $(1)))) +endef + +# Returns the greater of $1 or $2. +# If $1 or $2 is not a positive integer <= 100, then an error is generated. +define math_max +$(strip $(call _math_check_valid,$(1)) $(call _math_check_valid,$(2)) \ + $(lastword $(filter $(1) $(2),$(__MATH_NUMBERS)))) +endef + +define math_gt_or_eq +$(if $(filter $(1),$(call math_max,$(1),$(2))),true) +endef + +#$(warning $(call math_gt_or_eq, 2, 1)) +#$(warning $(call math_gt_or_eq, 1, 1)) +#$(warning $(if $(call math_gt_or_eq, 1, 2),false,true)) + ########################################################### ## Other includes ###########################################################