Bharath | d27ca20 | 2022-10-05 09:11:30 +0530 | [diff] [blame] | 1 | # vars for use by utils |
| 2 | colon := $(empty):$(empty) |
| 3 | underscore := $(empty)_$(empty) |
| 4 | |
| 5 | # $(call match-word,w1,w2) |
| 6 | # checks if w1 == w2 |
| 7 | # How it works |
| 8 | # if (w1-w2 not empty or w2-w1 not empty) then not_match else match |
| 9 | # |
| 10 | # returns true or empty |
| 11 | #$(warning :$(1): :$(2): :$(subst $(1),,$(2)):) \ |
| 12 | #$(warning :$(2): :$(1): :$(subst $(2),,$(1)):) \ |
| 13 | # |
| 14 | define match-word |
| 15 | $(strip \ |
| 16 | $(if $(or $(subst $(1),$(empty),$(2)),$(subst $(2),$(empty),$(1))),,true) \ |
| 17 | ) |
| 18 | endef |
| 19 | |
| 20 | # $(call find-word-in-list,w,wlist) |
| 21 | # finds an exact match of word w in word list wlist |
| 22 | # |
| 23 | # How it works |
| 24 | # fill wlist spaces with colon |
| 25 | # wrap w with colon |
| 26 | # search word w in list wl, if found match m, return stripped word w |
| 27 | # |
| 28 | # returns stripped word or empty |
| 29 | define find-word-in-list |
| 30 | $(strip \ |
| 31 | $(eval wl:= $(colon)$(subst $(space),$(colon),$(strip $(2)))$(colon)) \ |
| 32 | $(eval w:= $(colon)$(strip $(1))$(colon)) \ |
| 33 | $(eval m:= $(findstring $(w),$(wl))) \ |
| 34 | $(if $(m),$(1),) \ |
| 35 | ) |
| 36 | endef |
| 37 | |
| 38 | # $(call match-word-in-list,w,wlist) |
| 39 | # does an exact match of word w in word list wlist |
| 40 | # How it works |
| 41 | # if the input word is not empty |
| 42 | # return output of an exact match of word w in wordlist wlist |
| 43 | # else |
| 44 | # return empty |
| 45 | # returns true or empty |
| 46 | define match-word-in-list |
| 47 | $(strip \ |
| 48 | $(if $(strip $(1)), \ |
| 49 | $(call match-word,$(call find-word-in-list,$(1),$(2)),$(strip $(1))), \ |
| 50 | ) \ |
| 51 | ) |
| 52 | endef |
| 53 | |
| 54 | # $(call match-prefix,p,delim,w/wlist) |
| 55 | # matches prefix p in wlist using delimiter delim |
| 56 | # |
| 57 | # How it works |
| 58 | # trim the words in wlist w |
| 59 | # if find-word-in-list returns not empty |
| 60 | # return true |
| 61 | # else |
| 62 | # return empty |
| 63 | # |
| 64 | define match-prefix |
| 65 | $(strip \ |
| 66 | $(eval w := $(strip $(1)$(strip $(2)))) \ |
| 67 | $(eval text := $(patsubst $(w)%,$(1),$(3))) \ |
| 68 | $(if $(call match-word-in-list,$(1),$(text)),true,) \ |
| 69 | ) |
| 70 | endef |
| 71 | |
| 72 | # ---- |
| 73 | # The following utilities are meant for board platform specific |
| 74 | # featurisation |
| 75 | |
| 76 | # $(call get-vendor-board-platforms,v) |
| 77 | # returns list of board platforms for vendor v |
| 78 | define get-vendor-board-platforms |
| 79 | $($(1)_BOARD_PLATFORMS) |
| 80 | endef |
| 81 | |
| 82 | # $(call is-board-platform,bp) |
| 83 | # returns true or empty |
| 84 | define is-board-platform |
| 85 | $(call match-word,$(1),$(TARGET_BOARD_PLATFORM)) |
| 86 | endef |
| 87 | |
| 88 | # $(call is-not-board-platform,bp) |
| 89 | # returns true or empty |
| 90 | define is-not-board-platform |
| 91 | $(if $(call match-word,$(1),$(TARGET_BOARD_PLATFORM)),,true) |
| 92 | endef |
| 93 | |
| 94 | # $(call is-board-platform-in-list,bpl) |
| 95 | # returns true or empty |
| 96 | define is-board-platform-in-list |
| 97 | $(call match-word-in-list,$(TARGET_BOARD_PLATFORM),$(1)) |
| 98 | endef |
| 99 | |
| 100 | # $(call is-product-in-list,tpl) |
| 101 | # # returns true or empty |
| 102 | define is-product-in-list |
| 103 | $(call match-word-in-list,$(TARGET_PRODUCT),$(1)) |
| 104 | endef |
| 105 | |
| 106 | # $(call is-vendor-board-platform,vendor) |
| 107 | # returns true or empty |
| 108 | define is-vendor-board-platform |
| 109 | $(strip \ |
| 110 | $(call match-word-in-list,$(TARGET_BOARD_PLATFORM),\ |
| 111 | $(call get-vendor-board-platforms,$(1)) \ |
| 112 | ) \ |
| 113 | ) |
| 114 | endef |
| 115 | |
| 116 | # $(call is-chipset-in-board-platform,chipset) |
| 117 | # does a prefix match of chipset in TARGET_BOARD_PLATFORM |
| 118 | # uses underscore as a delimiter |
| 119 | # |
| 120 | # returns true or empty |
| 121 | define is-chipset-in-board-platform |
| 122 | $(call match-prefix,$(1),$(underscore),$(TARGET_BOARD_PLATFORM)) |
| 123 | endef |
| 124 | |
| 125 | # $(call is-chipset-prefix-in-board-platform,prefix) |
| 126 | # does a chipset prefix match in TARGET_BOARD_PLATFORM |
| 127 | # assumes '_' and 'a' as the delimiter to the chipset prefix |
| 128 | # |
| 129 | # How it works |
| 130 | # if ($(prefix)_ or $(prefix)a match in board platform) |
| 131 | # return true |
| 132 | # else |
| 133 | # return empty |
| 134 | # |
| 135 | define is-chipset-prefix-in-board-platform |
| 136 | $(strip \ |
| 137 | $(eval delim_a := $(empty)a$(empty)) \ |
| 138 | $(if \ |
| 139 | $(or \ |
| 140 | $(call match-prefix,$(1),$(delim_a),$(TARGET_BOARD_PLATFORM)), \ |
| 141 | $(call match-prefix,$(1),$(underscore),$(TARGET_BOARD_PLATFORM)), \ |
| 142 | ), \ |
| 143 | true, \ |
| 144 | ) \ |
| 145 | ) |
| 146 | endef |
| 147 | |
| 148 | #---- |
| 149 | # The following utilities are meant for Android Code Name |
| 150 | # specific featurisation |
| 151 | # |
| 152 | # refer http://source.android.com/source/build-numbers.html |
| 153 | # for code names and associated sdk versions |
| 154 | CUPCAKE_SDK_VERSIONS := 3 |
| 155 | DONUT_SDK_VERSIONS := 4 |
| 156 | ECLAIR_SDK_VERSIONS := 5 6 7 |
| 157 | FROYO_SDK_VERSIONS := 8 |
| 158 | GINGERBREAD_SDK_VERSIONS := 9 10 |
| 159 | HONEYCOMB_SDK_VERSIONS := 11 12 13 |
| 160 | ICECREAM_SANDWICH_SDK_VERSIONS := 14 15 |
| 161 | JELLY_BEAN_SDK_VERSIONS := 16 17 18 |
| 162 | |
| 163 | # $(call is-platform-sdk-version-at-least,version) |
| 164 | # version is a numeric SDK_VERSION defined above |
| 165 | define is-platform-sdk-version-at-least |
| 166 | $(strip \ |
| 167 | $(if $(filter 1,$(shell echo "$$(( $(PLATFORM_SDK_VERSION) >= $(1) ))" )), \ |
| 168 | true, \ |
| 169 | ) \ |
| 170 | ) |
| 171 | endef |
| 172 | |
| 173 | # $(call is-android-codename,codename) |
| 174 | # codename is one of cupcake,donut,eclair,froyo,gingerbread,icecream |
| 175 | # please refer the $(codename)_SDK_VERSIONS declared above |
| 176 | define is-android-codename |
| 177 | $(strip \ |
| 178 | $(if \ |
| 179 | $(call match-word-in-list,$(PLATFORM_SDK_VERSION),$($(1)_SDK_VERSIONS)), \ |
| 180 | true, \ |
| 181 | ) \ |
| 182 | ) |
| 183 | endef |
| 184 | |
| 185 | # $(call is-android-codename-in-list,cnlist) |
| 186 | # cnlist is combination/list of android codenames |
| 187 | define is-android-codename-in-list |
| 188 | $(strip \ |
| 189 | $(eval acn := $(empty)) \ |
| 190 | $(foreach \ |
| 191 | i,$(1),\ |
| 192 | $(eval acn += \ |
| 193 | $(if \ |
| 194 | $(call \ |
| 195 | match-word-in-list,\ |
| 196 | $(PLATFORM_SDK_VERSION),\ |
| 197 | $($(i)_SDK_VERSIONS)\ |
| 198 | ),\ |
| 199 | true,\ |
| 200 | )\ |
| 201 | )\ |
| 202 | ) \ |
| 203 | $(if $(strip $(acn)),true,) \ |
| 204 | ) |
| 205 | endef |