blob: 768558b4e845d06959af4554b34b3c87609fcdda [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)),\
22 $(if $(and $(call streq,Optimized,$($(key).Target)),\
23 $(call contains,$($(key).OnlyConfigs),$(1)),\
24 $(call contains,$($(key).OnlyArchs),$(2))),$(key),)))
25SelectFunctionDirs_Opt_Config = $(strip \
26 $(foreach key,$(AvailableIn.$(3)),\
27 $(if $(and $(call streq,Optimized,$($(key).Target)),\
28 $(call contains,$($(key).OnlyConfigs),$(1))),$(key),)))
29SelectFunctionDirs_Opt_Arch = $(strip \
30 $(foreach key,$(AvailableIn.$(3)),\
31 $(if $(and $(call streq,Optimized,$($(key).Target)),\
32 $(call contains,$($(key).OnlyArchs),$(2))),$(key),)))
33SelectFunctionDirs_Gen = $(strip \
34 $(foreach key,$(AvailableIn.$(3)),\
35 $(if $(call streq,Generic,$($(key).Target)),$(key))))
36
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)))