1 2rule SetupObjectsDir 3{ 4 # SetupObjectsDir 5 # 6 # Internal rule used to set up the *{LOCATE,SEARCH}*_{TARGET,SOURCE} 7 # variables for the current directory. 8 9 local relPath = [ FDirName $(SUBDIR_TOKENS[2-]) ] ; 10 if $(relPath) = . { 11 relPath = ; 12 } 13 COMMON_PLATFORM_LOCATE_TARGET = 14 [ FDirName $(HAIKU_COMMON_PLATFORM_OBJECT_DIR) $(relPath) ] ; 15 16 local var ; 17 for var in COMMON_ARCH COMMON_DEBUG DEBUG_$(HAIKU_DEBUG_LEVELS) { 18 HOST_$(var)_LOCATE_TARGET 19 = [ FDirName $(HOST_$(var)_OBJECT_DIR) $(relPath) ] ; 20 TARGET_$(var)_LOCATE_TARGET 21 = [ FDirName $(TARGET_$(var)_OBJECT_DIR) $(relPath) ] ; 22 } 23 24 LOCATE_TARGET = $(COMMON_PLATFORM_LOCATE_TARGET) ; 25 LOCATE_SOURCE = $(LOCATE_TARGET) ; 26 SEARCH_SOURCE = $(SUBDIR) $(LOCATE_SOURCE) 27 $(HOST_COMMON_DEBUG_LOCATE_TARGET) # Also add the standard output 28 $(TARGET_COMMON_DEBUG_LOCATE_TARGET) # dirs for generated sources. 29 ; 30} 31 32rule SetupFeatureObjectsDir feature 33{ 34 # SetupFeatureObjectsDir <feature> 35 # 36 # Updates the *{LOCATE,SEARCH}*_{TARGET,SOURCE} variables for the current 37 # directory appending a <feature> to each of them. Note that it resets 38 # the LOCATE_TARGET, LOCATE_SOURCE, SEARCH_SOURCE (!) variables. I.e. it 39 # should be invoked before customizing these variables further (e.g. like 40 # adding additional source directories to SEARCH_SOURCE). 41 42 COMMON_PLATFORM_LOCATE_TARGET 43 = [ FDirName $(COMMON_PLATFORM_LOCATE_TARGET) $(feature) ] ; 44 45 local var ; 46 for var in COMMON_ARCH COMMON_DEBUG DEBUG_$(HAIKU_DEBUG_LEVELS) { 47 HOST_$(var)_LOCATE_TARGET 48 = [ FDirName $(HOST_$(var)_LOCATE_TARGET) $(feature) ] ; 49 TARGET_$(var)_LOCATE_TARGET 50 = [ FDirName $(TARGET_$(var)_LOCATE_TARGET) $(feature) ] ; 51 } 52 53 LOCATE_TARGET = [ FDirName $(LOCATE_TARGET) $(feature) ] ; 54 LOCATE_SOURCE = $(LOCATE_TARGET) ; 55 SEARCH_SOURCE = $(SUBDIR) $(LOCATE_SOURCE) 56 $(HOST_COMMON_DEBUG_LOCATE_TARGET) # Also add the standard output 57 $(TARGET_COMMON_DEBUG_LOCATE_TARGET) # dirs for generated sources. 58 ; 59} 60 61rule SubIncludeGPL 62{ 63 # SubInclude rule that can be used to conditionally include GPL licensed 64 # add-ons 65 if $(HAIKU_INCLUDE_GPL_ADDONS) = 1 { 66 SubInclude $(1) ; 67 } 68} 69 70 71# pragma mark - MakeLocate variants 72 73 74rule MakeLocateCommonPlatform 75{ 76 # The file is shared between all target platforms. 77 MakeLocate $(1) : $(COMMON_PLATFORM_LOCATE_TARGET) ; 78} 79 80rule MakeLocatePlatform 81{ 82 # The file is specific for the target platform, but 83 # architecture independent. Usually the right rule for generated 84 # sources, though sometimes sources can be architecture specific. 85 local files = $(1) ; 86 local file ; 87 for file in $(files) { 88 if [ on $(file) return $(PLATFORM) ] = host { 89 MakeLocate $(file) : $(HOST_COMMON_ARCH_LOCATE_TARGET) ; 90 } else { 91 MakeLocate $(file) : $(TARGET_COMMON_ARCH_LOCATE_TARGET) ; 92 } 93 } 94} 95 96rule MakeLocateArch 97{ 98 # The file is platform+architecture specific, but is debug 99 # level independent. This is usually the right rule for generated 100 # architecture specific data or source files. 101 local files = $(1) ; 102 local file ; 103 for file in $(files) { 104 if [ on $(file) return $(PLATFORM) ] = host { 105 MakeLocate $(file) : $(HOST_COMMON_DEBUG_LOCATE_TARGET) ; 106 } else { 107 MakeLocate $(file) : $(TARGET_COMMON_DEBUG_LOCATE_TARGET) ; 108 } 109 } 110} 111 112rule MakeLocateDebug 113{ 114 # The file is platform+architecture+debug level specific. 115 # That's what should be used for compiled code. 116 local files = $(1) ; 117 local file ; 118 for file in $(files) { 119 on $(file) { 120 if $(PLATFORM) = host { 121 MakeLocate $(file) : $(HOST_DEBUG_$(DEBUG)_LOCATE_TARGET) ; 122 } else { 123 MakeLocate $(file) : $(TARGET_DEBUG_$(DEBUG)_LOCATE_TARGET) ; 124 } 125 } 126 } 127} 128 129 130# pragma mark - Deferred SubIncludes 131 132 133# The variable used to collect the deferred SubIncludes. 134HAIKU_DEFERRED_SUB_INCLUDES = ; 135 136rule DeferredSubInclude params : jamfile : scope 137{ 138 # DeferredSubInclude <subdir tokens> [ : <jamfile name> [ : <scope> ] ] ; 139 # 140 # Takes the same directory tokens parameter as SubInclude plus an optional 141 # alternative Jamfile name. The the subdirectory referred to by 142 # <subdir tokens> will be included when ExecuteDeferredSubIncludes is 143 # invoked, i.e. at the end of the root Jamfile. The <jamfile name> parameter 144 # specifies the name of the Jamfile to include. By default it is "Jamfile". 145 # The <scope> parameter can be "global" (default) or "local", specifying 146 # whether the alternative Jamfile name shall also be used for subdirectories. 147 148 HAIKU_DEFERRED_SUB_INCLUDES += "/" $(params) ; 149 if $(jamfile) { 150 SetConfigVar JAMFILE : $(params) : $(jamfile) : $(scope) ; 151 } 152} 153 154rule ExecuteDeferredSubIncludes 155{ 156 # ExecuteDeferredSubIncludes ; 157 # 158 # Performs the deferred SubIncludes scheduled by DeferredSubInclude. 159 160 local tokensList = $(HAIKU_DEFERRED_SUB_INCLUDES) ; 161 while $(tokensList) { 162 # chop off leading "/" 163 tokensList = $(tokensList[2-]) ; 164 165 # get the tokens for the next include 166 local tokens ; 167 while $(tokensList) && $(tokensList[1]) != "/" { 168 tokens += $(tokensList[1]) ; 169 tokensList = $(tokensList[2-]) ; 170 } 171 172 # perform the include 173 if $(tokens) { 174 SubInclude $(tokens) ; 175 } 176 } 177} 178 179rule HaikuSubInclude tokens 180{ 181 # HaikuSubInclude <tokens> ; 182 # 183 # Current subdir relative SubInclude. 184 # <tokens> - subdir tokens specifying the subdirectory to be include 185 # (relative to the current subdir) 186 187 if $(tokens) { 188 SubInclude HAIKU_TOP $(SUBDIR_TOKENS) $(tokens) ; 189 } 190} 191 192 193# pragma mark - Unique IDs/targets 194 195 196# private to NextID; incremented with each NextID invocation 197HAIKU_NEXT_ID = 0 ; 198 199rule NextID 200{ 201 # NextID ; 202 203 local result = $(HAIKU_NEXT_ID:J=) ; 204 HAIKU_NEXT_ID = [ AddNumAbs $(HAIKU_NEXT_ID) : 1 ] ; 205 return $(result) ; 206} 207 208rule NewUniqueTarget basename 209{ 210 # NewUniqueTarget [ basename ] ; 211 212 local id = [ NextID ] ; 213 return $(basename[1]:E=_target:G=unique!target)_$(id) ; 214} 215 216 217# pragma mark - RunCommandLine 218 219 220rule RunCommandLine commandLine 221{ 222 # RunCommandLine <commandLine> 223 # 224 # Creates a pseudo target that, when made by jam, causes the supplied shell 225 # command line to be executed. Elements of <commandLine> with the prefix ":" 226 # are replaced by the rule. After stripping the prefix such a string specifies 227 # a build system target and the finally executed command line will contain 228 # a path to the target instead. 229 # The pseudo target will depend on all targets thus identified. Each 230 # invocation of this rule creates a different pseudo target, which is 231 # returned to the caller. 232 233 # collect the targets in the command line and replace them by $targetX* 234 # variables 235 local substitutedCommandLine ; 236 local targets ; 237 238 local targetVarName = target ; 239 local i ; 240 for i in $(commandLine) { 241 # targets are marked by the ":" prefix 242 local target = [ Match ^:(.*) : $(i) ] ; 243 if $(target) { 244 targets += $(target) ; 245 targetVarName = $(targetVarName)X ; 246 i = "$"$(targetVarName) ; 247 } 248 249 substitutedCommandLine += $(i) ; 250 } 251 252 # define the "run" target 253 local run = [ NewUniqueTarget run ] ; 254 COMMAND_LINE on $(run) = $(substitutedCommandLine) ; 255 NotFile $(run) ; 256 Always $(run) ; 257 Depends $(run) : $(targets) ; 258 RunCommandLine1 $(run) : $(targets) ; 259 260 return $(run) ; 261} 262 263actions RunCommandLine1 { 264 target=target; 265 for t in $(2) ; do 266 target=${target}X 267 eval "${target}=${t}" 268 done 269 $(HOST_ADD_BUILD_COMPATIBILITY_LIB_DIR) 270 "$(COMMAND_LINE)" 271} 272 273 274#pragma mark - DefineBuildProfile 275 276 277rule DefineBuildProfile name : type : path { 278 # DefineBuildProfile <name> : <type> [ : <path> ] 279 # 280 # Makes a build profile known. Build profiles can be used to define 281 # different sets of settings for Haiku images/installations. For each 282 # profile the default actions "build", "update", and "mount" (the latter 283 # only for disks or image types) will be available (i.e. can be specified 284 # as second parameter on the jam command line). They will build an image 285 # or installation, update only given targets, respectively just mount the 286 # image or disk using the bfs_shell. 287 # 288 # <name> - The name of the build profile. 289 # <type> - The type of the build profile. Must be one of "image" (plain 290 # disk image), "anyboot-image" (custom disk image that can be 291 # written to CD or disk device), "cd-image" (ISO CD image), 292 # "vmware-image" (VMware disk image), "disk" (actual partition 293 # or hard disk device), "install" (installation in a directory), 294 # or "custom" (user-defined). 295 # <path> - The path associated with the profile. Depending on the profile 296 # type, this is the path to the disk image/VMware image, hard 297 # disk/partition device, or the installation directory. If the 298 # parameter is omitted, the value of the HAIKU[_VMWARE]_IMAGE_NAME, 299 # HAIKU_IMAGE_DIR, respectively HAIKU_INSTALL_DIR or their default 300 # values will be used instead. 301 302 if [ on $(name) return $(HAIKU_BUILD_PROFILE_SPECIFIED) ] { 303 Exit "ERROR: Build profile \"$(name)\" defined twice!" ; 304 } 305 HAIKU_BUILD_PROFILE_SPECIFIED on $(name) = 1 ; 306 307 if ! $(HAIKU_BUILD_PROFILE) || $(HAIKU_BUILD_PROFILE) != $(name) { 308 return ; 309 } 310 311 HAIKU_BUILD_PROFILE_DEFINED = 1 ; 312 313 # split path into directory path and name 314 local targetDir = $(path:D) ; 315 local targetName = $(path:BS) ; 316 317 # Jam's path splitting produces an empty string, if a component doesn't 318 # exist. That's a little unhandy for checks. 319 if $(targetDir) = "" { 320 targetDir = ; 321 } 322 if $(targetName) = "" { 323 targetName = ; 324 } 325 326 targetDir ?= $(HAIKU_IMAGE_DIR) ; 327 targetDir ?= $(HAIKU_DEFAULT_IMAGE_DIR) ; 328 329 # "disk" is "image" with HAIKU_DONT_CLEAR_IMAGE 330 if $(type) = "disk" { 331 type = "image" ; 332 HAIKU_DONT_CLEAR_IMAGE = 1 ; 333 } 334 335 local buildTarget ; 336 local startOffset ; 337 338 switch $(type) { 339 case "anyboot-image" : { 340 targetName ?= $(HAIKU_ANYBOOT_NAME) ; 341 targetName ?= $(HAIKU_DEFAULT_ANYBOOT_NAME) ; 342 HAIKU_ANYBOOT_DIR = $(targetDir) ; 343 HAIKU_ANYBOOT_NAME = $(targetName) ; 344 buildTarget = haiku-anyboot-image ; 345 } 346 347 case "cd-image" : { 348 targetName ?= $(HAIKU_CD_NAME) ; 349 targetName ?= $(HAIKU_DEFAULT_CD_NAME) ; 350 HAIKU_CD_DIR = $(targetDir) ; 351 HAIKU_CD_NAME = $(targetName) ; 352 buildTarget = haiku-cd ; 353 } 354 355 case "image" : { 356 targetName ?= $(HAIKU_IMAGE_NAME) ; 357 targetName ?= $(HAIKU_DEFAULT_IMAGE_NAME) ; 358 HAIKU_IMAGE_DIR = $(targetDir) ; 359 HAIKU_IMAGE_NAME = $(targetName) ; 360 buildTarget = haiku-image ; 361 } 362 363 case "vmware-image" : { 364 targetName ?= $(HAIKU_VMWARE_IMAGE_NAME) ; 365 targetName ?= $(HAIKU_DEFAULT_VMWARE_IMAGE_NAME) ; 366 HAIKU_IMAGE_DIR = $(targetDir) ; 367 HAIKU_VMWARE_IMAGE_NAME = $(targetName) ; 368 buildTarget = haiku-vmware-image ; 369 startOffset = --start-offset 65536 ; 370 } 371 372 case "install" : { 373 path ?= $(HAIKU_INSTALL_DIR) ; 374 path ?= $(HAIKU_DEFAULT_INSTALL_DIR) ; 375 HAIKU_INSTALL_DIR = $(path) ; 376 buildTarget = install-haiku ; 377 } 378 379 case "custom" : { 380 # user-defined -- don't do anything 381 return 1 ; 382 } 383 384 case * : { 385 Exit "Unsupported build profile type: " $(type) ; 386 } 387 } 388 389 switch $(HAIKU_BUILD_PROFILE_ACTION) { 390 case "build" : { 391 JAM_TARGETS = $(buildTarget) ; 392 } 393 394 case "update" : { 395 JAM_TARGETS = $(buildTarget) ; 396 SetUpdateHaikuImageOnly 1 ; 397 HAIKU_INCLUDE_IN_IMAGE on $(HAIKU_BUILD_PROFILE_PARAMETERS) = 1 ; 398 } 399 400 case "update-all" : { 401 JAM_TARGETS = $(buildTarget) ; 402 SetUpdateHaikuImageOnly 1 ; 403 HAIKU_INCLUDE_IN_IMAGE = 1 ; 404 } 405 406 case "mount" : { 407 if $(type) in "install" "cd-image" { 408 Exit "Build action \"mount\" not supported for profile type" 409 "\"$(type)\"." ; 410 } 411 412 local commandLine = :<build>bfs_shell $(startOffset) 413 \"$(targetName:D=$(targetDir))\" ; 414 JAM_TARGETS = [ RunCommandLine $(commandLine) ] ; 415 } 416 } 417 418 return 1 ; 419} 420 421 422# pragma mark - Build Features 423 424 425rule FIsBuildFeatureEnabled feature 426{ 427 # FIsBuildFeatureEnabled <feature> ; 428 # Returns whether the given build feature <feature> is enabled (if so: "1", 429 # if not: empty list). 430 # 431 # <feature> - The name of the build feature (all lower case). 432 433 if $(feature) in $(HAIKU_BUILD_FEATURES) { 434 return 1 ; 435 } 436 437 return ; 438} 439 440 441rule FMatchesBuildFeatures specification 442{ 443 # FMatchesBuildFeatures <specification> ; 444 # Returns whether the given build feature specification <specification> 445 # holds. <specification> consists of positive and negative build feature 446 # conditions. Conditions can be individual list elements and multiple 447 # conditions can be joined, separated by ",", in a single list element. The 448 # effect is the same; they are considered as single set of conditions. 449 # A positive condition does not start with a "!". It holds when the build 450 # feature named by the element is enabled. 451 # A negative condition starts with a "!". It holds when the build feature 452 # named by the string resulting from removing the leading "!" is not 453 # enabled. 454 # <specification> holds when it is not empty and 455 # * none of the negative conditions it contains hold and 456 # * if it contains any positive conditions, at least one one of them holds. 457 # 458 # <specification> - The build feature specification. A list of individual 459 # conditions or conditions joined by ",". 460 461 local splitSpecification ; 462 local element ; 463 for element in $(specification) { 464 splitSpecification += [ FSplitString $(element) : "," ] ; 465 } 466 return [ FSetConditionsHold $(splitSpecification) 467 : $(HAIKU_BUILD_FEATURES) ] ; 468} 469 470 471rule FFilterByBuildFeatures list 472{ 473 # FFilterByBuildFeatures <list> ; 474 # Filters the list annotated by build feature specifications and returns the 475 # resulting list. The list can be annotated in two different ways: 476 # * A single list element can be annotated by appending "@<specification>" 477 # to it, with <specification> being a build feature specification (a 478 # single comma-separated string). The element appears in the resulting 479 # list, only if <specification> holds. 480 # * A sublist can be annotated by enclosing it in "<specification> @{" (two 481 # separate list elements) and "}@", with <specification> being a build 482 # feature specification (a single comma-separated string). The enclosed 483 # sublist appears in the resulting list, only if <specification> holds. 484 # The sublist annotations can be nested. The annotations themselves don't 485 # appear in the resulting list. 486 # 487 # <list> - A list annotated with build feature specifications. 488 489 local filteredList ; 490 491 # Since we must look ahead one element to be able to decide whether an 492 # element is a regular list element or a features specification for a 493 # subsequent "@{". Hence we always process an element other than "@{" and 494 # "}@" in the next iteration. We append a dummy element to the list so we 495 # don't need special handling for the last element. 496 local evaluationStack = 1 ; 497 local previousElement ; 498 local element ; 499 for element in $(list) dummy { 500 local stackTop = $(evaluationStack[1]) ; 501 local processElement = $(previousElement) ; 502 switch $(element) { 503 case }@ : 504 { 505 # Pop the topmost specification off the stack. 506 evaluationStack = $(evaluationStack[2-]) ; 507 if ! $(evaluationStack) { 508 Exit "FFilterByBuildFeatures: Unbalanced @( in: " $(list) ; 509 } 510 511 processElement = $(previousElement) ; 512 previousElement = ; 513 } 514 case @{ : 515 { 516 if ! $(previousElement) { 517 Exit "FFilterByBuildFeatures: No feature specification" 518 "after )@ in: " $(list) ; 519 } 520 521 if $(evaluationStack[1]) = 1 522 && [ FMatchesBuildFeatures $(previousElement) ] { 523 evaluationStack = 1 $(evaluationStack) ; 524 } else { 525 evaluationStack = 0 $(evaluationStack) ; 526 } 527 528 processElement = ; 529 previousElement = ; 530 } 531 case * : 532 { 533 processElement = $(previousElement) ; 534 previousElement = $(element) ; 535 } 536 } 537 538 if $(processElement) && $(stackTop) = 1 { 539 local splitElement = [ Match "(.*)@([^@]*)" : $(processElement) ] ; 540 if $(splitElement) { 541 if [ FMatchesBuildFeatures $(splitElement[2]) ] { 542 filteredList += $(splitElement[1]) ; 543 } 544 } else { 545 filteredList += $(processElement) ; 546 } 547 } 548 } 549 550 if $(evaluationStack[2-]) { 551 Exit "FFilterByBuildFeatures: Unbalanced )@ in: " $(list) ; 552 } 553 554 return $(filteredList) ; 555} 556 557 558rule EnableBuildFeatures features : specification 559{ 560 # EnableBuildFeatures <features> : <specification> ; 561 # Enables the build features <features>, if the build features specification 562 # <specification> holds. If <specification> is omitted, the features are 563 # enabled unconditionally. 564 # The rule enables a build feature by adding its given lower case name to 565 # the build variable HAIKU_BUILD_FEATURES and defining a build variable 566 # HAIKU_BUILD_FEATURE_<FEATURE>_ENABLED (<FEATURE> being the upper case name 567 # of the build feature) to "1". 568 # 569 # <features> - A list of build feature names (lower case). 570 # <specification> - An optional build features specification (cf. 571 # FMatchesBuildFeatures). 572 573 if ! $(specification) 574 || [ FMatchesBuildFeatures $(specification) 575 : $(HAIKU_BUILD_FEATURES) ] { 576 local feature ; 577 for feature in $(features) { 578 HAIKU_BUILD_FEATURES += $(feature) ; 579 HAIKU_BUILD_FEATURE_$(feature:U)_ENABLED = 1 ; 580 } 581 } 582} 583