• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# vars for use by utils
2colon := $(empty):$(empty)
3underscore := $(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#
14define match-word
15$(strip \
16  $(if $(or $(subst $(1),$(empty),$(2)),$(subst $(2),$(empty),$(1))),,true) \
17)
18endef
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
29define 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)
36endef
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
46define 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)
52endef
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#
64define 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)
70endef
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
78define get-vendor-board-platforms
79$($(1)_BOARD_PLATFORMS)
80endef
81
82# $(call is-board-platform,bp)
83# returns true or empty
84define is-board-platform
85$(call match-word,$(1),$(TARGET_BOARD_PLATFORM))
86endef
87
88# $(call is-not-board-platform,bp)
89# returns true or empty
90define is-not-board-platform
91$(if $(call match-word,$(1),$(TARGET_BOARD_PLATFORM)),,true)
92endef
93
94# $(call is-board-platform-in-list,bpl)
95# returns true or empty
96define is-board-platform-in-list
97$(call match-word-in-list,$(TARGET_BOARD_PLATFORM),$(1))
98endef
99
100# $(call is-vendor-board-platform,vendor)
101# returns true or empty
102define is-vendor-board-platform
103$(strip \
104  $(call match-word-in-list,$(TARGET_BOARD_PLATFORM),\
105    $(call get-vendor-board-platforms,$(1)) \
106  ) \
107)
108endef
109
110# $(call is-chipset-in-board-platform,chipset)
111# does a prefix match of chipset in TARGET_BOARD_PLATFORM
112# uses underscore as a delimiter
113#
114# returns true or empty
115define is-chipset-in-board-platform
116$(call match-prefix,$(1),$(underscore),$(TARGET_BOARD_PLATFORM))
117endef
118
119# $(call is-chipset-prefix-in-board-platform,prefix)
120# does a chipset prefix match in TARGET_BOARD_PLATFORM
121# assumes '_' and 'a' as the delimiter to the chipset prefix
122#
123# How it works
124#   if ($(prefix)_ or $(prefix)a match in board platform)
125#     return true
126#   else
127#     return empty
128#
129define is-chipset-prefix-in-board-platform
130$(strip \
131  $(eval delim_a := $(empty)a$(empty)) \
132  $(if \
133    $(or \
134      $(call match-prefix,$(1),$(delim_a),$(TARGET_BOARD_PLATFORM)), \
135      $(call match-prefix,$(1),$(underscore),$(TARGET_BOARD_PLATFORM)), \
136    ), \
137    true, \
138  ) \
139)
140endef
141
142#----
143# The following utilities are meant for Android Code Name
144# specific featurisation
145#
146# refer http://source.android.com/source/build-numbers.html
147# for code names and associated sdk versions
148CUPCAKE_SDK_VERSIONS := 3
149DONUT_SDK_VERSIONS   := 4
150ECLAIR_SDK_VERSIONS  := 5 6 7
151FROYO_SDK_VERSIONS   := 8
152GINGERBREAD_SDK_VERSIONS := 9 10
153HONEYCOMB_SDK_VERSIONS := 11 12 13
154ICECREAM_SANDWICH_SDK_VERSIONS := 14 15
155JELLY_BEAN_SDK_VERSIONS := 16 17 18
156
157# $(call is-platform-sdk-version-at-least,version)
158# version is a numeric SDK_VERSION defined above
159define is-platform-sdk-version-at-least
160$(strip \
161  $(if $(filter 1,$(shell echo "$$(( $(PLATFORM_SDK_VERSION) >= $(1) ))" )), \
162    true, \
163  ) \
164)
165endef
166
167# $(call is-android-codename,codename)
168# codename is one of cupcake,donut,eclair,froyo,gingerbread,icecream
169# please refer the $(codename)_SDK_VERSIONS declared above
170define is-android-codename
171$(strip \
172  $(if \
173    $(call match-word-in-list,$(PLATFORM_SDK_VERSION),$($(1)_SDK_VERSIONS)), \
174    true, \
175  ) \
176)
177endef
178
179# $(call is-android-codename-in-list,cnlist)
180# cnlist is combination/list of android codenames
181define is-android-codename-in-list
182$(strip \
183  $(eval acn := $(empty)) \
184    $(foreach \
185      i,$(1),\
186      $(eval acn += \
187        $(if \
188          $(call \
189            match-word-in-list,\
190            $(PLATFORM_SDK_VERSION),\
191            $($(i)_SDK_VERSIONS)\
192          ),\
193          true,\
194        )\
195      )\
196    ) \
197  $(if $(strip $(acn)),true,) \
198)
199endef
200