| 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 | |
| 5 | # Function: SelectFunctionDir config arch function-name optimized |
| 6 | # |
| 7 | # Choose the appropriate implementation directory to use for 'function-name' in |
| 8 | # the configuration 'config' and on given arch. |
| 9 | SelectFunctionDir = $(strip \ |
| 10 | $(call Set,Tmp.SelectFunctionDir,$(call SelectFunctionDirs,$(1),$(2),$(3),$(4)))\ |
| 11 | $(if $(call streq,1,$(words $(Tmp.SelectFunctionDir))),\ |
| 12 | $(Tmp.SelectFunctionDir),\ |
| 13 | $(error SelectFunctionDir: invalid function name "$(3)" ($(strip\ |
| 14 | $(if $(call streq,0,$(words $(Tmp.SelectFunctionDir))),\ |
| 15 | no such function,\ |
| 16 | function implemented in multiple directories!!!)))))) |
| 17 | |
| 18 | # Helper functions that select the entire list of subdirs where a function is |
| 19 | # defined with a certain specificity. |
| 20 | SelectFunctionDirs_Opt_ConfigAndArch = $(strip \ |
| 21 | $(foreach key,$(AvailableIn.$(3)),\ |
| Daniel Dunbar | 6db90e6 | 2010-01-18 06:49:09 +0000 | [diff] [blame^] | 22 | $(if $(and $(call streq,Optimized,$($(key).Implementation)),\ |
| Daniel Dunbar | 78cfbc5 | 2010-01-18 06:48:56 +0000 | [diff] [blame] | 23 | $(call contains,$($(key).OnlyConfigs),$(1)),\ |
| 24 | $(call contains,$($(key).OnlyArchs),$(2))),$(key),))) |
| 25 | SelectFunctionDirs_Opt_Config = $(strip \ |
| 26 | $(foreach key,$(AvailableIn.$(3)),\ |
| Daniel Dunbar | 6db90e6 | 2010-01-18 06:49:09 +0000 | [diff] [blame^] | 27 | $(if $(and $(call streq,Optimized,$($(key).Implementation)),\ |
| Daniel Dunbar | 78cfbc5 | 2010-01-18 06:48:56 +0000 | [diff] [blame] | 28 | $(call contains,$($(key).OnlyConfigs),$(1))),$(key),))) |
| 29 | SelectFunctionDirs_Opt_Arch = $(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).OnlyArchs),$(2))),$(key),))) |
| 33 | SelectFunctionDirs_Gen = $(strip \ |
| 34 | $(foreach key,$(AvailableIn.$(3)),\ |
| Daniel Dunbar | 6db90e6 | 2010-01-18 06:49:09 +0000 | [diff] [blame^] | 35 | $(if $(call streq,Generic,$($(key).Implementation)),$(key)))) |
| Daniel Dunbar | 78cfbc5 | 2010-01-18 06:48:56 +0000 | [diff] [blame] | 36 | |
| 37 | # Helper function to select the right set of dirs in generic priority order. |
| 38 | SelectFunctions_Gen = \ |
| 39 | $(or $(call SelectFunctionDirs_Gen,$(1),$(2),$(3)),\ |
| 40 | $(call SelectFunctionDirs_Opt_ConfigAndArch,$(1),$(2),$(3)), \ |
| 41 | $(call SelectFunctionDirs_Opt_Config,$(1),$(2),$(3)), \ |
| 42 | $(call SelectFunctionDirs_Opt_Arch,$(1),$(2),$(3))) |
| 43 | |
| 44 | # Helper function to select the right set of dirs in optimized priority order. |
| 45 | SelectFunctions_Opt = \ |
| 46 | $(or $(call SelectFunctionDirs_Opt_ConfigAndArch,$(1),$(2),$(3)), \ |
| 47 | $(call SelectFunctionDirs_Opt_Config,$(1),$(2),$(3)), \ |
| 48 | $(call SelectFunctionDirs_Opt_Arch,$(1),$(2),$(3)), \ |
| 49 | $(call SelectFunctionDirs_Gen,$(1),$(2),$(3))) |
| 50 | |
| 51 | # Helper function to select the right set of dirs (which should be exactly one) |
| 52 | # for a function. |
| 53 | SelectFunctionDirs = \ |
| 54 | $(if $(call streq,1,$(4)),\ |
| 55 | $(call SelectFunctions_Opt,$(1),$(2),$(3)),\ |
| 56 | $(call SelectFunctions_Gen,$(1),$(2),$(3))) |