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 99rule SetPlatformCompatibilityFlagVariables 100{ 101 # SetPlatformCompatibilityFlagVariables <platform var> : <var prefix> 102 # : <platform kind> [ : other platforms ] ; 103 104 local platformVar = $(1) ; 105 local platform = $($(platformVar)) ; 106 local varPrefix = $(2) ; 107 local platformKind = $(3) ; 108 local otherPlatforms = $(4) ; 109 110 if ! $(platform) { 111 ECHO "Variable $(platformVar) not set. Please run ./configure or" ; 112 EXIT "specify it manually." ; 113 } 114 115 # special case: Haiku libbe.so built for testing under BeOS 116 if $(platform) = libbe_test { 117 platform = $(HOST_PLATFORM) ; 118 } 119 120 $(varPrefix)_PLATFORM_BEOS_COMPATIBLE = ; 121 $(varPrefix)_PLATFORM_BONE_COMPATIBLE = ; 122 $(varPrefix)_PLATFORM_DANO_COMPATIBLE = ; 123 $(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = ; 124 125 switch $(platform) 126 { 127 case r5 : 128 { 129 $(varPrefix)_PLATFORM_BEOS_COMPATIBLE = true ; 130 } 131 132 case bone : 133 { 134 $(varPrefix)_PLATFORM_BONE_COMPATIBLE = true ; 135 } 136 137 case dano : 138 { 139 $(varPrefix)_PLATFORM_DANO_COMPATIBLE = true ; 140 } 141 142 case haiku_host : 143 { 144 $(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = true ; 145 } 146 147 case haiku : 148 { 149 $(varPrefix)_PLATFORM_HAIKU_COMPATIBLE = true ; 150 } 151 152 case * : 153 { 154 if ! ( $(platform) in $(otherPlatforms) ) { 155 Exit Unsupported $(platformKind) platform: $(platform) ; 156 } 157 } 158 } 159 160 # set lesser flags, e.g. "DANO" for "HAIKU" and "BEOS" for "BONE" 161 $(varPrefix)_PLATFORM_HAIKU_COMPATIBLE 162 ?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ; 163 $(varPrefix)_PLATFORM_DANO_COMPATIBLE 164 ?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ; 165 $(varPrefix)_PLATFORM_BONE_COMPATIBLE 166 ?= $($(varPrefix)_PLATFORM_DANO_COMPATIBLE) ; 167 $(varPrefix)_PLATFORM_BEOS_COMPATIBLE 168 ?= $($(varPrefix)_PLATFORM_BONE_COMPATIBLE) ; 169 170 # set the machine friendly flags 171 $(varPrefix)_PLATFORM_(haiku)_COMPATIBLE 172 ?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ; 173 $(varPrefix)_PLATFORM_(haiku_host)_COMPATIBLE 174 ?= $($(varPrefix)_PLATFORM_HAIKU_COMPATIBLE) ; 175 $(varPrefix)_PLATFORM_(dano)_COMPATIBLE 176 ?= $($(varPrefix)_PLATFORM_DANO_COMPATIBLE) ; 177 $(varPrefix)_PLATFORM_(bone)_COMPATIBLE 178 ?= $($(varPrefix)_PLATFORM_BONE_COMPATIBLE) ; 179 $(varPrefix)_PLATFORM_(r5)_COMPATIBLE 180 ?= $($(varPrefix)_PLATFORM_BEOS_COMPATIBLE) ; 181 182 $(varPrefix)_PLATFORM_(libbe_test)_COMPATIBLE 183 ?= $($(varPrefix)_PLATFORM_BEOS_COMPATIBLE) ; 184} 185 186rule FAnalyzeGCCVersion 187{ 188 # FAnalyzeGCCVersion <rawVersionVariable> ; 189 # 190 local varName = $(1) ; 191 local rawVersion = $($(varName)) ; 192 193 if ! $(rawVersion) { 194 ECHO "Variable $(varName) not set. Please run ./configure or" ; 195 EXIT "specify it manually." ; 196 } 197 198 local version = ; 199 # split the raw version string at `.' and `-' characters 200 while $(rawVersion) { 201 local split = [ Match "([^.-]*)[.-](.*)" : $(rawVersion) ] ; 202 if $(split) { 203 version += $(split[1]) ; 204 rawVersion = $(split[2]) ; 205 } else { 206 version += $(rawVersion) ; 207 rawVersion = ; 208 } 209 } 210 211 return $(version) ; 212} 213 214rule SetIncludePropertiesVariables 215{ 216 # SetIncludePropertiesVariables <varPrefix> ; 217 # 218 local prefix = $(1) ; 219 if $($(prefix)_GCC_VERSION[1]) < 4 { 220 $(prefix)_INCLUDES_SEPARATOR = -I- ; 221 $(prefix)_LOCAL_INCLUDES_OPTION = -I ; 222 $(prefix)_SYSTEM_INCLUDES_OPTION = -I ; 223 } else { 224 $(prefix)_INCLUDES_SEPARATOR = ; 225 $(prefix)_LOCAL_INCLUDES_OPTION = "-iquote " ; 226 $(prefix)_SYSTEM_INCLUDES_OPTION = "-I " ; 227 } 228} 229 230 231#pragma mark - 232 233rule SetPlatformForTarget 234{ 235 # SetPlatformForTarget <target> : <platform> ; 236 237 PLATFORM on $(1) = $(2) ; 238} 239 240rule SetSubDirPlatform 241{ 242 # SetSubDirPlatform <platform> ; 243 244 PLATFORM = $(1) ; 245} 246 247rule SetSupportedPlatformsForTarget 248{ 249 # SetSupportedPlatformsForTarget <target> : <platforms> ; 250 251 SUPPORTED_PLATFORMS on $(1) = $(2) ; 252} 253 254rule SetSubDirSupportedPlatforms 255{ 256 # SetSubDirSupportedPlatforms <platforms> ; 257 258 SUPPORTED_PLATFORMS = $(1) ; 259} 260 261rule AddSubDirSupportedPlatforms 262{ 263 # AddSubDirSupportedPlatforms <platforms> ; 264 265 SUPPORTED_PLATFORMS += $(1) ; 266} 267 268rule SetSubDirSupportedPlatformsBeOSCompatible 269{ 270 # SetSubDirSupportedPlatformsBeOSCompatible ; 271 272 SUPPORTED_PLATFORMS = $(HAIKU_BEOS_COMPATIBLE_PLATFORMS) ; 273} 274 275rule IsPlatformSupportedForTarget 276{ 277 # IsPlatformSupportedForTarget <target> [ : <platform> ] 278 # 279 280 on $(1) { 281 if $(PLATFORM) in $(SUPPORTED_PLATFORMS) { 282 return true ; 283 } else { 284 return ; 285 } 286 } 287} 288 289rule InheritPlatform 290{ 291 # InheritPlatform <children> : <parent> ; 292 # PLATFORM and SUPPORTED_PLATFORMS are set on <children> to their value 293 # on <parent>. 294 # 295 local children = $(1) ; 296 local parent = $(2) ; 297 298 on $(parent) { 299 PLATFORM on $(children) = $(PLATFORM) ; 300 SUPPORTED_PLATFORMS on $(children) = $(SUPPORTED_PLATFORMS) ; 301 } 302} 303 304rule SubDirAsFlags 305{ 306 SUBDIRASFLAGS += $(<) ; 307} 308 309