blob: 0ff662614ecb0ed0f60c5044d92b3ca1cd232d64 [file] [log] [blame]
Daniel Dunbar78cfbc52010-01-18 06:48:56 +00001# 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.
9SelectFunctionDir = $(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.
20SelectFunctionDirs_Opt_ConfigAndArch = $(strip \
21 $(foreach key,$(AvailableIn.$(3)),\
Daniel Dunbar6db90e62010-01-18 06:49:09 +000022 $(if $(and $(call streq,Optimized,$($(key).Implementation)),\
Daniel Dunbar78cfbc52010-01-18 06:48:56 +000023 $(call contains,$($(key).OnlyConfigs),$(1)),\
24 $(call contains,$($(key).OnlyArchs),$(2))),$(key),)))
25SelectFunctionDirs_Opt_Config = $(strip \
26 $(foreach key,$(AvailableIn.$(3)),\
Daniel Dunbar6db90e62010-01-18 06:49:09 +000027 $(if $(and $(call streq,Optimized,$($(key).Implementation)),\
Daniel Dunbar78cfbc52010-01-18 06:48:56 +000028 $(call contains,$($(key).OnlyConfigs),$(1))),$(key),)))
29SelectFunctionDirs_Opt_Arch = $(strip \
30 $(foreach key,$(AvailableIn.$(3)),\
Daniel Dunbar6db90e62010-01-18 06:49:09 +000031 $(if $(and $(call streq,Optimized,$($(key).Implementation)),\
Daniel Dunbar78cfbc52010-01-18 06:48:56 +000032 $(call contains,$($(key).OnlyArchs),$(2))),$(key),)))
33SelectFunctionDirs_Gen = $(strip \
34 $(foreach key,$(AvailableIn.$(3)),\
Daniel Dunbar6db90e62010-01-18 06:49:09 +000035 $(if $(call streq,Generic,$($(key).Implementation)),$(key))))
Daniel Dunbar78cfbc52010-01-18 06:48:56 +000036
37# Helper function to select the right set of dirs in generic priority order.
38SelectFunctions_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.
45SelectFunctions_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.
53SelectFunctionDirs = \
54 $(if $(call streq,1,$(4)),\
55 $(call SelectFunctions_Opt,$(1),$(2),$(3)),\
56 $(call SelectFunctions_Gen,$(1),$(2),$(3)))