1# Rules without side effects. 2 3# Vanilla Jam compatibility 4if ! $(INVOCATION_SUBDIR_SET) { 5 rule FIsPrefix 6 { 7 # FIsPrefix <a> : <b> ; 8 # Returns true, if list <a> is a prefix (a proper one or equal) of 9 # list <b>, an empty list otherwise. 10 local a = $(1) ; 11 local b = $(2) ; 12 while $(a) && $(a[1]) = $(b[1]) { 13 a = $(a[2-]) ; 14 b = $(b[2-]) ; 15 } 16 17 if $(a) { 18 return ; 19 } else { 20 return true ; 21 } 22 } 23 24 rule LocalClean { Clean $(1) : $(2) ; } 25 26 rule LocalDepends { Depends $(1) : $(2) ; } 27 28} # vanilla Jam compatibility 29 30rule FFilter 31{ 32 # FFilter <list> : <excludes> ; 33 # Removes all occurrences of <excludes> in <list>. 34 35 local list = $(1) ; 36 local excludes = $(2) ; 37 local newList ; 38 local item ; 39 for item in $(list) { 40 local skip ; 41 local exclude ; 42 for exclude in $(excludes) { 43 if $(item) = $(exclude) { 44 skip = true ; 45 } 46 } 47 if ! $(skip) { 48 newList += $(item) ; 49 } 50 } 51 return $(newList) ; 52} 53 54rule FGetGrist 55{ 56 # FGetGrist <target> ; 57 # 58 # Returns the grist of a target, not including leading "<" and trailing ">". 59 60 local grist = $(1[1]:G) ; 61 if ! $(grist) { 62 return ; 63 } 64 65 return [ Match <(.*)> : $(grist) ] ; 66} 67 68rule FSplitString string : delimiterChar 69{ 70 local result ; 71 72 while $(string) { 73 local split = [ Match $(delimiterChar)*([^$(delimiterChar)]+)(.*) 74 : $(string) ] ; 75 result += $(split[1]) ; 76 string = $(split[2-]) ; 77 } 78 79 return $(result) ; 80} 81 82rule FSplitPath 83{ 84 # SplitPath <path> ; 85 # Decomposes a path into its components. 86 local path = $(1:G=) ; 87 local components ; 88 # $(path:D) for "/" is "/". Therefore the second condition. 89 while $(path:D) && $(path:D) != $(path) 90 { 91 # Note: $(path:B) returns "." for "..", but $(path:D=) is fine. 92 components = $(path:D=) $(components) ; 93 path = $(path:D) ; 94 } 95 components = $(path) $(components) ; 96 return $(components) ; 97} 98 99 100rule FConditionsHold conditions : predicate 101{ 102 # FConditionsHold <conditions> : <predicate> ; 103 # Checks whether the conditions <conditions> are satisfied by the predicate 104 # rule <predicate> and returns a respective result (if so: "1", if not: 105 # empty list). The conditions are satisfied when <conditions> is not empty 106 # and 107 # * none of the negative conditions it contains hold and 108 # * if <conditions> contains any positive conditions, at least one of those 109 # holds. 110 # A positive condition is an element not starting with a "!". It holds when 111 # the predicate rule <predicate> returns true for the element. 112 # A negative condition is an element that starts with a "!". It holds when 113 # the predicate rule <predicate> returns true for the string resulting from 114 # removing the leading "!". 115 # 116 # <conditions> - The list of conditions. 117 # <predicate> - The predicate rule invoked to test the elements. 118 # 119 # Examples: 120 # For a predicate that holds for the elements of the set { a b c } the 121 # following conditions hold: 122 # { a }, { a d }, { !d }, { !d !e }, { a !d }, { b !e !f } 123 # The following conditions don't hold: 124 # { }, { d }, { d e }, { !a }, { !a b }, { !d e } { a b !c !d } 125 126 local hasPositive ; 127 local hasNegative ; 128 local positiveMatch ; 129 local condition ; 130 for condition in $(conditions) { 131 switch $(condition) { 132 case !* : 133 { 134 hasNegative = 1 ; 135 condition = [ Match "!(.*)" : $(condition) ] ; 136 if [ $(predicate) $(condition) ] { 137 return ; 138 } 139 } 140 case * : 141 { 142 hasPositive = 1 ; 143 if [ $(predicate) $(condition) ] { 144 positiveMatch = 1 ; 145 } 146 } 147 } 148 } 149 150 if $(hasPositive) { 151 return $(positiveMatch) ; 152 } 153 return $(hasNegative) ; 154} 155 156 157rule SetPlatformCompatibilityFlagVariables 158{ 159 # SetPlatformCompatibilityFlagVariables <platform var> : <var prefix> 160 # : <platform kind> [ : other platforms ] ; 161 162 local platformVar = $(1) ; 163 local platform = $($(platformVar)) ; 164 local varPrefix = $(2) ; 165 local platformKind = $(3) ; 166 local otherPlatforms = $(4) ; 167 168 if ! $(platform) { 169 ECHO "Variable $(platformVar) not set. Please run ./configure or" ; 170 EXIT "specify it manually." ; 171 } 172 173 # special case: Haiku libbe.so built for testing under Haiku 174 if $(platform) = libbe_test { 175 platform = $(HOST_PLATFORM) ; 176 } 177 178 # unset variables first 179 $(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = ; 180 181 switch $(platform) 182 { 183 case haiku_host : 184 { 185 $(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = true ; 186 } 187 188 case haiku : 189 { 190 $(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = true ; 191 } 192 193 case host : 194 # not compatible to anything 195 196 case * : 197 { 198 if ! ( $(platform) in $(otherPlatforms) ) { 199 Exit Unsupported $(platformKind) platform: $(platform) ; 200 } 201 } 202 } 203 204 # set the machine friendly flags 205 $(varPrefix)_PLATFORM_(haiku)_COMPATIBLE 206 ?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ; 207 $(varPrefix)_PLATFORM_(haiku_host)_COMPATIBLE 208 ?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ; 209} 210 211rule FAnalyzeGCCVersion 212{ 213 # FAnalyzeGCCVersion <rawVersionVariable> ; 214 # 215 local varName = $(1) ; 216 local rawVersion = $($(varName)) ; 217 218 if ! $(rawVersion) { 219 ECHO "Variable $(varName) not set. Please run ./configure or" ; 220 EXIT "specify it manually." ; 221 } 222 223 local version = ; 224 # split the raw version string at `.' and `-' characters 225 while $(rawVersion) { 226 local split = [ Match "([^.-]*)[.-](.*)" : $(rawVersion) ] ; 227 if $(split) { 228 version += $(split[1]) ; 229 rawVersion = $(split[2]) ; 230 } else { 231 version += $(rawVersion) ; 232 rawVersion = ; 233 } 234 } 235 236 return $(version) ; 237} 238 239rule SetIncludePropertiesVariables prefix : suffix 240{ 241 # SetIncludePropertiesVariables <prefix> : <suffix> ; 242 # 243 suffix = $(suffix:E=) ; 244 if $($(prefix)_GCC_VERSION$(suffix)[1]) < 4 { 245 $(prefix)_INCLUDES_SEPARATOR$(suffix) = -I- ; 246 $(prefix)_LOCAL_INCLUDES_OPTION$(suffix) = -I ; 247 $(prefix)_SYSTEM_INCLUDES_OPTION$(suffix) = -I ; 248 } else { 249 $(prefix)_INCLUDES_SEPARATOR$(suffix) = ; 250 $(prefix)_LOCAL_INCLUDES_OPTION$(suffix) = "-iquote " ; 251 $(prefix)_SYSTEM_INCLUDES_OPTION$(suffix) = "-I " ; 252 } 253} 254 255 256#pragma mark - 257 258rule SetPlatformForTarget 259{ 260 # SetPlatformForTarget <target> : <platform> ; 261 262 PLATFORM on $(1) = $(2) ; 263} 264 265rule SetSubDirPlatform 266{ 267 # SetSubDirPlatform <platform> ; 268 269 PLATFORM = $(1) ; 270} 271 272rule SetSupportedPlatformsForTarget 273{ 274 # SetSupportedPlatformsForTarget <target> : <platforms> ; 275 276 SUPPORTED_PLATFORMS on $(1) = $(2) ; 277} 278 279rule SetSubDirSupportedPlatforms 280{ 281 # SetSubDirSupportedPlatforms <platforms> ; 282 283 SUPPORTED_PLATFORMS = $(1) ; 284} 285 286rule AddSubDirSupportedPlatforms 287{ 288 # AddSubDirSupportedPlatforms <platforms> ; 289 290 SUPPORTED_PLATFORMS += $(1) ; 291} 292 293rule IsPlatformSupportedForTarget 294{ 295 # IsPlatformSupportedForTarget <target> [ : <platform> ] 296 # 297 298 on $(1) { 299 if $(PLATFORM) in $(SUPPORTED_PLATFORMS) { 300 return true ; 301 } else { 302 return ; 303 } 304 } 305} 306 307rule InheritPlatform 308{ 309 # InheritPlatform <children> : <parent> ; 310 # PLATFORM and SUPPORTED_PLATFORMS are set on <children> to their value 311 # on <parent>. 312 # 313 local children = $(1) ; 314 local parent = $(2) ; 315 316 on $(parent) { 317 PLATFORM on $(children) = $(PLATFORM) ; 318 SUPPORTED_PLATFORMS on $(children) = $(SUPPORTED_PLATFORMS) ; 319 } 320} 321 322rule SubDirAsFlags 323{ 324 SUBDIRASFLAGS += $(<) ; 325} 326