3 # Contains rules providing the config variable feature. It allows to set the
4 # values for certain variables for subdirectories in a central place. That is
5 # one can, for instance, specify in a file like UserBuildConfig for which
6 # directories to enable debugging, warnings, set special defines, compiler
7 # flags and the like without needing to edit the Jamfiles for the respective
12 # ConfigObject <dir> [ : <varName> ] ;
14 # Private rule. Returns the dummy object on which the config variables are
15 # set for a given subdir.
17 # <dir>: Parameters as passed to the SubDir rule, i.e. the name of the
18 # TOP variable and the subdir tokens.
20 local config = $(2:E=__config__) ;
21 local grist = [ FGrist root $(1) ] ;
22 return $(config:G=$(grist)) ;
27 # SetConfigVar <var> : <dir> : <value> [ : <scope> ] ;
29 # Sets a config variable for a specified directory to the given value.
31 # <var>: The name of the variable to be set.
32 # <dir>: Parameters as passed to the SubDir rule, i.e. the name of the
33 # TOP variable and the subdir tokens.
34 # <value>: The value to which the variable shall be set.
35 # <scope>: Either "global" or "local". The former implies that the variable
36 # value shall also be used for subdirectories (recursively), if
37 # for them the variable has not been set. The latter has the same
38 # effect regarding subdirs as if the variable for the directory
39 # is not set. Defaults to "global".
42 local config = [ ConfigObject $(2) ] ;
43 local scope = $(4:E=global) ;
45 $(var) on $(config) = $(3) ;
46 __set_$(var) on $(config) = $(scope) ;
48 if $(scope) = global {
49 $(var) on [ ConfigObject $(2) : __inherited_config__ ] = $(3) ;
52 if ! [ on $(config) return $(__configured) ] {
53 __configured on $(config) = true ;
54 __dir_tokens on $(config) = $(2) ;
56 HAIKU_EXISTING_SUBDIR_CONFIGS += $(config) ;
60 rule AppendToConfigVar
62 # AppendToConfigVar <var> : <dir> : <value> [ : <scope> ] ;
64 # Appends a value to a config variable for a specified directory. Shortcut
66 # SetConfigVar <var> : <dir> : [ ConfigVar <var> : <dir> ] <value
69 # <var>: The name of the variable to be set.
70 # <dir>: Parameters as passed to the SubDir rule, i.e. the name of the
71 # TOP variable and the subdir tokens.
72 # <value>: The value which to append to the variables current value.
73 # <scope>: Either "global" or "local". The former implies that the variable
74 # value shall also be used for subdirectories (recursively), if
75 # for them the variable has not been set. The latter has the same
76 # effect regarding subdirs as if the variable for the directory
77 # is not set. Defaults to "global".
79 SetConfigVar $(1) : $(2) : [ ConfigVar $(1) : $(2) ] $(3) : $(4) ;
84 # ConfigVar <var> : <dir> [ : <scope> ] ;
86 # Returns the value of a configuration variable for a given subdir.
87 # If the variable is not set for the subdir, the rule is invoked
88 # recursively for the parent directory with the scope "global". When
89 # the root is reached without yielding a value, the value of the global
90 # variable <var> is returned.
92 # <var>: The name of the variable whose value shall be returned.
93 # <dir>: Parameters as passed to the SubDir rule, i.e. the name of the
94 # TOP variable and the subdir tokens.
95 # <scope>: If not given any scope passed to SetConfigVar for the given
96 # directory will be accepted, otherwise it must match the scope
97 # passed to SetConfigVar.
101 local config = [ ConfigObject $(dir) ] ;
103 local varScope = [ on $(config) return $(__set_$(var)) ] ;
104 if ( ! $(scope) && $(varScope) )
105 || ( $(scope) && $(scope) = $(varScope) )
107 on $(config) return $($(var)) ;
109 dir = [ FReverse $(dir) ] ;
110 return [ ConfigVar $(var) : [ FReverse $(dir[2-]) ] : global ] ;
114 rule PrepareSubDirConfigVariables
116 local dirTokens = $(1) ;
117 local config = [ ConfigObject $(dirTokens) ] ;
119 if ! [ on $(config) return $(__prepared) ] {
120 # prepare config for parent dir
121 local parentDir = [ FReverse $(dirTokens) ] ;
122 parentDir = [ FReverse $(parentDir[2-]) ] ;
123 PrepareSubDirConfigVariables $(parentDir) ;
125 # set values for all config variables for the config and the inherited
126 # config for this directory
127 local inheritedConfig = [ ConfigObject $(dirTokens)
128 : __inherited_config__ ] ;
130 on [ ConfigObject $(parentDir) : __inherited_config__ ] {
132 for var in $(AUTO_SET_UP_CONFIG_VARIABLES) {
133 $(var) on $(config) ?= $($(var)) ;
134 $(var) on $(inheritedConfig) ?= $($(var)) ;
138 HAIKU_INHERITED_SUBDIR_CONFIG on $(config) = $(inheritedConfig) ;
140 __prepared on $(config) = true ;
144 rule PrepareConfigVariables
146 # initialize variables on the root config and the root inherited config
147 # objects to the global values
148 local rootConfig = [ ConfigObject ] ; # the root config object
149 local inheritedRootConfig = [ ConfigObject : __inherited_config__ ] ;
152 for var in $(AUTO_SET_UP_CONFIG_VARIABLES) {
153 $(var) on $(rootConfig) = $($(var)) ;
154 $(var) on $(inheritedRootConfig) = $($(var)) ;
156 __prepared on $(rootConfig) = true ;
158 HAIKU_INHERITED_SUBDIR_CONFIG = $(rootConfig) ;
161 for config in $(HAIKU_EXISTING_SUBDIR_CONFIGS) {
162 PrepareSubDirConfigVariables [ on $(config) return $(__dir_tokens) ] ;
166 # Some config variables that should be set up automatically for subdirs.
167 AUTO_SET_UP_CONFIG_VARIABLES +=
168 CCFLAGS C++FLAGS DEBUG DEFINES HDRS JAMFILE LINKFLAGS OPTIM OPTIMIZE