1#---------------------------------------------------------------------------- 2# Project: Horizon 3# File: CTR.commondefs.func.om 4# 5# Copyright (C)2009-2011 Nintendo Co., Ltd. All rights reserved. 6# 7# These coded instructions, statements, and computer programs contain 8# proprietary information of Nintendo of America Inc. and/or Nintendo 9# Company Ltd., and are protected by Federal copyright law. They may 10# not be disclosed to third parties or copied or duplicated in any form, 11# in whole or in part, without the prior written consent of Nintendo. 12# 13# $Rev: 48432 $ 14#---------------------------------------------------------------------------- 15 16 17#---------------------------------------------------------------------------- 18# Function definitions 19#---------------------------------------------------------------------------- 20 21 22public.GetBannerFile(config) = 23 private.banner = $(config.getDefaultBannerFile) 24 if $(defined CTR_BANNER_SPEC) 25 private.base = $(removesuffix $(basename $(CTR_BANNER_SPEC))) 26 return $(addprefix $(config.getObjectDirectory)$(DIRSEP), $(addsuffixes $(EXT_BANNER), $(base))) 27 else 28 if $(defined CTR_BANNER) 29 return $(CTR_BANNER) 30 elseif $(or $(and $(defined CTR_NO_BANNER_ICON), $(equal $(CTR_NO_BANNER_ICON), true)), \ 31 $(and $(defined CTR_NO_BANNER), $(equal $(CTR_NO_BANNER), true)) ) 32 return $(EMPTY) 33 return $(banner) 34 35public.GetIconFile(config) = 36 private.icon = $(config.getDefaultIconFile) 37 if $(defined CTR_BANNER_SPEC) 38 private.base = $(removesuffix $(basename $(CTR_BANNER_SPEC))) 39 return $(addprefix $(config.getObjectDirectory)$(DIRSEP), $(addsuffixes $(EXT_ICON), $(base))) 40 else 41 if $(defined CTR_ICON) 42 return $(CTR_ICON) 43 elseif $(and $(defined CTR_NO_BANNER_ICON), $(equal $(CTR_NO_BANNER_ICON), true)) 44 return $(EMPTY) 45 return $(icon) 46 47public.GetMakeromOptions(config)= 48 private.romfs_root = $(if $(defined ROMFS_ROOT),$`(ROMFS_ROOT),$(EMPTY)) 49 private.title = $(if $(defined TITLE),$`(TITLE),CtrApp) 50 51 private.flags[] = 52 -DROMFS_ROOT=$(romfs_root) 53 -DTITLE=$(title) 54 55 BannerFile = $(GetBannerFile $(config)) 56 IconFile = $(GetIconFile $(config)) 57 if $(not $(equal $(BannerFile.length), 0)) 58 flags += -banner $(BannerFile) 59 export flags 60 61 if $(not $(equal $(IconFile.length), 0)) 62 flags += -icon $(IconFile) 63 export flags 64 65 return $(flags) 66 67global.FilterOutOptionPair(key, list) = 68 if $(lt $(length $(list)),2) 69 return $(list) 70 if $(equal $(key),$(nth 0,$(list))) 71 return $(FilterOutOptionPair $(key),$(nth-tl 2,$(list))) 72 return $(nth 0,$(list)) $(FilterOutOptionPair $(key),$(nth-tl 1,$(list))) 73 74 75 76 77 78 79 80 81 82 83 84 85#------------------------------------------------------- 86# AddRuleToMakeCci 87# 88# Overview 89# | 90# 91# Referenced global variables 92# None. 93#------------------------------------------------------- 94AddRuleToMakeCci(cci, elf, flags, depends) = 95 $(cci): $(makeDirectory $(dirname $(cci))) 96 $(cci): $(elf) $(depends) $(MAKEROM) build-romfs :value: $(getMtimeIfLarge $(elf) $(depends)) 97 $(MAKEROM) -o $@ $(elf) $(flags) -f card 98 return $(cci) 99 100#------------------------------------------------------- 101# AddRuleToMakeCclE 102# 103# Overview 104# | 105# 106# Referenced global variables 107# None. 108#------------------------------------------------------- 109AddRuleToMakeCclE(ccl_e, elf, r, flags, depends) = 110 $(ccl_e): $(makeDirectory $(dirname $(ccl_e))) 111 $(ccl_e): $(elf) $(r) $(depends) $(MAKEROM) build-romfs :value: $(getMtimeIfLarge $(elf) $(r) $(depends)) 112 $(MAKEROM) -o $@ $< $(flags) -lr $(r) -f le -m 0x01000000 113 return $(ccl_e) 114 115#------------------------------------------------------- 116# AddRuleToMakeCclR 117# 118# Overview 119# | 120# 121# Referenced global variables 122# None. 123#------------------------------------------------------- 124AddRuleToMakeCclR(ccl_r, flags, depends) = 125 $(ccl_r): $(makeDirectory $(dirname $(ccl_r))) 126 $(ccl_r): $(depends) $(MAKEROM) build-romfs :value: $(getMtimeIfLarge $(depends)) 127 $(MAKEROM) -o $@ $(flags) -f lr 128 return $(ccl_r) 129 130#------------------------------------------------------- 131# AddRuleToMakeCcl 132# 133# Overview 134# | 135# 136# Referenced global variables 137# None. 138#------------------------------------------------------- 139AddRuleToMakeCcl(ccl, e, r) = 140 $(ccl): $(makeDirectory $(dirname $(ccl))) 141 $(ccl): $(e) $(r) $(MAKEROM) build-romfs :value: $(getMtimeIfLarge $(e) $(r)) 142 $(MAKEROM) -o $@ -le $(e) -lr $(r) -f list 143 return $(ccl) 144 145#------------------------------------------------------- 146# AddRuleToMakeCxi 147# 148# Overview 149# | 150# 151# Referenced global variables 152# None. 153#------------------------------------------------------- 154AddRuleToMakeCxi(cxi, elf, flags, depends) = 155 $(cxi): $(makeDirectory $(dirname $(cxi))) 156 $(cxi): $(elf) $(depends) $(MAKEROM) build-romfs :value: $(getMtimeIfLarge $(elf) $(depends)) 157 $(MAKEROM) -o $@ $< $(flags) 158 return $(cxi) 159 160#------------------------------------------------------- 161# AddRuleToMakeCia 162# 163# Overview 164# | 165# 166# Referenced global variables 167# None. 168#------------------------------------------------------- 169AddRuleToMakeCia(cia, flags, depends) = 170 $(cia): $(makeDirectory $(dirname $(cia))) 171 $(cia): $(depends) $(MAKECIA) :value: $(getMtimeIfLarge $(depends)) 172 $(MAKECIA) -o $@ $(flags) 173 return $(cia) 174 175#------------------------------------------------------- 176# AddRuleToMakeCfa 177# 178# Overview 179# | 180# 181# Referenced global variables 182# None. 183#------------------------------------------------------- 184AddRuleToMakeCfa(cfa, srcdir, flags, depends) = 185 $(cfa): $(makeDirectory $(dirname $(cfa))) 186 $(cfa): $(srcdir) $(depends) $(MAKEROM) :value: $(getMtimeIfLarge $(depends)) 187 $(MAKEROM) -o $@ -DROMFS_ROOT=$(srcdir) $(flags) -f data 188 return $(cfa) 189 190#------------------------------------------------------- 191# AddRuleToMakeBanner 192# 193# Overview 194# | 195# 196# Referenced global variables 197# None. 198#------------------------------------------------------- 199AddRuleToMakeBanner(banner, icon, bsf) = 200 $(banner): $(makeDirectory $(dirname $(banner))) 201 $(icon): $(makeDirectory $(dirname $(icon))) 202 $(banner) $(icon): $(bsf) $(MAKEBANNER) 203 $(MAKEBANNER) $< $(banner) $(icon) 204 return $(banner) $(icon) 205 206#------------------------------------------------------- 207# AddRuleToMakeIcon 208# 209# Overview 210# | 211# 212# Referenced global variables 213# None. 214#------------------------------------------------------- 215AddRuleToMakeIcon(icon, bsf) = 216 $(icon): $(makeDirectory $(dirname $(icon))) 217 $(icon): $(bsf) $(MAKEBANNER) 218 $(MAKEBANNER) -d -nobnr $(file $<) $(absname $(icon)) 219 return $(icon) 220 221AddRuleToMakeCfaFromCias(cfa, flags, depends) = 222 $(cfa): $(makeDirectory $(dirname $(cfa))) 223 $(cfa): $(depends) $(MAKECIAARCHIVE) :value: $(getMtimeIfLarge $(depends)) 224 $(MAKECIAARCHIVE) -o $@ $(flags) 225 return $(cfa) 226 227 228 229 230 231#------------------------------------------------------- 232# MakeCci 233# 234# Overview 235# Create .cci from ELF 236# Return the .cci path 237# 238# Referenced global variables 239# None. 240#------------------------------------------------------- 241MakeCci(config, name, elf, flags, cci_depends) = 242 private.cci = $(config.getBinaryPath $(name), $(EXT_CCI)) 243 return $(AddRuleToMakeCci $(cci),$(elf),$(flags), $(cci_depends)) 244 245#------------------------------------------------------- 246# MakeCclE 247# 248# Overview 249# Create the E portion of .ccl 250# Return the path to the E portion of .ccl 251# 252# Referenced global variables 253# None. 254#------------------------------------------------------- 255MakeCclE(config, name, elf, r, flags, depends) = 256 private.e = $(config.getBinaryPath $(name), $(EXT_CCL_E)) 257 return $(AddRuleToMakeCclE $(e),$(elf),$(r),$(flags),$(depends)) 258 259#------------------------------------------------------- 260# MakeCclR 261# 262# Overview 263# Create the R portion of .ccl 264# Return the path to the R portion of .ccl 265# 266# Referenced global variables 267# None. 268#------------------------------------------------------- 269MakeCclR(config, name, flags, cci_depends) = 270 private.r = $(config.getBinaryPath $(name), $(EXT_CCL_R)) 271 return $(AddRuleToMakeCclR $(r),$(flags),$(cci_depends)) 272 273#------------------------------------------------------- 274# MakeCcl 275# 276# Overview 277# Create .ccl 278# Return the .ccl path 279# 280# Referenced global variables 281# None. 282#------------------------------------------------------- 283MakeCcl(config, name, e, r) = 284 private.ccl = $(config.getBinaryPath $(name), $(EXT_CCL)) 285 return $(AddRuleToMakeCcl $(ccl),$(e),$(r)) 286 287#------------------------------------------------------- 288# MakeCxi 289# 290# Overview 291# Create .cxi from ELF 292# Return the .cxi path 293# 294# Referenced global variables 295# None. 296#------------------------------------------------------- 297MakeCxi(config, name, elf, flags, cxi_depends) = 298 private.cxi = $(config.getBinaryPath $(name), $(EXT_CXI)) 299 return $(AddRuleToMakeCxi $(cxi),$(elf),$(flags), $(cxi_depends)) 300 301#------------------------------------------------------- 302# MakeCia 303# 304# Overview 305# Create .cia from .cxi 306# Return the .cia path 307# 308# Referenced global variables 309# None. 310#------------------------------------------------------- 311MakeCia(config, name, flags, depends) = 312 private.cia = $(config.getBinaryPath $(name), $(EXT_CIA)) 313 return $(AddRuleToMakeCia $(cia), $(flags), $(depends)) 314 315#------------------------------------------------------- 316# MakeCfa 317# 318# Overview 319# Create .cfa from the directory 320# Return the .cfa path 321# 322# Referenced global variables 323# None. 324#------------------------------------------------------- 325MakeCfa(config, name, srcdir, flags, depends) = 326 private.cfa = $(config.getBinaryPath $(name), $(EXT_CFA)) 327 return $(AddRuleToMakeCfa $(cfa), $(srcdir), $(flags), $(depends)) 328 329 330#------------------------------------------------------- 331# MakeBanner 332# 333# Overview 334# | 335# 336# Referenced global variables 337# None. 338#------------------------------------------------------- 339MakeBanner(config, rsf) = 340 private.banner = $(GetBannerFile $(config)) 341 private.icon = $(GetIconFile $(config)) 342 return $(AddRuleToMakeBanner $(banner),$(icon),$(bsf)) 343 344#------------------------------------------------------- 345# MakeIcon 346# 347# Overview 348# | 349# 350# Referenced global variables 351# None. 352#------------------------------------------------------- 353MakeIcon(config, bsf) = 354 private.base = $(removesuffix $(bsf)) 355 private.icon = $(addprefix $(config.getObjectDirectory)$(DIRSEP), $(addsuffixes $(EXT_ICON), $(base))) 356 return $(AddRuleToMakeIcon $(icon),$(bsf)) 357 358 359 360 361 362 363 364 365 366 367#------------------------------------------------------- 368# BuildCci 369# 370# Overview 371# Create .cci 372# Return the .cci path 373# 374# Referenced global variables 375# None. 376#------------------------------------------------------- 377BuildCci(config, name, files, cci_flags, cci_depends) = 378 private.elf = $(ExecutableElf $(config), $(name), $(files)) 379 private.cci = $(MakeCci $(config), $(name), $(elf), $(cci_flags), $(cci_depends)) 380 return $(cci) 381 382#------------------------------------------------------- 383# BuildCcl 384# 385# Overview 386# Create .ccl 387# Return the .ccl path 388# 389# Referenced global variables 390# None. 391#------------------------------------------------------- 392BuildCcl(config, name, files, cci_flags, cci_depends, r_depends) = 393 private.elf = $(ExecutableElf $(config), $(name), $(files)) 394 private.r = $(MakeCclR $(config), $(name), $(cci_flags), $(r_depends) $(cci_depends)) 395 private.e = $(MakeCclE $(config), $(name), $(elf), $(r), $(cci_flags), $(cci_depends)) 396 private.ccl = $(MakeCcl $(config), $(name), $(e), $(r)) 397 return $(ccl) 398 399#------------------------------------------------------- 400# BuildCia 401# 402# Overview 403# Create .cia 404# Return the .cia path 405# 406# Referenced global variables 407# None. 408#------------------------------------------------------- 409BuildCia(config, name, files, cxi_flags, cia_flags, cxi_depends, cia_depends) = 410 if $(files) 411 private.elf = $(ExecutableElf $(config), $(name), $(files)) 412 private.cxi = $(MakeCxi $(config), $(name), $(elf), $(cxi_flags), $(cxi_depends)) 413 cia_flags = -i $(cxi) $(cia_flags) 414 cia_depends += $(cxi) 415 export cia_flags 416 export cia_depends 417 418 return $(MakeCia $(config), $(name), $(cia_flags), $(cia_depends)) 419 420 421 422MakeCfaFromCias(config, name, cia_list, rsf) = 423 private.workdir = $(makeDirectory $(makePath $(config.getObjectDirectory) $(name))) 424 private.cfa = $(makePath $(config.getObjectDirectory) $(name)$(EXT_CFA)) 425 private.flags = -cia $(cia_list) -rsf $(rsf) --romfs-root $(workdir) 426 private.depends = $(cia_list) $(rsf) $(workdir) 427 return $(AddRuleToMakeCfaFromCias $(cfa), $(flags), $(depends)) 428 429MakeChildCfa(config, cia_list) = 430 private.rsf = $(makePath $(ROOT_RESOURCES) specfiles Child.rsf) 431 return $(MakeCfaFromCias $(config), Child, $(cia_list), $(rsf)) 432 433MakeManualCfa(config, manual_dir, flags, depends) = 434 private.rsf = $(makePath $(ROOT_RESOURCES) specfiles Manual.rsf) 435 flags += -rsf $(rsf) 436 return $(MakeCfa $(config), Manual, $(manual_dir), $(flags), $(rsf) $(depends)) 437 438#------------------------------------------------------- 439# DataContent 440# 441# Overview 442# Create data content combined .cxi and .cfa files 443# Return the .cia path 444# 445# Referenced global variables 446# None. 447#------------------------------------------------------- 448DataContent(config, name, contents, flags) = 449 flags += $(mapToArray $(contents),$(fun k,v,$(array -i,$(v):$(k)))) 450 private.depends = $(mapToArray $(contents),$(fun k,v,$(v))) 451 return $(MakeCia $(config), $(name), $(flags), $(depends)) 452 453#------------------------------------------------------- 454# InstallProgram 455# 456# Overview 457# | 458# 459# Referenced global variables 460# BUILDTYPES 461#------------------------------------------------------- 462InstallProgram(config, install_dir, files) = 463 if $(not $(files)) 464 return $(EMPTY) 465 466 if $(or $(and $(config.isSdkTool),\ 467 $(equal $(filter full,$(BUILDTYPES)),full)),\ 468 $(and $(not $(config.isSdkTool)),\ 469 $(not $(equal $(install_dir), $(dirname $(nth 0, $(files))))))) 470 private.ofiles = 471 foreach(outfile, $(files)) 472 dst = $(install_dir)/$(basename $(outfile)) 473 value $(AddRuleToInstall $(dst),$(outfile)) 474 return $(ofiles) 475 return $(EMPTY) 476 477ProgramCard(config, name, files, flags, depends) = 478 return $(BuildCci $(config),$(name),$(files),$(flags.find cci),$(depends.find cci)) 479 480ProgramList(config, name, files, flags, depends) = 481 return $(BuildCcl $(config),$(name),$(files),$(flags.find cci),$(depends.find cci),$(depends.find rom_fs)) 482 483ProgramImport(config, name, files, flags, depends) = 484 return $(BuildCia $(config),$(name),$(files), \ 485 $(flags.find cxi), $(flags.find cia), \ 486 $(depends.find cxi), $(depends.find cia) ) 487 488ProgramPatch(config, name, files, flags, depends) = 489 private.cxi_flags = $(flags.find cxi) 490 private.cia_flags = $(flags.find cia) 491 private.cxi_depends = $(depends.find cxi) 492 private.cia_depends = $(depends.find cia) 493 private.cnt_depends = $(depends.find cnt) 494 495 cxi_flags = $(FilterOutOptionPair -banner,$(cxi_flags)) 496 cia_flags = $(FilterOutOptionPair -i,$(cia_flags)) 497 cxi_depends = $(filter-out $(GetBannerFile $(config)),$(cxi_depends)) 498 cia_depends = $(filter-out $(cnt_depends),$(cia_depends)) 499 500 return $(BuildCia $(config),$(name),$(files), \ 501 $(cxi_flags),$(cia_flags),$(cxi_depends),$(cia_depends)) 502 503 504#------------------------------------------------------- 505# Program 506# 507# Overview 508# Create CTR execution file 509# 510# Referenced global variables 511# BUILD_APPLICATION, LDSCRIPT, CRT_0_O, 512# ROMFS_DEPENDENCIES, ROMFS_ROOT, MAKEROMFLAGS, 513# DESCRIPTOR, ROM_SPEC_FILE, CTR_APPTYPE, 514# PROGRAM_BUILDER_MAP, MANUAL_DIR, CHILD_APPS, 515# MANUAL_DEPENDENCIES 516#------------------------------------------------------- 517Program(config, name, files) = 518 global.BUILD_APPLICATION = true 519 private.contents = $(Map) 520 521 if $(not $(defined LDSCRIPT)) 522 LDSCRIPT = $(config.getDefaultLdscriptPath) 523 export 524 525 if $(not $(defined CRT_0_O)) 526 CRT_0_O = crt0.o 527 export 528 529 if $(not $(defined ROMFS_DEPENDENCIES)) 530 if $(defined ROMFS_ROOT) 531 ROMFS_DEPENDENCIES = $(ls -R, $(dir $(ROMFS_ROOT))) 532 export 533 else 534 ROMFS_DEPENDENCIES = 535 export 536 export 537 538 if $(not $(defined MANUAL_DEPENDENCIES)) 539 if $(defined MANUAL_DIR) 540 MANUAL_DEPENDENCIES = $(ls -R, $(dir $(MANUAL_DIR))) 541 export 542 else 543 MANUAL_DEPENDENCIES = 544 export 545 export 546 547 # For manual 548 if $(defined MANUAL_DIR) 549 private.cfa = $(MakeManualCfa $(config), $(MANUAL_DIR), $(MAKEROMFLAGS), $(MANUAL_DEPENDENCIES)) 550 contents = $(contents.add 1,$(cfa)) 551 export contents 552 553 # For child 554 if $(defined CHILD_APPS) 555 private.cfa = $(MakeChildCfa $(config), $(CHILD_APPS)) 556 contents = $(contents.add 2,$(cfa)) 557 export contents 558 559 private.desc = $(if $(defined DESCRIPTOR),$`(DESCRIPTOR),$(config.getDefaultDescriptorPath)) 560 561 private.cxi_flags = $(MAKEROMFLAGS) 562 private.cci_flags = $(EMPTY_ARRAY) 563 private.cia_flags = $(MAKECIAFLAGS) 564 private.rom_fs_depends = $(ROMFS_DEPENDENCIES) 565 private.cxi_depends = $(desc) $(ROM_SPEC_FILE) $(GetBannerFile $(config)) $(GetIconFile $(config)) 566 private.cci_depends = $(EMPTY_ARRAY) 567 private.cia_depends = $(EMPTY_ARRAY) 568 private.cnt_depends = $(EMPTY_ARRAY) 569 570 cxi_flags += -desc $(desc) -rsf $(ROM_SPEC_FILE) 571 cxi_flags += $(GetMakeromOptions $(config)) 572 573 cci_flags += $(mapToArray $(contents),$(fun k,v,-content $(v):$(k))) 574 cia_flags += $(mapToArray $(contents),$(fun k,v,-i $(v):$(k))) 575 cnt_depends += $(mapToArray $(contents),$(fun k,v,$(v))) 576 577 private.flags = $(Map) 578 private.depends = $(Map) 579 flags = $(flags.add cxi,$(cxi_flags)) 580 flags = $(flags.add cci,$(cxi_flags) $(cci_flags)) 581 flags = $(flags.add cia,$(cia_flags)) 582 depends = $(depends.add rom_fs,$(rom_fs_depends)) 583 depends = $(depends.add cxi,$(rom_fs_depends) $(cxi_depends)) 584 depends = $(depends.add cci,$(rom_fs_depends) $(cxi_depends) $(cci_depends) $(cnt_depends)) 585 depends = $(depends.add cia,$(cia_depends) $(cnt_depends)) 586 depends = $(depends.add cnt,$(cnt_depends)) 587 588 private.app_type = 589 if $(equal $(CTR_APPTYPE),$(APPTYPE_BOTH)) 590 value $(APPTYPE_CARD) $(APPTYPE_NAND) 591 else 592 value $(CTR_APPTYPE) 593 594 private.target_files = 595 foreach (type, $(app_type)) 596 private.builder = $(PROGRAM_BUILDER_MAP.find $(type)) 597 if $(builder) 598 value $(apply $(builder), $(config), $(name), $(files), $(flags), $(depends)) 599 else 600 eprintln($"Build Error: Unknown APPTYPE:" '$(type)') 601 exit(1) 602 603 target_files = $(stripEmpty $(target_files)) 604 605 # If the tree is referenced externally, determine whether to install 606 private.install_dir = $(config.getImageDirectory true) 607 private.install_targets = $(InstallProgram $(config),$(install_dir),$(target_files)) 608 609 return $(target_files) $(install_targets) 610 611 612#------------------------------------------------------- 613# Banner 614# 615# Overview 616# Create banner 617# 618# Referenced global variables 619# None. 620#------------------------------------------------------- 621Banner(config, bsf) = 622 return $(MakeBanner $(config),$(bsf)) 623 624#------------------------------------------------------- 625# Icon 626# 627# Overview 628# Create an icon 629# 630# Referenced global variables 631# None. 632#------------------------------------------------------- 633Icon(config, bsf) = 634 return $(MakeIcon $(config),$(bsf)) 635 636 637 638 639global.GetExportTypeOption(type) = 640 switch($(type)) 641 case SYMBOL 642 return $(EMPTY) 643 case INDEX 644 return -i 645 case OFFSET 646 return -e 647 eprintln(unknown MODULE_EXPORT_TYPE "$(type)") 648 649#-------------------------------------------- 650 651private.AddRuleToMakeXrl1st(xrl, plf, isApp, flags) = 652 $(xrl) : $(plf) $(MAKECRO) 653 $(MAKECRO) -l $(if $(isApp),-a) -o $@ $(flags) $< 654 return $(xrl) 655 656private.AddRuleToMakeXrlStatic(xrlS, xrl1st, list1st, flags) = 657 $(xrlS) : $(xrl1st) $(list1st) $(MAKECRO) 658 $(MAKECRO) -c -o $@ $(mapprefix -r ,$(list1st)) $(flags) $< 659 return $(xrlS) 660 661private.AddRuleToMakeXrl2nd(xrl2nd, xrl1st, xrl) = 662 $(xrl2nd) : $(xrl1st) $(xrl) $(MAKECRO) 663 $(MAKECRO) -m -o $@ -d $(xrl1st) -d $(xrl) -g 664 return $(xrl2nd) 665 666private.AddRuleToMakeXrl3rd(xrl3rd, xrl2nd, list2nd) = 667 $(xrl3rd) : $(xrl2nd) $(list2nd) $(MAKECRO) 668 $(MAKECRO) -f -o $@ $(mapprefix -r ,$(list2nd)) $< 669 return $(xrl3rd) 670 671private.AddRuleToMakeXrl4th(xrl4th, axf, xrl3rd) = 672 $(xrl4th) : $(axf) $(xrl3rd) $(MAKECRO) 673 $(MAKECRO) -p -o $@ -d $(xrl3rd) $< 674 return $(xrl4th) 675 676private.AddRuleToMergeXrl(xrl, xrllist, mn) = 677 $(xrl) : $(xrllist) $(MAKECRO) 678 $(MAKECRO) -m -o $@ $(mapprefix -d ,$(xrllist)) -n "$(mn)" -g 679 return $(xrl) 680 681private.AddRuleToMakeEdit(edit, xrl) = 682 $(edit) : $(xrl) $(MAKECRO) 683 $(MAKECRO) -s -o $@ $< 684 return $(edit) 685 686private.AddRuleToMakeCmdOpt(cmd, xrl) = 687 $(cmd) : $(xrl) $(MAKECRO) 688 $(MAKECRO) -x -y nnroUnresolved -o $@ $< 689 return $(cmd) 690 691private.AddRuleToMakeRo(ro, rlt, axf, xrl, list3rd) = 692 $(rlt) $(ro) : $(axf) $(xrl) $(list3rd) $(MAKECRO) 693 $(MAKECRO) -o $(ro) -t $(rlt) -d $(xrl) $(mapprefix -r ,$(list3rd)) $< 694 return $(ro) 695 696private.AddRuleToMakeRs(ro, axf, xrl, list3rd) = 697 $(ro) : $(axf) $(xrl) $(list3rd) $(MAKECRO) 698 $(MAKECRO) -o $(ro) -d $(xrl) $(mapprefix -r ,$(list3rd)) $< 699 return $(ro) 700 701private.AddRuleToMakeRr(rr, rlt_list, add_debug) = 702 $(rr): $(makeDirectory $(dirname $(rr))) 703 $(rr) : $(rlt_list) $(MAKECRR) 704 $(MAKECRR) $(if $(add_debug),-d) -o $@ $(mapprefix -r ,$(rlt_list)) 705 return $(rr) 706 707private.AddRuleToCopyFile(d, s) = 708 $(d): $(makeDirectory $(dirname $(d))) 709 $(d) : $(s) 710 cp -f $< $@ 711 return $(d) 712 713private.AddRuleToReplaceReference(path, raw) = 714 $(path) : $(raw) $(MAKECRO) 715 $(MAKECRO) -u nnroUnresolved -o $@ $< 716 return $(path) 717 718private.AddRuleToMakeForceImport(path, xrl) = 719 $(path) : $(makeDirectory $(dirname $(path))) 720 $(path) : $(xrl) 721 $(MAKECRO) -w -o $@ $(xrl) 722 return $(path) 723 724private.AddRuleToForceImport(path, axf, list) = 725 $(path) : $(axf) $(list) :value: $(getMtimeIfLarge $(axf)) 726 $(FROMELF) -o $@ $(axf) --elf --via $(list) 727 return $(path) 728 729 730 731#-------------------------------------------- 732 733private.MakePlf(config, name, files, addtional_ldflags) = 734 EXCLUSION_SCATTER = 1 735 EXT_ELF = $(EXT_PLF) 736 EXT_LDS = $(EXT_PLF)$(EXT_LDS) 737 EXT_MAP = $(EXT_PLF)$(EXT_MAP) 738 EXT_DASM = $(EXT_PLF)$(EXT_DASM) 739 EXT_CG = $(EXT_PLF)$(EXT_CG) 740 DISAS = $(EMPTY) 741 CRT_0_O = $(EMPTY) 742 LDFLAGS += \ 743 --no_scanlib \ 744 --partial \ 745 --vfemode=off \ 746 --diag_suppress=L6475W \ 747 $(addtional_ldflags) 748 749 public.ELF_FLAGS_HOOK = 750 fun(flags) = 751 return $(filter-out --scanlib --vfemode=force,$(flags)) 752 753 private.plf = $(ORIGINAL_ExecutableElf $(config), $(name), $(files)) 754 $(plf): $(makeDirectory $(dirname $(plf))) 755 return $(plf) 756 757private.MakeXrl1st(config, name, plf, isApp, flags) = 758 private.path = $(config.getBinaryPath $(name), .1$(EXT_XRL)) 759 return $(AddRuleToMakeXrl1st $(path), $(plf), $(isApp), $(flags)) 760 761private.MakeXrl2nd(config, name, xrl1st, xrl) = 762 private.path = $(config.getBinaryPath $(name), .2$(EXT_XRL)) 763 if $(xrl) 764 return $(AddRuleToMakeXrl2nd $(path), $(xrl1st), $(xrl)) 765 else 766 return $(AddRuleToCopyFile $(path), $(xrl1st)) 767 768private.MakeXrl3rd(config, name, xrl2nd, list2nd) = 769 private.path = $(config.getBinaryPath $(name), .3$(EXT_XRL)) 770 return $(AddRuleToMakeXrl3rd $(path), $(xrl2nd), $(list2nd)) 771 772private.MakeXrl4th(config, name, axf, xrl3rd) = 773 private.path = $(config.getBinaryPath $(name), .4$(EXT_XRL)) 774 return $(AddRuleToMakeXrl4th $(path), $(axf), $(xrl3rd)) 775 776private.MakeXrlStatic0(config, name, plf, isApp, flags) = 777 private.path = $(config.getBinaryPath $(name), .0$(EXT_XRL)) 778 return $(AddRuleToMakeXrl1st $(path), $(plf), $(isApp), $(flags)) 779 780private.MakeXrlStatic1(config, name, xrl1st, xrl) = 781 private.path = $(config.getBinaryPath $(name), .1$(EXT_XRL)) 782 if $(xrl) 783 return $(AddRuleToMakeXrl2nd $(path), $(xrl1st), $(xrl)) 784 else 785 return $(AddRuleToCopyFile $(path), $(xrl1st)) 786 787private.MakeXrlStatic2(config, name, xrl1st, list2nd, flags) = 788 private.path = $(config.getBinaryPath $(name), .2$(EXT_XRL)) 789 return $(AddRuleToMakeXrlStatic $(path), $(xrl1st), $(list2nd), $(flags)) 790 791private.MakeEdit(config, name, xrl) = 792 private.path = $(config.getBinaryPath $(name), $(EXT_EDIT)) 793 return $(AddRuleToMakeEdit $(path), $(xrl)) 794 795private.MakeCmdOpt(config, name, xrl) = 796 private.path = $(config.getBinaryPath $(name), $(EXT_UAE)) 797 return $(AddRuleToMakeCmdOpt $(path), $(xrl)) 798 799private.MakeRo(config, name, axf, xrl, list3rd) = 800 private.ro = $(config.getBinaryPath $(name), $(EXT_RO)) 801 private.rlt = $(config.getBinaryPath $(name), $(EXT_RLT)) 802 return $(AddRuleToMakeRo $(ro), $(rlt), $(axf), $(xrl), $(list3rd)) 803 804private.MakeRs(config, name, axf, xrl, list3rd) = 805 private.path = $(config.getBinaryPath $(name), $(EXT_RS)) 806 return $(AddRuleToMakeRs $(path), $(axf), $(xrl), $(list3rd)) 807 808private.MakeRr(config, name, rlt_list, add_debug) = 809 private.path = $(config.getBinaryPath $(name), $(EXT_RR)) 810 return $(AddRuleToMakeRr $(path), $(rlt_list), $(add_debug)) 811 812private.MakeAxfForRo(config, name, src, edit) = 813 private.base = $(makePath $(ROOT_BUILD) linker $(config.platform).Ro.$(config.processor)) 814 LDSCRIPT = $(makePath $(ROOT_RESOURCES) specfiles linker CTR.Ro.MPCore.ldscript) 815 LDFLAGS += \ 816 $(addprefix --edit=,$(edit)) \ 817 --base_platform \ 818 --diag_suppress=L6780W \ 819 --dll \ 820 --no_cppinit \ 821 --no_scanlib \ 822 --override_visi. \ 823 --pltgot=direct \ 824 --undefined_and_export=nnroControlObject_ \ 825 --emit_non_debug_relocs \ 826 $(if $`(ENABLE_CPP_EXCEPTION),--undefined=nnroEitNode_) 827 828 public.ELF_FLAGS_HOOK = 829 fun(flags) = 830 return $(filter-out --scanlib --vfemode=force --entry=% --keep=nnMain,$(flags)) 831 832 private.axf = $(ORIGINAL_ExecutableElf $(config), $(name), $(src)) 833 $(axf) : $(edit) 834 return $(axf) 835 836private.MakeForceImport(config, name, xrl) = 837 private.path = $(config.getBinaryPath $(name), $(EXT_FIL)) 838 return $(AddRuleToMakeForceImport $(path), $(xrl)) 839 840 841private.ForceImport(config, name, axf, list) = 842 private.path = $(config.getBinaryPath $(name), $(EXT_ELF2)) 843 return $(AddRuleToForceImport $(path), $(axf), $(list)) 844 845private.ReplaceReference(config, name, raw) = 846 private.path = $(config.getBinaryPath $(name), .axf) 847 return $(AddRuleToReplaceReference $(path), $(raw)) 848 849 850#-------------------------------------------- 851 852global.IsModuleListDefined() = 853 return $(or $(defined MODULE_LIST),$(defined MODULE_LIST_XRL)) 854 855global.IsModuleListValid() = 856 return $(or $(and $(defined MODULE_LIST), $(not $(equal $`(MODULE_LIST), $(EMPTY)))),\ 857 $(and $(defined MODULE_LIST_XRL),$(not $(equal $`(MODULE_LIST_XRL),$(EMPTY))))) 858 859global.BuildRo(config, name, src, list2nd, list3rd, flags) = 860 DEFAULT_LIBS = $(EMPTY) 861 config.getDefaultLibraries = 862 fun() 863 value $(EMPTY) 864 config.getHostIoLibraries = 865 fun() 866 value $(EMPTY) 867 868 private.libdir = $(config.getLibraryDirectory false) 869 private.rocrt = $(file $(addprefix $(libdir)$(DIRSEP), $(addsuffix $(EXT_LIB), $(completeLibrarySuffix $(config), libnn_rocrt)))) 870 LDFLAGS += $(rocrt) 871 872 873 private.plf = $(MakePlf $(config), $(name), $(src), $(EMPTY)) 874 private.xrl1st = $(MakeXrl1st $(config), $(name), $(plf), false, $(flags)) 875 private.xrl2nd = $(MakeXrl2nd $(config), $(name), $(xrl1st), $(if $(defined MODULE_XRL),$`(MODULE_XRL))) 876 private.xrl3rd = $(MakeXrl3rd $(config), $(name), $(xrl2nd), $(list2nd)) 877 private.edit = $(MakeEdit $(config), $(name), $(xrl3rd)) 878 private.fil = $(MakeForceImport $(config), $(name), $(xrl3rd)) 879 private.axf = $(MakeAxfForRo $(config), $(name), $(src), $(edit)) 880 private.axg = $(ForceImport $(config), $(name), $(axf), $(fil)) 881 882 private.ro = 883 if $(MODULE_ENABLE_OFFSET) 884 private.xrl4th = $(MakeXrl4th $(config), $(name), $(axg), $(xrl3rd)) 885 value $(MakeRo $(config), $(name), $(axg), $(xrl4th), $(list3rd)) 886 else 887 value $(MakeRo $(config), $(name), $(axg), $(xrl3rd), $(EMPTY)) 888 889 $(axf) : $(rocrt) 890 return $(ro) 891 892private.BuildAxfUsingRo(config, name, files, list2nd, flags) = 893 private.plf = 894 section 895 DEFAULT_LIBS = $(EMPTY) 896 config.getDefaultLibraries = 897 fun() 898 value $(EMPTY) 899 config.getHostIoLibraries = 900 fun() 901 value $(EMPTY) 902 value $(MakePlf $(config), $(name), $(files), $(EMPTY)) 903 904 private.xrlS0 = $(MakeXrlStatic0 $(config), $(name), $(plf), true, $(flags)) 905 private.xrlS1 = $(MakeXrlStatic1 $(config), $(name), $(xrlS0), $(if $(defined MODULE_XRL),$`(MODULE_XRL))) 906 private.xrlS2 = $(MakeXrlStatic2 $(config), $(name), $(xrlS1), $(list2nd), $(flags)) 907 private.xrl3rd = $(MakeXrl3rd $(config), $(name), $(xrlS2), $(list2nd)) 908 private.edit = $(MakeEdit $(config), $(name), $(xrl3rd)) 909 private.uae = $(MakeCmdOpt $(config), $(name), $(xrl3rd)) 910 911 private.raw_axf = 912 section 913 public.LIBS += libnn_ro 914 public.LDFLAGS += \ 915 --base_platform \ 916 --diag_suppress=L6780W,L6473W,L6331W \ 917 $(if $(edit),--edit=$(edit)) \ 918 --override_visi. \ 919 --pltgot=direct \ 920 --undefined_and_export=nnroAeabiAtexit_ \ 921 --vfemode=off \ 922 $(if $(uae),--via $(uae)) 923 public.ELF_FLAGS_HOOK = 924 fun(flags) = 925 return $(filter-out --vfemode=force,$(flags)) 926 927 value $(ORIGINAL_ExecutableElf $(config), $(name), $(files)) 928 929 private.axf = $(ReplaceReference $(config), $(name).ro, $(raw_axf)) 930 931 $(raw_axf) : $(edit) $(uae) 932 return $(axf) 933 934global.BuildRs(config, name, axf, xrl3rd, list4th) = 935 if $(MODULE_ENABLE_OFFSET) 936 private.xrl4th = $(MakeXrl4th $(config), $(name), $(axf), $(xrl3rd)) 937 return $(MakeRs $(config), $(name), $(axf), $(xrl4th), $(list4th)) 938 else 939 return $(MakeRs $(config), $(name), $(axf), $(xrl3rd), $(EMPTY)) 940 941 942global.CollectXrl2nd(config, module_list) = 943 private.list2nd = 944 foreach(module, $(filter-out $(dir .),$(module_list))) 945 private.name = $(basename $(module)) 946 value $(config.getBinaryPathOf $(module), $(name), .2$(EXT_XRL)) 947 return $(list2nd) 948 949global.CollectXrl4th(config, module_list) = 950 private.list4th = 951 foreach(module, $(filter-out $(dir .),$(module_list))) 952 private.name = $(basename $(module)) 953 value $(config.getBinaryPathOf $(module), $(name), .4$(EXT_XRL)) 954 return $(list4th) 955 956private.CollectRlt(config, module_list) = 957 private.rlt_list = 958 foreach(module, $(filter-out $(dir .),$(module_list))) 959 private.name = $(basename $(module)) 960 value $(config.getBinaryPathOf $(module), $(name), $(EXT_RLT)) 961 return $(rlt_list) 962 963global.ExecutableElfUsingRo(config, name, files) = 964 if $(and $(defined TARGET_PROGRAM),$(IsModuleListDefined)) 965 private.list2nd = 966 if $(IsModuleListDefined) 967 value $(if $(defined MODULE_LIST),$(CollectXrl2nd $(config), $`(MODULE_LIST))) $(if $(defined MODULE_LIST_XRL),$`(MODULE_LIST_XRL)) 968 else 969 value $(EMPTY) 970 private.flags = $(GetExportTypeOption $(MODULE_EXPORT_TYPE)) 971 private.elf = $(BuildAxfUsingRo $(config), $(name), $(files), $(list2nd), $(flags)) 972 return $(elf) 973 else 974 return $(ORIGINAL_ExecutableElf $(config), $(name), $(files)) 975 976global.ElfUsingRo(elf, flags, files, depends) = 977 if $(ELF_FLAGS_HOOK) 978 flags = $(ELF_FLAGS_HOOK $(flags)) 979 export flags 980 return $(ORIGINAL_Elf $(elf), $(flags), $(files), $(depends)) 981 982global.BuildRr(config, name, module_list, add_debug) = 983 private.rlt_list = $(CollectRlt $(config), $(module_list)) 984 return $(MakeRr $(config), $(name), $(rlt_list), $(add_debug)) 985 986