1 # Library Utility Functions 2 # 3 # This should be included following 'lib_info.mk'. 4 5 # Function: GetCNAVar variable-name platform-key config arch 6 # 7 # Get a per-config-and-arch variable value. 8 GetCNAVar = $(strip \ 9 $(or $($(2).$(1).$(3).$(4)), \ 10 $($(2).$(1).$(3)), \ 11 $($(2).$(1).$(4)), \ 12 $($(2).$(1)))) 13 14 # Function: SelectFunctionDir config arch function-name optimized 15 # 16 # Choose the appropriate implementation directory to use for 'function-name' in 17 # the configuration 'config' and on given arch. 18 SelectFunctionDir = $(strip \ 19 $(call Set,Tmp.SelectFunctionDir,$(call SelectFunctionDirs,$(1),$(2),$(3),$(4)))\ 20 $(if $(call streq,1,$(words $(Tmp.SelectFunctionDir))),\ 21 $(Tmp.SelectFunctionDir),\ 22 $(error SelectFunctionDir: invalid function name "$(3)" ($(strip\ 23 $(if $(call streq,0,$(words $(Tmp.SelectFunctionDir))),\ 24 no such function,\ 25 function implemented in multiple directories!!!)))))) 26 27 # Helper functions that select the entire list of subdirs where a function is 28 # defined with a certain specificity. 29 SelectFunctionDirs_Opt_ConfigAndArch = $(strip \ 30 $(foreach key,$(AvailableIn.$(3)),\ 31 $(if $(and $(call streq,Optimized,$($(key).Implementation)),\ 32 $(call contains,$($(key).OnlyConfigs),$(1)),\ 33 $(call contains,$($(key).OnlyArchs),$(2))),$(key),))) 34 SelectFunctionDirs_Opt_Config = $(strip \ 35 $(foreach key,$(AvailableIn.$(3)),\ 36 $(if $(and $(call streq,Optimized,$($(key).Implementation)),\ 37 $(call contains,$($(key).OnlyConfigs),$(1))),$(key),))) 38 SelectFunctionDirs_Opt_Arch = $(strip \ 39 $(foreach key,$(AvailableIn.$(3)),\ 40 $(if $(and $(call streq,Optimized,$($(key).Implementation)),\ 41 $(call contains,$($(key).OnlyArchs),$(2))),$(key),))) 42 SelectFunctionDirs_Gen = $(strip \ 43 $(foreach key,$(AvailableIn.$(3)),\ 44 $(if $(call streq,Generic,$($(key).Implementation)),$(key)))) 45 46 # Helper function to select the right set of dirs in generic priority order. 47 SelectFunctions_Gen = \ 48 $(or $(call SelectFunctionDirs_Gen,$(1),$(2),$(3)),\ 49 $(call SelectFunctionDirs_Opt_ConfigAndArch,$(1),$(2),$(3)), \ 50 $(call SelectFunctionDirs_Opt_Config,$(1),$(2),$(3)), \ 51 $(call SelectFunctionDirs_Opt_Arch,$(1),$(2),$(3))) 52 53 # Helper function to select the right set of dirs in optimized priority order. 54 SelectFunctions_Opt = \ 55 $(or $(call SelectFunctionDirs_Opt_ConfigAndArch,$(1),$(2),$(3)), \ 56 $(call SelectFunctionDirs_Opt_Config,$(1),$(2),$(3)), \ 57 $(call SelectFunctionDirs_Opt_Arch,$(1),$(2),$(3)), \ 58 $(call SelectFunctionDirs_Gen,$(1),$(2),$(3))) 59 60 # Helper function to select the right set of dirs (which should be exactly one) 61 # for a function. 62 SelectFunctionDirs = \ 63 $(if $(call streq,1,$(4)),\ 64 $(call SelectFunctions_Opt,$(1),$(2),$(3)),\ 65 $(call SelectFunctions_Gen,$(1),$(2),$(3))) 66