#---------------------------------------------------------------------------- # Project: Horizon # File: CTR.commondefs.func.om # # Copyright (C)2009-2011 Nintendo Co., Ltd. All rights reserved. # # These coded instructions, statements, and computer programs contain # proprietary information of Nintendo of America Inc. and/or Nintendo # Company Ltd., and are protected by Federal copyright law. They may # not be disclosed to third parties or copied or duplicated in any form, # in whole or in part, without the prior written consent of Nintendo. # # $Rev: 36036 $ #---------------------------------------------------------------------------- #---------------------------------------------------------------------------- # Function definitions #---------------------------------------------------------------------------- public.GetBannerFile(config) = private.banner = $(config.getDefaultBannerFile) if $(defined CTR_BANNER_SPEC) private.base = $(removesuffix $(CTR_BANNER_SPEC)) return $(addprefix $(config.getObjectDirectory)$(DIRSEP), $(addsuffixes $(EXT_BANNER), $(base))) else if $(defined CTR_BANNER) return $(CTR_BANNER) elseif $(or $(and $(defined CTR_NO_BANNER_ICON), $(equal $(CTR_NO_BANNER_ICON), true)), \ $(and $(defined CTR_NO_BANNER), $(equal $(CTR_NO_BANNER), true)) ) return $(EMPTY) return $(banner) public.GetIconFile(config) = private.icon = $(config.getDefaultIconFile) if $(defined CTR_BANNER_SPEC) private.base = $(removesuffix $(CTR_BANNER_SPEC)) return $(addprefix $(config.getObjectDirectory)$(DIRSEP), $(addsuffixes $(EXT_ICON), $(base))) else if $(defined CTR_ICON) return $(CTR_ICON) elseif $(and $(defined CTR_NO_BANNER_ICON), $(equal $(CTR_NO_BANNER_ICON), true)) return $(EMPTY) return $(icon) public.GetMakeromOptions(config)= private.romfs_root = $(if $(defined ROMFS_ROOT),$`(ROMFS_ROOT),$(EMPTY)) private.title = $(if $(defined TITLE),$`(TITLE),CtrApp) private.flags[] = -DROMFS_ROOT=$(romfs_root) -DTITLE=$(title) # disable for omake2 # if $(defined CTR_BANNER_SPEC) # if $(or $(defined CTR_BANNER), $(defined CTR_ICON)) # eprintln($"CTR_BANNER CTR_ICON and CTR_BANNER_SPEC cannot be used simultaneously") # exit(1) BannerFile = $(GetBannerFile $(config)) IconFile = $(GetIconFile $(config)) if $(not $(equal $(BannerFile.length), 0)) flags += -banner $(BannerFile) export flags if $(not $(equal $(IconFile.length), 0)) flags += -icon $(IconFile) export flags return $(flags) #------------------------------------------------------- # AddRuleToMakeCci # # Overview # | # # Global variable that is referenced # None. #------------------------------------------------------- AddRuleToMakeCci(cci, elf, flags, depends) = $(cci): $(makeDirectory $(dirname $(cci))) $(cci): $(elf) $(depends) $(MAKEROM) build-romfs :value: $(getMtimeIfLarge $(elf) $(depends)) $(MAKEROM) -o $@ $< $(flags) -f card return $(cci) #------------------------------------------------------- # AddRuleToMakeCclE # # Overview # | # # Global variable that is referenced # None. #------------------------------------------------------- AddRuleToMakeCclE(ccl_e, elf, r, flags, depends) = $(ccl_e): $(makeDirectory $(dirname $(ccl_e))) $(ccl_e): $(elf) $(r) $(depends) $(MAKEROM) build-romfs :value: $(getMtimeIfLarge $(elf) $(r) $(depends)) $(MAKEROM) -o $@ $< $(flags) -lr $(r) -f le -m 0x01000000 return $(ccl_e) #------------------------------------------------------- # AddRuleToMakeCclR # # Overview # | # # Global variable that is referenced # None. #------------------------------------------------------- AddRuleToMakeCclR(ccl_r, flags, depends) = $(ccl_r): $(makeDirectory $(dirname $(ccl_r))) $(ccl_r): $(depends) $(MAKEROM) build-romfs :value: $(getMtimeIfLarge $(depends)) $(MAKEROM) -o $@ $(flags) -f lr return $(ccl_r) #------------------------------------------------------- # AddRuleToMakeCcl # # Overview # | # # Global variable that is referenced # None. #------------------------------------------------------- AddRuleToMakeCcl(ccl, e, r) = $(ccl): $(makeDirectory $(dirname $(ccl))) $(ccl): $(e) $(r) $(MAKEROM) build-romfs :value: $(getMtimeIfLarge $(e) $(r)) $(MAKEROM) -o $@ -le $(e) -lr $(r) -f list return $(ccl) #------------------------------------------------------- # AddRuleToMakeCxi # # Overview # | # # Global variable that is referenced # None. #------------------------------------------------------- AddRuleToMakeCxi(cxi, elf, flags, depends) = $(cxi): $(makeDirectory $(dirname $(cxi))) $(cxi): $(elf) $(depends) $(MAKEROM) build-romfs :value: $(getMtimeIfLarge $(elf) $(depends)) $(MAKEROM) -o $@ $< $(flags) return $(cxi) #------------------------------------------------------- # AddRuleToMakeCia # # Overview # | # # Global variable that is referenced # None. #------------------------------------------------------- AddRuleToMakeCia(cia, flags, depends) = $(cia): $(makeDirectory $(dirname $(cia))) $(cia): $(depends) $(MAKECIA) :value: $(getMtimeIfLarge $(depends)) $(MAKECIA) -o $@ $(flags) return $(cia) #------------------------------------------------------- # AddRuleToMakeCfa # # Overview # | # # Global variable that is referenced # None. #------------------------------------------------------- AddRuleToMakeCfa(cfa, srcdir, flags, depends) = $(cfa): $(makeDirectory $(dirname $(cfa))) $(cfa): $(srcdir) $(depends) $(MAKEROM) :value: $(getMtimeIfLarge $(depends)) $(MAKEROM) -o $@ -DROMFS_ROOT=$(srcdir) $(flags) -f data return $(cfa) #------------------------------------------------------- # AddRuleToMakeBanner # # Overview # | # # Global variable that is referenced # None. #------------------------------------------------------- AddRuleToMakeBanner(banner, icon, bsf) = $(banner): $(makeDirectory $(dirname $(banner))) $(icon): $(makeDirectory $(dirname $(icon))) $(banner) $(icon): $(bsf) $(MAKEBANNER) $(MAKEBANNER) $< $(banner) $(icon) AddRuleToMakeCfaFromCias(cfa, flags, depends) = $(cfa): $(makeDirectory $(dirname $(cfa))) $(cfa): $(depends) $(MAKECIAARCHIVE) :value: $(getMtimeIfLarge $(depends)) $(MAKECIAARCHIVE) -o $@ $(flags) return $(cfa) #------------------------------------------------------- # MakeCci # # Overview # Create .cci from ELF # Return the .cci path # # Global variable that is referenced # None. #------------------------------------------------------- MakeCci(config, name, elf, flags, cci_depends) = private.cci = $(config.getBinaryPath $(name), $(EXT_CCI)) return $(AddRuleToMakeCci $(cci),$(elf),$(flags), $(cci_depends)) #------------------------------------------------------- # MakeCclE # # Overview # Create the E portion of .ccl # Return the path to the E portion of .ccl # # Global variable that is referenced # None. #------------------------------------------------------- MakeCclE(config, name, elf, r, flags, depends) = private.e = $(config.getBinaryPath $(name), $(EXT_CCL_E)) return $(AddRuleToMakeCclE $(e),$(elf),$(r),$(flags),$(depends)) #------------------------------------------------------- # MakeCclR # # Overview # Create the R portion of .ccl # Return the path to the R portion of .ccl # # Global variable that is referenced # None. #------------------------------------------------------- MakeCclR(config, name, flags, cci_depends) = private.r = $(config.getBinaryPath $(name), $(EXT_CCL_R)) return $(AddRuleToMakeCclR $(r),$(flags),$(cci_depends)) #------------------------------------------------------- # MakeCcl # # Overview # Create .ccl # Return the .ccl path # # Global variable that is referenced # None. #------------------------------------------------------- MakeCcl(config, name, e, r) = private.ccl = $(config.getBinaryPath $(name), $(EXT_CCL)) return $(AddRuleToMakeCcl $(ccl),$(e),$(r)) #------------------------------------------------------- # MakeCxi # # Overview # Create .cxi from ELF # Return the .cxi path # # Global variable that is referenced # None. #------------------------------------------------------- MakeCxi(config, name, elf, flags, cxi_depends) = private.cxi = $(config.getBinaryPath $(name), $(EXT_CXI)) return $(AddRuleToMakeCxi $(cxi),$(elf),$(flags), $(cxi_depends)) #------------------------------------------------------- # MakeCia # # Overview # Create .cia from .cxi # Return the .cia path # # Global variable that is referenced # None. #------------------------------------------------------- MakeCia(config, name, flags, depends) = private.cia = $(config.getBinaryPath $(name), $(EXT_CIA)) return $(AddRuleToMakeCia $(cia), $(flags), $(depends)) #------------------------------------------------------- # MakeCfa # # Overview # Create .cfa from the directory # Return the .cfa path # # Global variable that is referenced # None. #------------------------------------------------------- MakeCfa(config, name, srcdir, flags, depends) = private.cfa = $(config.getBinaryPath $(name), $(EXT_CFA)) return $(AddRuleToMakeCfa $(cfa), $(srcdir), $(flags), $(depends)) #------------------------------------------------------- # MakeBanner # # Overview # | # # Global variable that is referenced # None. #------------------------------------------------------- MakeBanner(config, rsf) = private.banner = $(GetBannerFile $(config)) private.icon = $(GetIconFile $(config)) return $(AddRuleToMakeBanner $(banner),$(icon),$(bsf)) #------------------------------------------------------- # BuildCci # # Overview # Create .cci # Return the .cci path # # Global variable that is referenced # None. #------------------------------------------------------- BuildCci(config, name, files, cci_flags, cci_depends) = private.elf = $(ExecutableElf $(config), $(name), $(files)) private.cci = $(MakeCci $(config), $(name), $(elf), $(cci_flags), $(cci_depends)) return $(cci) #------------------------------------------------------- # BuildCcl # # Overview # Create .ccl # Return the .ccl path # # Global variable that is referenced # None. #------------------------------------------------------- BuildCcl(config, name, files, cci_flags, cci_depends, r_depends) = private.elf = $(ExecutableElf $(config), $(name), $(files)) private.r = $(MakeCclR $(config), $(name), $(cci_flags), $(r_depends)) private.e = $(MakeCclE $(config), $(name), $(elf), $(r), $(cci_flags), $(cci_depends)) private.ccl = $(MakeCcl $(config), $(name), $(e), $(r)) return $(ccl) #------------------------------------------------------- # BuildCia # # Overview # Create .cia # Return the .cia path # # Global variable that is referenced # None. #------------------------------------------------------- BuildCia(config, name, files, cxi_flags, cia_flags, cxi_depends, cia_depends) = if $(files) private.elf = $(ExecutableElf $(config), $(name), $(files)) private.cxi = $(MakeCxi $(config), $(name), $(elf), $(cxi_flags), $(cxi_depends)) cia_flags = -i $(cxi) $(cia_flags) cia_depends += $(cxi) export cia_flags export cia_depends return $(MakeCia $(config), $(name), $(cia_flags), $(cia_depends)) MakeCfaFromCias(config, name, cia_list, rsf) = private.workdir = $(makeDirectory $(makePath $(config.getObjectDirectory) $(name))) private.cfa = $(makePath $(config.getObjectDirectory) $(name)$(EXT_CFA)) private.flags = -cia $(cia_list) -rsf $(rsf) --romfs-root $(workdir) private.depends = $(cia_list) $(rsf) $(workdir) return $(AddRuleToMakeCfaFromCias $(cfa), $(flags), $(depends)) MakeChildCfa(config, cia_list) = private.rsf = $(makePath $(ROOT_RESOURCES) specfiles Child.rsf) return $(MakeCfaFromCias $(config), Child, $(cia_list), $(rsf)) MakeManualCfa(config, manual_dir, flags) = private.rsf = $(makePath $(ROOT_RESOURCES) specfiles Manual.rsf) flags += -rsf $(rsf) return $(MakeCfa $(config), Manual, $(manual_dir), $(flags), $(rsf)) #------------------------------------------------------- # InstallProgram # # Overview # | # # Global variable that is referenced # BUILDTYPES #------------------------------------------------------- InstallProgram(config, install_dir, files) = if $(not $(files)) return $(EMPTY) if $(or $(and $(config.isSdkTool),\ $(equal $(filter full,$(BUILDTYPES)),full)),\ $(and $(not $(config.isSdkTool)),\ $(not $(equal $(install_dir), $(dirname $(nth 0, $(files))))))) private.ofiles = foreach(outfile, $(files)) dst = $(install_dir)/$(basename $(outfile)) value $(AddRuleToInstall $(dst),$(outfile)) return $(ofiles) return $(EMPTY) ProgramCard(config, name, files, flags, depends) = return $(BuildCci $(config),$(name),$(files),$(flags.find cci),$(depends.find cci)) ProgramList(config, name, files, flags, depends) = return $(BuildCcl $(config),$(name),$(files),$(flags.find cci),$(depends.find cci),$(depends.find rom_fs)) ProgramImport(config, name, files, flags, depends) = return $(BuildCia $(config),$(name),$(files), \ $(flags.find cxi), $(flags.find cia), \ $(depends.find cxi), $(depends.find cia) ) #------------------------------------------------------- # Program # # Overview # Create CTR execution file # # Global variable that is referenced # BUILD_APPLICATION, LDSCRIPT_TEMPLATE, CRT_0_O, # ROMFS_DEPENDENCIES, ROMFS_ROOT, MAKEROMFLAGS, # DESCRIPTOR, ROM_SPEC_FILE, CTR_APPTYPE, # PROGRAM_BUILDER_MAP, MANUAL_DIR, CHILD_APPS #------------------------------------------------------- Program(config, name, files) = global.BUILD_APPLICATION = true private.contents = $(Map) if $(not $(defined LDSCRIPT_TEMPLATE)) LDSCRIPT_TEMPLATE = $(config.getLdscriptTemplatePath) export if $(not $(defined CRT_0_O)) CRT_0_O = crt0.o export if $(not $(defined ROMFS_DEPENDENCIES)) if $(defined ROMFS_ROOT) ROMFS_DEPENDENCIES = $(ls -R, $(dir $(ROMFS_ROOT))) export else ROMFS_DEPENDENCIES = export export # For manual if $(defined MANUAL_DIR) private.cfa = $(MakeManualCfa $(config), $(MANUAL_DIR), $(MAKEROMFLAGS)) contents = $(contents.add 1,$(cfa)) export contents # For child if $(defined CHILD_APPS) private.cfa = $(MakeChildCfa $(config), $(CHILD_APPS)) contents = $(contents.add 2,$(cfa)) export contents private.desc = $(if $(defined DESCRIPTOR),$`(DESCRIPTOR),$(config.getDefaultDescriptorPath)) private.cxi_flags = $(MAKEROMFLAGS) private.cci_flags = $(EMPTY_ARRAY) private.cia_flags = $(MAKECIAFLAGS) private.rom_fs_depends = $(ROMFS_DEPENDENCIES) private.cxi_depends = $(desc) $(ROM_SPEC_FILE) $(GetBannerFile $(config)) $(GetIconFile $(config)) private.cci_depends = $(EMPTY_ARRAY) private.cia_depends = $(EMPTY_ARRAY) cxi_flags += -desc $(desc) -rsf $(ROM_SPEC_FILE) cxi_flags += $(GetMakeromOptions $(config)) cci_flags += $(mapToArray $(contents),$(fun k,v,-content $(v):$(k))) cia_flags += $(mapToArray $(contents),$(fun k,v,-i $(v):$(k))) cci_depends += $(mapToArray $(contents),$(fun k,v,$(v))) cia_depends += $(mapToArray $(contents),$(fun k,v,$(v))) private.flags = $(Map) private.depends = $(Map) flags = $(flags.add cxi,$(cxi_flags)) flags = $(flags.add cci,$(cxi_flags) $(cci_flags)) flags = $(flags.add cia,$(cia_flags)) depends = $(depends.add rom_fs,$(rom_fs_depends)) depends = $(depends.add cxi,$(rom_fs_depends) $(cxi_depends)) depends = $(depends.add cci,$(rom_fs_depends) $(cxi_depends) $(cci_depends)) depends = $(depends.add cia,$(cia_depends)) private.app_type = if $(equal $(CTR_APPTYPE),$(APPTYPE_BOTH)) value $(APPTYPE_CARD) $(APPTYPE_NAND) else value $(CTR_APPTYPE) private.target_files = foreach (type, $(app_type)) private.builder = $(PROGRAM_BUILDER_MAP.find $(type)) if $(builder) value $(apply $(builder), $(config), $(name), $(files), $(flags), $(depends)) else eprintln($"Build Error: Unknown APPTYPE:" '$(type)') exit(1) target_files = $(stripEmpty $(target_files)) # If the tree is referenced externally, determine whether to install private.install_dir = $(config.getImageDirectory true) private.install_targets = $(InstallProgram $(config),$(install_dir),$(target_files)) return $(target_files) $(install_targets) #------------------------------------------------------- # Banner # # Overview # Create banner # # Global variable that is referenced # None. #------------------------------------------------------- Banner(config, bsf) = return $(MakeBanner $(config),$(bsf))