1rule FSameTargetWithPrependedGrist 2{ 3 # SameTargetWithPrependedGrist <target> : <grist to prepend> ; 4 # 5 local target = $(1) ; 6 local gristToPrepend = $(2) ; 7 local grist = $(target:G) ; 8 9 if $(grist) { 10 grist = $(gristToPrepend)!$(grist) ; 11 } else { 12 grist = $(gristToPrepend) ; 13 } 14 15 return $(target:G=$(grist)) ; 16} 17 18rule InitScript 19{ 20 # Note: The script must have been LOCATEd before. 21 local script = $(1) ; 22 local initScript 23 = [ FSameTargetWithPrependedGrist $(script) : init-script ] ; 24 25 if ! [ on $(script) return $(__is_initialized) ] { 26 __is_initialized on $(script) = true ; 27 28 MakeLocate $(initScript) : [ on $(script) return $(LOCATE) ] ; 29 Always $(initScript) ; 30 Depends $(script) : $(initScript) ; 31 32 InitScript1 $(initScript) ; 33 } 34 35 return $(initScript) ; 36} 37 38actions InitScript1 39{ 40 $(RM) $(1) 41 touch $(1) 42} 43 44rule AddVariableToScript script : variable : value 45{ 46 # AddVariableToScript <script> : <variable> : <value> ; 47 48 # interpret an empty variable value as empty string 49 if ! $(value) { 50 value = "" ; 51 } 52 53 InitScript $(script) ; 54 55 VARIABLE_DEFS on $(script) += "echo $(variable)=\\\"$(value[1])\\\" >> " ; 56 57 # if the value is an array, add the other array elements 58 value = $(value[2-]) ; 59 while $(value) { 60 VARIABLE_DEFS on $(script) 61 += "echo $(variable)=\\\" \\\$$(variable) $(value[1])\\\" >> " ; 62 value = $(value[2-]) ; 63 } 64 65 AddVariableToScript1 $(script) ; 66} 67 68actions together AddVariableToScript1 69{ 70 $(VARIABLE_DEFS)$(1); 71} 72 73rule AddTargetVariableToScript 74{ 75 # AddTargetVariableToScript <script> : <target> [ : <variable> ] ; 76 # 77 local script = $(1) ; 78 local target = $(2) ; 79 local variable = $(3:E=$(target:BS)) ; 80 81 InitScript $(script) ; 82 83 # That's not completely save, if one has more than on target with the 84 # same base name. A unique pseudo target would have to be introduced 85 # to do it more correctly. 86 VARIABLE_NAME($(target:BS)) on $(script) = $(variable) ; 87 88 Depends $(script) : $(target) ; 89 AddTargetVariableToScript1 $(script) : $(target) ; 90} 91 92actions AddTargetVariableToScript1 93{ 94 echo "$(VARIABLE_NAME($(2:BS)))=\"$(2)\"" >> $(1) 95} 96 97 98#pragma mark - 99 100rule AddDirectoryToContainer container : directoryTokens 101{ 102 # AddDirectoryToContainer <container> : <directoryTokens> 103 104 local containerGrist = [ on $(container) return $(HAIKU_CONTAINER_GRIST) ] ; 105 local directory = [ FDirName $(directoryTokens) ] ; 106 directory = $(directory:G=$(containerGrist)) ; 107 108 if ! [ on $(directory) return $(__is_on_image) ] { 109 HAIKU_INSTALL_DIRECTORIES on $(container) += $(directory) ; 110 __is_on_image on $(directory) = true ; 111 DIRECTORY_TOKENS on $(directory) = $(directoryTokens) ; 112 NotFile $(directory) ; 113 114 # mark the parent dir as not to be created 115 local parent = [ FReverse $(directoryTokens) ] ; 116 parent = [ FReverse $(parent[2-]) ] ; 117 if $(parent) { 118 parent = [ FDirName $(parent) ] ; 119 parent = $(parent:G=$(containerGrist)) ; 120 DONT_CREATE on $(parent) = true ; 121 } 122 } 123 124 return $(directory) ; 125} 126 127rule FilterContainerUpdateTargets targets : filterVariable 128{ 129 # FilterContainerUpdateTargets targets : filterVariable 130 131 local filteredTargets ; 132 local target ; 133 for target in $(targets) { 134 if [ on $(target) return $($(filterVariable)) ] { 135 filteredTargets += $(target) ; 136 } 137 } 138 return $(filteredTargets) ; 139} 140 141rule AddFilesToContainer container : directoryTokens : targets : destName 142{ 143 # AddFilesToContainer <container> : <directoryTokens> : <targets> 144 # [ : dest name ] 145 # 146 local directory = [ AddDirectoryToContainer $(container) 147 : $(directoryTokens) ] ; 148 local containerGrist = [ on $(container) return $(HAIKU_CONTAINER_GRIST) ] ; 149 150 # If the image shall only be updated, we filter out all targets not marked 151 # accordingly. 152 if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] { 153 local filterVar 154 = [ on $(container) return $(HAIKU_INCLUDE_IN_CONTAINER_VAR) ] ; 155 if $(filterVar) { 156 targets = [ FilterContainerUpdateTargets $(targets) 157 : $(filterVar) ] ; 158 } 159 } 160 161 # We create a unique dummy target per target to install. 162 local installTargetsVar 163 = [ on $(container) return $(HAIKU_INSTALL_TARGETS_VAR) ] ; 164 local target ; 165 for target in $(targets) { 166 local name ; 167 if $(destName) { 168 name = $(destName) ; 169 } else { 170 name = $(target:G=:D=) ; 171 } 172 173 local destTarget = $(name:G=$(containerGrist)__$(directory:G=)) ; 174 TARGET on $(destTarget) = $(target) ; 175 INSTALL_DIR on $(destTarget) = $(directory) ; 176 $(installTargetsVar) on $(target) += $(destTarget) ; 177 TARGETS_TO_INSTALL on $(directory) += $(destTarget) ; 178 } 179} 180 181rule AddSymlinkToContainer container : directoryTokens : linkTarget : linkName 182{ 183 # AddSymlinkToContainer <container> : <directory> : <link target> 184 # [ : <link name> ] ; 185 # 186 187 # If the image shall only be updated, we don't add any symlinks. 188 if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] { 189 return ; 190 } 191 192 local directory = [ AddDirectoryToContainer $(container) 193 : $(directoryTokens) ] ; 194 195 if ! $(linkName) { 196 local path = [ FReverse [ FSplitPath $(linkTarget) ] ] ; 197 linkName = $(path[1]) ; 198 } 199 200 local link = $(directory)/$(linkName) ; 201 SYMLINK_TARGET on $(link) = $(linkTarget) ; 202 SYMLINKS_TO_INSTALL on $(directory) += $(link) ; 203} 204 205rule CopyDirectoryToContainer container : directoryTokens : sourceDirectory 206 : targetDirectoryName : excludePatterns : alwaysUpdate 207{ 208 # CopyDirectoryToContainer <container> : <directoryTokens> 209 # : <sourceDirectory> : <targetDirectoryName> : <excludePatterns> 210 # : <alwaysUpdate> ; 211 # 212 213 # If the image shall only be updated, we don't copy any directories 214 if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] 215 && ! $(alwaysUpdate) { 216 return ; 217 } 218 219 if ! $(targetDirectoryName) { 220 local path = [ FReverse [ FSplitPath $(sourceDirectory) ] ] ; 221 targetDirectoryName = $(path[1]) ; 222 } 223 224 local directory = [ AddDirectoryToContainer $(container) 225 : $(directoryTokens) $(targetDirectoryName) ] ; 226 227 local targetDir = $(directory)/-/$(sourceDirectory) ; 228 EXCLUDE_PATTERNS on $(targetDir) = $(excludePatterns) ; 229 SOURCE_DIRECTORY on $(targetDir) = $(sourceDirectory) ; 230 TARGET_DIRECTORY on $(targetDir) = $(directory) ; 231 DIRECTORIES_TO_INSTALL on $(directory) += $(targetDir) ; 232} 233 234rule UnzipArchiveToContainer container : directoryTokens : zipFile 235{ 236 # UnzipArchiveToContainer <container> : <directory> : <zipFile> ] ; 237 # 238 239 local directory = [ AddDirectoryToContainer $(container) 240 : $(directoryTokens) ] ; 241 242 ZIP_FILES_TO_INSTALL on $(directory) += $(zipFile) ; 243} 244 245rule AddDriversToContainer container : relativeDirectoryTokens : targets 246{ 247 # AddDriversToContainer <container> : <relative directory> : <targets> ; 248 # 249 local directoryTokens = beos system add-ons kernel drivers dev 250 $(relativeDirectoryTokens) ; 251 252 AddFilesToContainer $(container) : beos system add-ons kernel drivers bin 253 : $(targets) ; 254 255 # If the image shall only be updated, we don't add any symlinks. 256 if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] { 257 return ; 258 } 259 260 # get the relative symlink path prefix 261 local linkPrefix = ; 262 for i in $(relativeDirectoryTokens) { 263 linkPrefix += .. ; 264 } 265 linkPrefix += .. bin ; 266 267 # add the symlinks 268 local name ; 269 for name in $(targets:BS) { 270 AddSymlinkToContainer $(container) : $(directoryTokens) 271 : [ FDirName $(linkPrefix) $(name) ] : $(name) ; 272 } 273} 274 275rule AddDriverRegistrationToContainer container : relativeDirectoryTokens 276 : target : links 277{ 278 # AddDriverRegistrationToContainer <container> : <directory> 279 # : <link target> : <link names> ] ; 280 # 281 local directoryTokens = beos system add-ons kernel registration 282 $(relativeDirectoryTokens) ; 283 284 # get the relative symlink path prefix 285 local linkPrefix = ; 286 for i in $(relativeDirectoryTokens) { 287 linkPrefix += .. ; 288 } 289 linkPrefix += .. drivers bin ; 290 291 # add the symlink 292 AddSymlinkToContainer $(container) : $(directoryTokens) 293 : [ FDirName $(linkPrefix) $(target:BS) ] : $(links) ; 294} 295 296rule AddBootModuleSymlinksToContainer container : targets 297{ 298 # AddBootModuleSymlinksToContainer <container> : <targets> ; 299 # 300 301 # If the image shall only be updated, we don't add any symlinks. 302 if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] { 303 return ; 304 } 305 306 # add the symlinks 307 local installTargetsVar 308 = [ on $(container) return $(HAIKU_INSTALL_TARGETS_VAR) ] ; 309 local target ; 310 for target in $(targets) { 311 # Symlink to the first place where the target has been installed. 312 local destTarget = [ on $(target) return $($(installTargetsVar)[1]) ] ; 313 local installDir = [ on $(destTarget) return $(INSTALL_DIR) ] ; 314 315 if ! $(installDir) { 316 Echo "ERROR: AddBootModuleSymlinksToContainer: Can't create a " 317 "symlink to target" \"$(target)"\"." ; 318 Exit "ERROR: Add*ToContainer has not been invoked for it yet." ; 319 } 320 321 local name = $(target:BS) ; 322 local linkTarget = [ FDirName /boot $(installDir:G=) $(name) ] ; 323 324 AddSymlinkToContainer $(container) : beos system add-ons kernel boot 325 : $(linkTarget) : $(name) ; 326 } 327} 328 329 330rule CreateContainerMakeDirectoriesScript container : script 331{ 332 MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ; 333 Always $(script) ; 334 335 local initScript = [ InitScript $(script) ] ; 336 337 local scriptBody 338 = [ FSameTargetWithPrependedGrist $(script) : script-body ] ; 339 LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ; 340 Depends $(scriptBody) : $(initScript) ; 341 Depends $(script) : $(scriptBody) ; 342 343 # collect the directories to create 344 local dirsToCreate ; 345 local directories = [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] ; 346 local dir ; 347 for dir in $(directories) { 348 if ! [ on $(dir) return $(DONT_CREATE) ] { 349 dirsToCreate += $(dir) ; 350 } 351 } 352 353 # If the image shall only be updated, we don't create directories. 354 if $(dirsToCreate) 355 && ! [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] { 356 Depends $(scriptBody) : $(dirsToCreate) ; 357 CreateContainerMakeDirectoriesScript1 $(scriptBody) : $(dirsToCreate) ; 358 359 # For directories with attributes, we convert those the specified 360 # resource files to files with attributes and add commands to the script 361 # adding the attributes to the directories. 362 for dir in $(directories) { 363 local resourceFiles = [ on $(dir) return $(ATTRIBUTE_FILES) ] ; 364 if $(resourceFiles) { 365 local dirTokens = [ on $(dir) return $(DIRECTORY_TOKENS) ] ; 366 367 # translate resources file to file with attributes 368 local attributeFile = $(script)-attributes-$(dirTokens:J=-) ; 369 ResAttr $(attributeFile) : $(resourceFiles) ; 370 371 # use a unique dummy target for this file, on which we 372 # can define the TARGET_DIR variable 373 local dummyTarget = $(script)-attributes-dummy-$(dir:G=) ; 374 NotFile $(dummyTarget) ; 375 TARGET_DIR on $(dummyTarget) = $(dir:G=) ; 376 377 Depends $(dummyTarget) : $(initScript) $(attributeFile) ; 378 Depends $(script) : $(dummyTarget) ; 379 380 AppendToContainerMakeDirectoriesScriptAttributes $(dummyTarget) 381 : $(initScript) $(attributeFile) ; 382 } 383 } 384 } 385} 386 387actions piecemeal CreateContainerMakeDirectoriesScript1 388{ 389 echo \$mkdir -p "\"\${tPrefix}$(2:G=)\"" >> $(1) 390} 391 392actions AppendToContainerMakeDirectoriesScriptAttributes 393{ 394 echo \$copyAttrs "\"\${sPrefix}$(2[2])\"" \ 395 "\"\${tPrefix}$(TARGET_DIR)\"" >> $(2[1]) 396} 397 398rule CreateContainerCopyFilesScript container : script 399{ 400 MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ; 401 Always $(script) ; 402 403 local initScript = [ InitScript $(script) ] ; 404 405 local scriptBody 406 = [ FSameTargetWithPrependedGrist $(script) : script-body ] ; 407 LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ; 408 Depends $(scriptBody) : $(initScript) ; 409 Depends $(script) : $(scriptBody) ; 410 411 local dir ; 412 for dir in [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] { 413 # filter the targets that shall be renamed; they have to be copied 414 # individually 415 local destTargets = [ on $(dir) return $(TARGETS_TO_INSTALL) ] ; 416 local remainingTargets ; 417 local destTarget ; 418 for destTarget in $(destTargets) { 419 local target = [ on $(destTarget) return $(TARGET) ] ; 420 local name = $(destTarget:BS) ; 421 if $(name) != $(target:BS) { 422 # use a unique dummy target for this file, on which we 423 # can define the TARGET_DIR variable 424 local dummyTarget = $(script)-dummy-$(dir:G=)-$(target) ; 425 NotFile $(dummyTarget) ; 426 TARGET_DIR on $(dummyTarget) = $(dir:G=) ; 427 INSTALL_TARGET_NAME on $(dummyTarget) = $(name) ; 428 429 Depends $(dummyTarget) : $(initScript) $(target) ; 430 Depends $(script) : $(dummyTarget) ; 431 432 AppendToContainerCopyFilesScriptSingleFile $(dummyTarget) 433 : $(initScript) $(target) ; 434 } else { 435 remainingTargets += $(target) ; 436 } 437 } 438 targets = $(remainingTargets) ; 439 440 if $(targets) { 441 # use a unique dummy target for this directory, on which we 442 # can define the TARGET_DIR variable 443 local dummyTarget = $(script)-dummy-$(dir:G=) ; 444 NotFile $(dummyTarget) ; 445 TARGET_DIR on $(dummyTarget) = $(dir:G=) ; 446 447 Depends $(dummyTarget) : $(initScript) $(targets) ; 448 Depends $(script) : $(dummyTarget) ; 449 450 OUTPUT_SCRIPT on $(dummyTarget) = $(initScript) ; 451 AppendToContainerCopyFilesScript $(dummyTarget) : $(targets) ; 452 } 453 454 local symlinks = [ on $(dir) return $(SYMLINKS_TO_INSTALL) ] ; 455 local symlink ; 456 for symlink in $(symlinks) { 457 NotFile $(symlink) ; 458 459 Depends $(script) : $(symlink) ; 460 Depends $(symlink) : $(initScript) ; 461 462 AddSymlinkToContainerCopyFilesScript $(symlink) : $(initScript) ; 463 } 464 465 local targetDirs = [ on $(dir) return $(DIRECTORIES_TO_INSTALL) ] ; 466 local targetDir ; 467 for targetDir in $(targetDirs) { 468 NotFile $(targetDir) ; 469 470 Depends $(script) : $(targetDir) ; 471 Depends $(targetDir) : $(initScript) ; 472 473 AddDirectoryToContainerCopyFilesScript $(targetDir) : $(initScript) ; 474 } 475 } 476} 477 478actions piecemeal AppendToContainerCopyFilesScript bind OUTPUT_SCRIPT 479{ 480 echo \$cp "\"\${sPrefix}$(2)\"" "\"\${tPrefix}$(TARGET_DIR)\"" >> $(OUTPUT_SCRIPT) 481} 482 483actions AppendToContainerCopyFilesScriptSingleFile 484{ 485 echo \$cp "\"\${sPrefix}$(2[2])\"" \ 486 "\"\${tPrefix}$(TARGET_DIR)/$(INSTALL_TARGET_NAME)\"" >> $(2[1]) 487} 488 489actions AddSymlinkToContainerCopyFilesScript 490{ 491 echo \$ln -sfn "\"$(SYMLINK_TARGET)\"" "\"\${tPrefix}$(1:G=)\"" >> $(2[1]) 492} 493 494actions AddDirectoryToContainerCopyFilesScript 495{ 496 echo \$cp -r $(EXCLUDE_PATTERNS) "\"\${sPrefix}$(SOURCE_DIRECTORY)/.\"" \ 497 "\"\${tPrefix}$(TARGET_DIRECTORY:G=)\"" >> $(2[1]) 498} 499 500 501rule CreateContainerUnzipFilesScript container : script 502{ 503 MakeLocate $(script) : $(HAIKU_OUTPUT_DIR) ; 504 Always $(script) ; 505 506 local initScript = [ InitScript $(script) ] ; 507 508 local scriptBody 509 = [ FSameTargetWithPrependedGrist $(script) : script-body ] ; 510 LOCATE on $(scriptBody) = [ on $(script) return $(LOCATE) ] ; 511 Depends $(scriptBody) : $(initScript) ; 512 Depends $(script) : $(scriptBody) ; 513 514 local dir ; 515 for dir in [ on $(container) return $(HAIKU_INSTALL_DIRECTORIES) ] { 516 local zipFiles = [ on $(dir) return $(ZIP_FILES_TO_INSTALL) ] ; 517 local zipFile ; 518 for zipFile in $(zipFiles) { 519 # use a unique dummy target for this file, on which we 520 # can define the TARGET_DIR variable 521 local dummyTarget = $(script)-dummy-$(dir:G=)-$(zipFile) ; 522 NotFile $(dummyTarget) ; 523 TARGET_DIR on $(dummyTarget) = $(dir:G=) ; 524 525 Depends $(dummyTarget) : $(initScript) $(zipFile) ; 526 Depends $(script) : $(dummyTarget) ; 527 528 AddUnzipFileToContainerUnzipFilesScript $(dummyTarget) 529 : $(initScript) $(zipFile) ; 530 } 531 } 532} 533 534actions AddUnzipFileToContainerUnzipFilesScript 535{ 536 echo unzipFile "\"$(2[2])\"" "\"$(TARGET_DIR)\"" >> $(2[1]) 537} 538 539 540#pragma mark - Haiku Image rules 541 542rule SetUpdateHaikuImageOnly flag 543{ 544 HAIKU_CONTAINER_UPDATE_ONLY on $(HAIKU_IMAGE_CONTAINER_NAME) = $(flag) ; 545} 546 547rule IsUpdateHaikuImageOnly 548{ 549 on $(HAIKU_IMAGE_CONTAINER_NAME) return $(HAIKU_CONTAINER_UPDATE_ONLY) ; 550} 551 552rule AddDirectoryToHaikuImage directoryTokens : attributeFiles 553{ 554 # AddDirectoryToHaikuImage <directoryTokens> 555 556 local dir = [ AddDirectoryToContainer $(HAIKU_IMAGE_CONTAINER_NAME) 557 : $(directoryTokens) ] ; 558 559 if $(attributeFiles) { 560 SEARCH on $(attributeFiles) 561 += [ FDirName $(HAIKU_TOP) data image_directories ] ; 562 ATTRIBUTE_FILES on $(dir) += $(attributeFiles) ; 563 } 564 565 return $(dir) ; 566} 567 568rule AddFilesToHaikuImage directory : targets : destName 569{ 570 # AddFilesToHaikuImage <directory> : <targets> [ : dest name ] 571 572 AddFilesToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(directory) 573 : $(targets) : $(destName) ; 574} 575 576rule AddSymlinkToHaikuImage directoryTokens : linkTarget : linkName 577{ 578 # AddSymlinkToHaikuImage <directory> : <link target> [ : <link name> ] ; 579 580 AddSymlinkToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(directoryTokens) 581 : $(linkTarget) : $(linkName) ; 582} 583 584rule CopyDirectoryToHaikuImage directoryTokens : sourceDirectory 585 : targetDirectoryName : excludePatterns : alwaysUpdate 586{ 587 CopyDirectoryToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(directoryTokens) 588 : $(sourceDirectory) : $(targetDirectoryName) : $(excludePatterns) 589 : $(alwaysUpdate) ; 590} 591 592rule AddSourceDirectoryToHaikuImage dirTokens : alwaysUpdate 593{ 594 # AddSourceDirectoryToHaikuImage <dirTokens> : <alwaysUpdate> ; 595 596 CopyDirectoryToHaikuImage home HaikuSources 597 : [ FDirName $(HAIKU_TOP) $(dirTokens) ] 598 : : -x .svn : $(alwaysUpdate) ; 599} 600 601rule AddHeaderDirectoryToHaikuImage dirTokens : dirName : alwaysUpdate 602{ 603 # AddHeaderDirectoryToHaikuImage <dirTokens> : [ <dirName> ] 604 # : <alwaysUpdate> ; 605 606 CopyDirectoryToHaikuImage develop headers 607 : [ FDirName $(HAIKU_TOP) headers $(dirTokens) ] 608 : $(dirName) : -x .svn : $(alwaysUpdate) ; 609} 610 611rule UnzipArchiveToHaikuImage dirTokens : zipFile : alwaysUpdate 612{ 613 # UnzipArchiveToHaikuImage <dirTokens> : <zipFile> : <alwaysUpdate> ; 614 615 # If the image shall only be updated, we unzip only, if explicitely 616 # requested. 617 if ! [ IsUpdateHaikuImageOnly ] || $(alwaysUpdate) { 618 UnzipArchiveToContainer $(HAIKU_IMAGE_CONTAINER_NAME) : $(dirTokens) 619 : $(zipFile) ; 620 } 621} 622 623rule AddDriversToHaikuImage relativeDirectoryTokens : targets 624{ 625 # AddDriversToHaikuImage <relative directory> : <targets> ; 626 627 AddDriversToContainer $(HAIKU_IMAGE_CONTAINER_NAME) 628 : $(relativeDirectoryTokens) : $(targets) ; 629} 630 631rule AddDriverRegistrationToHaikuImage relativeDirectoryTokens : target : links 632{ 633 # AddDriverRegistrationToHaikuImage <directory> : <link target> : <link names> ] ; 634 635 AddDriverRegistrationToContainer $(HAIKU_IMAGE_CONTAINER_NAME) 636 : $(relativeDirectoryTokens) : $(target) : $(links) ; 637} 638 639rule AddBootModuleSymlinksToHaikuImage targets 640{ 641 # AddBootModuleSymlinksToHaikuImage <targets> ; 642 643 AddBootModuleSymlinksToContainer $(HAIKU_IMAGE_CONTAINER_NAME) 644 : $(targets) ; 645} 646 647rule AddOptionalHaikuImagePackages packages 648{ 649 HAIKU_OPTIONAL_PACKAGE_ADDED on $(packages) = 1 ; 650} 651 652rule IsOptionalHaikuImagePackageAdded package 653{ 654 if [ on $(package) return $(HAIKU_OPTIONAL_PACKAGE_ADDED) ] { 655 return 1 ; 656 } 657 658 return $(HAIKU_ADD_ALL_OPTIONAL_PACKAGES) ; 659} 660 661rule OptionalPackageDependencies package : dependencies 662{ 663 if [ IsOptionalHaikuImagePackageAdded $(package) ] { 664 AddOptionalHaikuImagePackages $(dependencies) ; 665 } 666} 667 668rule InstallOptionalHaikuImagePackage package : url : dirTokens 669{ 670 # download zip file 671 local zipFile = $(package:G=download).zip ; 672 MakeLocate $(zipFile) : $(HAIKU_DOWNLOAD_DIR) ; 673 DownloadFile $(zipFile) : $(url) ; 674 675 # unzip onto image 676 UnzipArchiveToHaikuImage $(dirTokens) : $(zipFile) ; 677} 678 679rule AddEntryToHaikuImageUserGroupFile file : entry 680{ 681 local allEntries = [ on $(file) return $(HAIKU_IMAGE_USER_GROUP_ENTRIES) ] ; 682 683 if $(allEntries) { 684 allEntries = $(allEntries)|$(entry) ; 685 } else { 686 allEntries = $(entry) ; 687 688 Always $(file) ; 689 MakeLocate $(file) : $(HAIKU_COMMON_PLATFORM_OBJECT_DIR) ; 690 BuildHaikuImageUserGroupFile $(file) ; 691 AddFilesToHaikuImage beos etc : $(file) ; 692 } 693 694 HAIKU_IMAGE_USER_GROUP_ENTRIES on $(file) = $(allEntries) ; 695} 696 697actions BuildHaikuImageUserGroupFile 698{ 699 echo "$(HAIKU_IMAGE_USER_GROUP_ENTRIES)" | tr '|' '\n' > $(1) 700} 701 702rule AddUserToHaikuImage user : uid : gid : home : shell : realName 703{ 704 if ! $(user) || ! $(uid) || ! $(gid) || ! $(home) { 705 Exit "Invalid haiku user specification passed to AddUserToHaikuImage." ; 706 } 707 708 local entry 709 = $(user):x:$(uid):$(gid):$(realName:E=$(user)):$(home):$(shell:E="") ; 710 711 AddEntryToHaikuImageUserGroupFile <haiku-image>passwd : $(entry) ; 712} 713 714rule AddGroupToHaikuImage group : gid : members 715{ 716 if ! $(group) || ! $(gid) { 717 Exit "Invalid haiku group specification passed to" 718 "AddGroupToHaikuImage." ; 719 } 720 721 local entry = $(group):x:$(gid):$(members:J=,:E) ; 722 723 AddEntryToHaikuImageUserGroupFile <haiku-image>group : $(entry) ; 724} 725 726rule AddOptionalPackageDescriptionToHaikuImage file : searchPath 727{ 728 if $(searchPath) { 729 SEARCH on $(file) = [ FDirName $(searchPath) ] ; 730 } 731 732 HAIKU_IMAGE_OPTIONAL_PACKAGE_DESCRIPTIONS += $(file) ; 733} 734 735rule AddLicenseToHaikuImage file : name : searchPath 736{ 737 if $(searchPath) { 738 SEARCH on $(file) = [ FDirName $(searchPath) ] ; 739 } 740 741 if $(name) && $(file:BS) = $(name) { 742 name = ; 743 } 744 745 AddFilesToHaikuImage beos etc licenses : $(file) : $(name) ; 746} 747 748 749rule CreateHaikuImageMakeDirectoriesScript script 750{ 751 CreateContainerMakeDirectoriesScript $(HAIKU_IMAGE_CONTAINER_NAME) 752 : $(script) ; 753} 754 755rule CreateHaikuImageCopyFilesScript script 756{ 757 CreateContainerCopyFilesScript $(HAIKU_IMAGE_CONTAINER_NAME) : $(script) ; 758} 759 760rule CreateHaikuImageUnzipFilesScript script 761{ 762 CreateContainerUnzipFilesScript $(HAIKU_IMAGE_CONTAINER_NAME) : $(script) ; 763} 764 765rule BuildHaikuImage haikuImage : scripts : isImage : isVMwareImage 766{ 767 # BuildHaikuImage <haiku image> : <scripts> : <is image> : <isVMwareImage> ; 768 769 if $(isImage) = 1 || $(isImage) = true { 770 IS_IMAGE on $(haikuImage) = 1 ; 771 } else { 772 IS_IMAGE on $(haikuImage) = "" ; 773 } 774 775 if $(isVMwareImage) = 1 || $(isVMwareImage) = true { 776 IS_VMWARE_IMAGE on $(haikuImage) = 1 ; 777 } else { 778 IS_VMWARE_IMAGE on $(haikuImage) = "" ; 779 } 780 781 local mainScript = build_haiku_image ; 782 SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ; 783 784 Depends $(haikuImage) : $(mainScript) $(scripts) ; 785 BuildHaikuImage1 $(haikuImage) : $(mainScript) $(scripts) ; 786} 787 788actions BuildHaikuImage1 789{ 790 export imagePath="$(1)" 791 export isImage="$(IS_IMAGE)" 792 export isVMwareImage="$(IS_VMWARE_IMAGE)" 793 $(2[1]) $(2[2-]) 794} 795 796rule BuildVMWareImage vmwareImage : plainImage : imageSize 797{ 798 # BuildVMWareImage <vmware image> : <plain image> : <image size in MB> 799 800 IMAGE_SIZE on $(vmwareImage) = $(imageSize) ; 801 802 Depends $(vmwareImage) : <build>vmdkheader $(plainImage) ; 803 BuildVMWareImage1 $(vmwareImage) : <build>vmdkheader $(plainImage) ; 804} 805 806actions BuildVMWareImage1 807{ 808 $(RM) $(1) 809 $(2[1]) -h 64k -i$(IMAGE_SIZE)M $(1) && 810 cat $(2[2]) >> $(1) 811} 812 813 814#pragma mark - Network Boot Archive rules 815 816rule AddDirectoryToNetBootArchive directoryTokens 817{ 818 # AddDirectoryToNetBootArchive <directoryTokens> 819 820 return [ AddDirectoryToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) 821 : $(directoryTokens) ] ; 822} 823 824rule AddFilesToNetBootArchive directory : targets : destName 825{ 826 # AddFilesToNetBootArchive <directory> : <targets> [ : dest name ] 827 828 AddFilesToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) : $(directory) 829 : $(targets) : $(destName) ; 830} 831 832rule AddSymlinkToNetBootArchive directoryTokens : linkTarget : linkName 833{ 834 # AddSymlinkToNetBootArchive <directory> : <link target> [ : <link name> ] ; 835 836 AddSymlinkToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) 837 : $(directoryTokens) : $(linkTarget) : $(linkName) ; 838} 839 840rule AddDriversToNetBootArchive relativeDirectoryTokens : targets 841{ 842 # AddDriversToNetBootArchive <relative directory> : <targets> ; 843 844 AddDriversToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) 845 : $(relativeDirectoryTokens) : $(targets) ; 846} 847 848rule AddDriverRegistrationToNetBootArchive relativeDirectoryTokens : target 849 : links 850{ 851 # AddDriverRegistrationToNetBootArchive <directory> : <link target> 852 # : <link names> ] ; 853 854 AddDriverRegistrationToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) 855 : $(relativeDirectoryTokens) : $(target) : $(links) ; 856} 857 858rule AddBootModuleSymlinksToNetBootArchive targets 859{ 860 # AddBootModuleSymlinksToNetBootArchive <targets> ; 861 862 AddBootModuleSymlinksToContainer $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) 863 : $(targets) ; 864} 865 866rule CreateNetBootArchiveMakeDirectoriesScript script 867{ 868 CreateContainerMakeDirectoriesScript 869 $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) : $(script) ; 870} 871 872rule CreateNetBootArchiveCopyFilesScript script 873{ 874 CreateContainerCopyFilesScript $(HAIKU_NET_BOOT_ARCHIVE_CONTAINER_NAME) 875 : $(script) ; 876} 877 878rule BuildNetBootArchive archive : scripts 879{ 880 # BuildHNetBootArchive <archive> : <scripts> ; 881 882 local mainScript = build_tgz_archive ; 883 SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ; 884 885 Depends $(archive) : $(mainScript) $(scripts) ; 886 BuildNetBootArchive1 $(archive) : $(mainScript) $(scripts) ; 887} 888 889actions BuildNetBootArchive1 890{ 891 $(2[1]) $(1) $(2[2-]) 892} 893 894 895#pragma mark - Floppy Boot Archive rules 896 897rule AddDirectoryToFloppyBootArchive directoryTokens 898{ 899 # AddDirectoryToFloppyBootArchive <directoryTokens> 900 901 return [ AddDirectoryToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) 902 : $(directoryTokens) ] ; 903} 904 905rule AddFilesToFloppyBootArchive directory : targets : destName 906{ 907 # AddFilesToFloppyBootArchive <directory> : <targets> [ : dest name ] 908 909 AddFilesToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) : $(directory) 910 : $(targets) : $(destName) ; 911} 912 913rule AddSymlinkToFloppyBootArchive directoryTokens : linkTarget : linkName 914{ 915 # AddSymlinkToFloppyBootArchive <directory> : <link target> [ : <link name> ] ; 916 917 AddSymlinkToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) 918 : $(directoryTokens) : $(linkTarget) : $(linkName) ; 919} 920 921rule AddDriversToFloppyBootArchive relativeDirectoryTokens : targets 922{ 923 # AddDriversToFloppyBootArchive <relative directory> : <targets> ; 924 925 AddDriversToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) 926 : $(relativeDirectoryTokens) : $(targets) ; 927} 928 929rule AddDriverRegistrationToFloppyBootArchive relativeDirectoryTokens : target 930 : links 931{ 932 # AddDriverRegistrationToFloppyBootArchive <directory> : <link target> 933 # : <link names> ] ; 934 935 AddDriverRegistrationToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) 936 : $(relativeDirectoryTokens) : $(target) : $(links) ; 937} 938 939rule AddBootModuleSymlinksToFloppyBootArchive targets 940{ 941 # AddBootModuleSymlinksToFloppyBootArchive <targets> ; 942 943 AddBootModuleSymlinksToContainer $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) 944 : $(targets) ; 945} 946 947rule CreateFloppyBootArchiveMakeDirectoriesScript script 948{ 949 CreateContainerMakeDirectoriesScript 950 $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) : $(script) ; 951} 952 953rule CreateFloppyBootArchiveCopyFilesScript script 954{ 955 CreateContainerCopyFilesScript $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) 956 : $(script) ; 957} 958 959rule BuildFloppyBootArchive archive : scripts 960{ 961 # BuildHFloppyBootArchive <archive> : <scripts> ; 962 963 local mainScript = build_tgz_archive ; 964 SEARCH on $(mainScript) = [ FDirName $(HAIKU_TOP) build scripts ] ; 965 966 Depends $(archive) : $(mainScript) $(scripts) ; 967 BuildFloppyBootArchive1 $(archive) : $(mainScript) $(scripts) ; 968} 969 970actions BuildFloppyBootArchive1 971{ 972 $(2[1]) $(1) $(2[2-]) 973} 974 975# warning: that is quite x86 dependant... 976 977rule BuildFloppyBootImage image : zbeos : archive 978{ 979 Depends $(image) : $(zbeos) ; 980 Depends $(image) : $(archive) ; 981 #MakeLocateDebug $(image) ; 982 BuildFloppyBootImage1 $(image) : $(zbeos) $(archive) ; 983} 984 985actions BuildFloppyBootImage1 986{ 987 $(RM) $(<) 988 # make an empty image 989 dd if=/dev/zero of=$(<) bs=1k count=1440 990 # add zbeos 991 dd if=$(>[1]) of=$(<) conv=notrunc 992 # add the boot drivers tgz archive 993 # keep the offset in sync with 994 # src/system/boot/loader/file_systems/tarfs/tarfs.cpp:kFloppyArchiveOffset 995 dd if=$(>[2]) of=$(<) bs=192k seek=1 conv=notrunc 996} 997 998 999#pragma mark - CD Boot Image rules 1000 1001rule BuildCDBootImage image : bootfloppy : extrafiles 1002{ 1003 Depends $(image) : $(bootfloppy) ; 1004 Depends $(image) : $(extrafiles) ; 1005 BOOTIMG on $(image) = $(bootfloppy) ; 1006 1007 BuildCDBootImage1 $(image) : $(bootfloppy) $(extrafiles) ; 1008} 1009 1010actions BuildCDBootImage1 1011{ 1012 $(RM) $(<) 1013 mkisofs -b $(BOOTIMG) -r -J -V bootimg -o $(<) $(>[1]) $(>[2-]) 1014} 1015 1016 1017