Daniel Dunbar | 78cfbc5 | 2010-01-18 06:48:56 +0000 | [diff] [blame] | 1 | # Library Utility Functions |
| 2 | # |
| 3 | # This should be included following 'lib_info.mk'. |
| 4 | |
Daniel Dunbar | 48464e0 | 2010-01-18 06:49:33 +0000 | [diff] [blame] | 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 | |
Daniel Dunbar | 78cfbc5 | 2010-01-18 06:48:56 +0000 | [diff] [blame] | 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)),\ |
Daniel Dunbar | 6db90e6 | 2010-01-18 06:49:09 +0000 | [diff] [blame] | 31 | $(if $(and $(call streq,Optimized,$($(key).Implementation)),\ |
Daniel Dunbar | 78cfbc5 | 2010-01-18 06:48:56 +0000 | [diff] [blame] | 32 | $(call contains,$($(key).OnlyConfigs),$(1)),\ |
| 33 | $(call contains,$($(key).OnlyArchs),$(2))),$(key),))) |
| 34 | SelectFunctionDirs_Opt_Config = $(strip \ |
| 35 | $(foreach key,$(AvailableIn.$(3)),\ |
Daniel Dunbar | 6db90e6 | 2010-01-18 06:49:09 +0000 | [diff] [blame] | 36 | $(if $(and $(call streq,Optimized,$($(key).Implementation)),\ |
Daniel Dunbar | 78cfbc5 | 2010-01-18 06:48:56 +0000 | [diff] [blame] | 37 | $(call contains,$($(key).OnlyConfigs),$(1))),$(key),))) |
| 38 | SelectFunctionDirs_Opt_Arch = $(strip \ |
| 39 | $(foreach key,$(AvailableIn.$(3)),\ |
Daniel Dunbar | 6db90e6 | 2010-01-18 06:49:09 +0000 | [diff] [blame] | 40 | $(if $(and $(call streq,Optimized,$($(key).Implementation)),\ |
Daniel Dunbar | 78cfbc5 | 2010-01-18 06:48:56 +0000 | [diff] [blame] | 41 | $(call contains,$($(key).OnlyArchs),$(2))),$(key),))) |
| 42 | SelectFunctionDirs_Gen = $(strip \ |
| 43 | $(foreach key,$(AvailableIn.$(3)),\ |
Daniel Dunbar | 6db90e6 | 2010-01-18 06:49:09 +0000 | [diff] [blame] | 44 | $(if $(call streq,Generic,$($(key).Implementation)),$(key)))) |
Daniel Dunbar | 78cfbc5 | 2010-01-18 06:48:56 +0000 | [diff] [blame] | 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))) |