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