blob: 089a0e2eddc973b60c7214f4fd5e2d0ac241d81c [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
Daniel Dunbar48464e02010-01-18 06:49:33 +00005# Function: GetCNAVar variable-name platform-key config arch
6#
7# Get a per-config-and-arch variable value.
8GetCNAVar = $(strip \
9 $(or $($(2).$(1).$(3).$(4)), \
10 $($(2).$(1).$(3)), \
11 $($(2).$(1).$(4)), \
12 $($(2).$(1))))
13
Daniel Dunbar78cfbc52010-01-18 06:48:56 +000014# 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.
18SelectFunctionDir = $(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.
29SelectFunctionDirs_Opt_ConfigAndArch = $(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).OnlyConfigs),$(1)),\
33 $(call contains,$($(key).OnlyArchs),$(2))),$(key),)))
34SelectFunctionDirs_Opt_Config = $(strip \
35 $(foreach key,$(AvailableIn.$(3)),\
Daniel Dunbar6db90e62010-01-18 06:49:09 +000036 $(if $(and $(call streq,Optimized,$($(key).Implementation)),\
Daniel Dunbar78cfbc52010-01-18 06:48:56 +000037 $(call contains,$($(key).OnlyConfigs),$(1))),$(key),)))
38SelectFunctionDirs_Opt_Arch = $(strip \
39 $(foreach key,$(AvailableIn.$(3)),\
Daniel Dunbar6db90e62010-01-18 06:49:09 +000040 $(if $(and $(call streq,Optimized,$($(key).Implementation)),\
Daniel Dunbar78cfbc52010-01-18 06:48:56 +000041 $(call contains,$($(key).OnlyArchs),$(2))),$(key),)))
42SelectFunctionDirs_Gen = $(strip \
43 $(foreach key,$(AvailableIn.$(3)),\
Daniel Dunbar6db90e62010-01-18 06:49:09 +000044 $(if $(call streq,Generic,$($(key).Implementation)),$(key))))
Daniel Dunbar78cfbc52010-01-18 06:48:56 +000045
46# Helper function to select the right set of dirs in generic priority order.
47SelectFunctions_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.
54SelectFunctions_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.
62SelectFunctionDirs = \
63 $(if $(call streq,1,$(4)),\
64 $(call SelectFunctions_Opt,$(1),$(2),$(3)),\
65 $(call SelectFunctions_Gen,$(1),$(2),$(3)))