Build System

Contents


1. Using the omake Tool

This document describes the features of OMake. OMake is the command-line build environment of CTR-SDK. The following descriptions assume that the build environment can locate the omake executable through the PATH environment variable.

1.1 The omake Command

The omake command is a tool for automating application build and other procedures. On start, the omake command loads a file containing build rules (OMakefile in the current directory), and then calls the compiler and linker according to those rules.

CTR-SDK supports OMake version 0.9.8.5-3. It also supports OMake 0.9.8.5-3 patch 7, which includes modifications made by Nintendo.

Start the command from the Cygwin or Windows command prompt as follows.
% omake
You can change the operation of omake by using options, setting variables, and specifying the target name.
% omake [OPTIONS] [VARIABLE=SETTING] [TARGET_NAME]
To facilitate the creation of OMakefiles, CTR-SDK provides files (in the following directories) that contain frequently used build rules. You can include commondefs and modulerules in your OMakefile when building your application. For information about coding an OMakefile, see OMakefile.

1.2 omake Options

The following table describes some of the more frequently used options specific to omake.

OptionsDescription
--versionCheck the version.
-j <PARALLEL_COUNT>Perform the specified number of parallel builds.
--verboseBuild while displaying the command that is being run.
--dependIgnore dependencies in the build.
-U Ignore dependencies and the cache in the build. (This option is useful when you have deleted a header file, because it discards all cached dependencies when building.)

1.3 omake Targets

This section describes targets defined by the CTR-SDK build system.

Building

build is the default target name when the target value for omake is omitted. You can perform the omake build action simply by typing omake.

OMake starts by checking all dependencies under OMakeroot. Even if you run the omake command somewhere under OMakeroot, it performs dependent builds. The command generates the build output in a directory named for the build type of the program being built and other attributes. For example, a build directory could be named images/CTR-TS.Process.MPCore.[fast|small]/[Release|Development|Debug]. For information about how to change the target's build type and other attributes, see Build Switches.

Deleting

1.4 omake Variables

The following section describes how to use build switches. This section and Build Variables Configurable Within the CTR-SDK's OMakefile describe the omake variables.

2. How to Use Build Switches

This section describes how to use the environment variables, build options, and build variables available in the CTR-SDK build system.

2.1 Environment Variables Available When Building the SDK

The following environment variables can be configured for the CTR-SDK build system. If an option is not set, the default value is used.

Environment Variable Description
CTRSDK_ROOT
[Required]
Directory where CTR-SDK is installed (the directory into which $CTR_SDK is extracted).

Example (the Windows-format absolute path must be specified):
CTRSDK_ROOT=C:/CTR_SDK

Default: None
ARMCC41BIN
ARMCC41INC
ARMCC41LIB
Directory where the ARM compiler is installed.

Default: None. (Normally, these are set automatically during installation of the ARM compiler.)
CTRSDK_RVCT_VER Sets the ARM compiler version to use for the build. If the environment variables corresponding to the specified ARM compiler have not been set, the newest ARM compiler that supports CTR-SDK is used.
Operation is currently not guaranteed on compilers other than ARMCC 4.1.

Example (to build with ARMCC 4.1):

CTRSDK_RVCT_VER=41

Default: 41 (build with ARMCC 4.1).
CTRSDK_TARGETS Sets the target hardware and optimization type in environment variables.
The only hardware setting is TS, and the optimization type settings are fast and small.
If FILTER is set, these options are ignored.

CTR-TS.* Development hardware (debugger hardware or development system).

*.fast Optimized for speed.
*.small Optimized for size.

Example (when supporting only fast builds on development hardware):
CTRSDK_TARGETS=CTR-TS.Process.MPCore.fast
Example (when supporting both fast and small builds on development hardware):
CTRSDK_TARGETS=CTR-TS.Process.MPCore.*

Default: CTR-TS*MPCore* (when supporting both fast and small on development hardware).

2.2 Build Options Available When Building the SDK

The following build options are used when building the CTR-SDK (using the build system).
They can be specified as arguments to the omake command.
If an option is not set, the default value is used.

Build Options Description
BUILD Sets the target build type.
The four possible settings are Debug, Development, Release, and full. Specify full to build all build types. You can specify multiple types by delimiting them with commas.

Changing this setting changes the compile options and the libraries that are linked when running the omake command.

The details for each build type are as follows.
Features Debug Development Release
Operations Guaranteed No Software to Be Tested
Debug Output Functions From OS API Enabled Disabled
Application Optimization OFF ON
Library Optimization OFF ON
CTR-SDK Internal Debugging Code Enabled Disabled
ASSERT Enabled Disabled
HostIO Enabled Disabled

Debug builds disable the gnu extensions.
Although debug information is included in the Release build object files, it is removed by makerom.

Default: Development
DEBUG_PRINT Enables or disables debug output functions regardless of build type.
Specifying true to the macro enables NN_LOG (OS debug output); specifying false leaves NN_LOG empty.

However, the debug output used in CTR-SDK cannot be enabled or disabled.

Default: For release builds, false; otherwise, true.
ASSERT_WARNING Enables or disables ASSERTs and WARNINGs regardless of build type.
Specifying true to the macro enables NN_*ASSERT/NN_WARNING; specifying false leaves NN_*ASSERT/NN_WARNING empty.

However, CTR-SDK ASSERTs and WARNINGs cannot be enabled or disabled.

Defaults: For release builds, false; otherwise, true.
FILTER Sets the target hardware and optimization type.
The only hardware setting is TS, and the optimization type settings are fast and small.
If these are set, the CTRSDK_TARGETS setting is ignored.

CTR-TS.* Development hardware (debugger hardware or development system).

*.fast Optimized for speed.
*.small Optimized for size.

Example (when supporting only fast builds on development hardware):
FILTER=CTR-TS.Process.MPCore.fast
Example (when supporting both fast and small builds on development hardware):
FILTER=CTR-TS.Process.MPCore.*

Default: CTR-TS*MPCore* (when supporting both fast and small on development hardware).

2.3 Build Variables Configurable Within the OMakefile of CTR-SDK

The following options are available for setting build conditions per directory in the CTR-SDK OMakefile.
If an option is not set, the default value is used.

If you specify a path for the following build variables, you must generally specify the Windows-format absolute path or the relative path. You must generally set these build variables before referencing modulerules.
Build Variable Description
SUPPORTED_TARGETS
[Required]
Sets the targets supported by the program.
The only available hardware setting is TS, and the optimization type settings are fast and small.

CTR-TS.* Development hardware (debugger hardware or development system).

*.fast Optimized for speed.
*.small Optimized for size.

Example (when supporting only fast builds on development hardware):
SUPPORTED_TARGETS = CTR-TS.Process.MPCore.fast
Example (when supporting both fast and small builds on development hardware):
SUPPORTED_TARGETS = CTR-TS.Process.MPCore.*

Default: None
CTR_APPTYPE Sets the type of CTR application to create. You can specify multiple types by delimiting them with spaces.
You must configure this variable between the include statements for commondefs and modulerules.

CARD Creates a CCI file for card-based software.
NAND Creates a CIA file for DLP child devices.
SD Creates a CIA file for downloadable applications.
LIST Creates a CCL file.

Default: CARD.
SOURCES Enumerates the source files to compile or assemble.
The build system attempts to generate object files, using the compiler or assembler, for the file extensions .c, .cpp, or .s.
You must configure this variable between the include statements for commondefs and modulerules.

Default: None
INCLUDES Specifies the directory if there are any include files specific to this program.
By default, this variable is set to the $CTR-SDK/include and $OMAKEROOT/include directories. Any additional settings must be specified using the += operator.
You must configure this variable between the include statements for commondefs and modulerules.

Default: $CTR-SDK/include, $OMakeroot/include.
OBJECTS Specifies the object files to link.

Example (linking object file xxx.o):
OBJECTS = xxx.o

Default: None
LIBS Specifies the libraries to link. The extension is not needed.
The build system automatically links several standard libraries, but any special libraries required for a specific program must be explicitly specified.

A fast build normally links in the libnn_xxx.fast library to match the optimization type, but it is also possible to explicitly specify libnn_xxx.fast.
In this case, the specified library is linked regardless of the optimization type.

This variable is set by default to the standard library, so any additional settings must be specified using the += operator.
You must configure this variable between the include statements for commondefs and modulerules.

Example (to link against the additional library libnn_xxx):
LIBS += libnn_xxx
Example (to link against the additional library libnn_xxx.fast):
LIBS += libnn_xxx.fast

Default: Standard library (see $CTR_SDK/build/omake/platforms/CTR.targetdefs.om).
LIBFILES Specifies program-specific libraries to link when building an image with TARGET_PROGRAM specified.
You must configure this variable between the include statements for commondefs and modulerules.

Example (to add the $TMP/libraries/CTR-TS.Process.MPCore/release/libnn_xxx.[fast|small].a library):
LIBFILES = $(TMP)/libraries/CTR-TS.Process.MPCore/release/libnn_xxx

Default: None
LIBRARY_LIBFILES Specifies program-specific libraries to link when building an image with TARGET_LIBRARY specified.
You must configure this variable between the include statements for commondefs and modulerules.

Example (to add the $TMP/libraries/CTR-TS.Process.MPCore/release/libnn_xxx.[fast|small].a library):
LIBRARY_LIBFILES = $(TMP)/libraries/CTR-TS.Process.MPCore/release/libnn_xxx

Default: None
TARGET_PROGRAM Specifies the name of the image to generate. The extension is not needed.
Links the object files created by compiling or assembling the source files specified in SOURCES and creates the target file. The extension of the created target file is normally .cci.
Note that the defined macro is different when specifying TARGET_PROGRAM or TARGET_LIBRARY.

Default: None
TARGET_LIBRARY
[Caution]
Specifies the names of the library to build. The extension is not needed.
Compiles or assembles the source files specified by SOURCES and links the resulting object files to create the library.
Note that the defined macro is different when specifying TARGET_PROGRAM or TARGET_LIBRARY.

Default: None
CCFLAGS Set this variable when you want to change the options passed to the compiler when compiling source files or creating linker script files.
This variable is set to the required options by default. Any additional options must be specified using the += operator.

Default: See $CTR_SDK/build/omake/compilers/commondefs.cctype.RVCT.om.
CCFLAGS_WARNING
[Caution]
Set this variable when you want to change the warning options passed to the compiler.
Always set the warning options using this variable, not CCFLAGS.
This variable is set to the required options by default. Any additional options must be specified using the += operator.

Default: See $CTR_SDK/build/omake/compilers/commondefs.cctype.RVCT.om.
CCFLAGS_DEV_OPT To change the optimization level of an application in a Development build, set this variable. The specified optimization level does not affect Release or Debug builds.

Default: See $CTR_SDK/build/omake/compilers/commondefs.cctype.RVCT.om.
CFLAGS Set this variable when you want to change the options passed to the compiler only when compiling C files.
This variable is set to the required options by default. Any additional options must be specified using the += operator.

Default: See $CTR_SDK/build/omake/compilers/commondefs.cctype.RVCT.om.
CXXFLAGS Set this variable when you want to change the options passed to the compiler only when compiling C++ files.
This variable is set to the required options by default. Any additional options must be specified using the += operator.

Default: See $CTR_SDK/build/omake/compilers/commondefs.cctype.RVCT.om.
ASFLAGS Set this variable when you want to change the options passed to the compiler only when compiling assembler files.
This variable is set to the required options by default. Any additional options must be specified using the += operator.

Default: See $CTR_SDK/build/omake/compilers/commondefs.cctype.RVCT.om.
LDFLAGS Set this variable when you want to change the options passed to the linker.
This variable is set to the required options by default. Any additional options must be specified using the += operator.

Default: See $CTR_SDK/build/omake/compilers/commondefs.cctype.RVCT.om.
LDFLAGS_WARNING Set this variable when you want to change the warning options passed to the linker.

This variable is set to the required options by default. Any additional options must be specified using the += operator.

Default: See $CTR_SDK/build/omake/compilers/commondefs.cctype.RVCT.om.
ENABLE_CPP_EXCEPTION Set this variable to true to enable C++ exceptions.
You must configure this variable between the include statements for commondefs and modulerules.

Default: false.
INSTALL_ROOT
[Caution]
Specifies the absolute or relative path to the installation directory.
Use to change the installation directory for libraries and target files.
This variable must be set before the commondefs file is included. (Setting the variable within OMakeroot is one way of ensuring this.)

Example (to change the installation directory to .tmp):
INSTALL_ROOT = ./tmp

Default: None
HostIO If set to true, HostIO is enabled regardless of build type.

Defaults: For release builds, false; otherwise, true.
TARGET_BUILDTYPES Specifies the build type specified on the command line.
Use this variable to exclude a particular build type or in other such cases.
If you reference or set this variable, you must do so between the include statements for commondefs and modulerules.

Example (to exclude Debug builds):

TARGET_BUILDTYPES = $(filter Release Development, $(TARGET_BUILDTYPES))

Default: None
CHILD_APPS Specifies the child program to use for Download Play distribution.
You must specify the directory path for this variable in Windows format, using the absolute or relative path. You must set this variable before referencing modulerules.

Example (specifying a fast child in a Release build):

CHILD_APPS[] = ../Child/images/CTR-TS.Process.MPCore.fast/Release/Child.cia

Default: None
MANUAL_DIR Use this variable to add an e-manual to the application.
Whether it is necessary to add an e-manual to the application depends on the application. For MANUAL_DIR, specify the directory where the e-manual resides. Place one file in this directory and name the file Manual.bcma.
You must specify the directory path for this variable in Windows format, using the absolute or relative path. You must set this variable before referencing modulerules.

Input example (from SampleDemos/demo1/OMakefile):)
MANUAL_DIR = ./manual

Default: None

ctr_makerom

The following settings are reflected in ctr_makerom, even though they are build variables that configure build conditions separately for each directory in the CTR-SDK's OMakefile.

Build Variable Description
ROM_SPEC_FILE Specifies an RSF file describing the contents of a ROM file (RomSpecFile).
The specified file is passed to ctr_makerom using the -rsf option. The file's settings serve as the basis to the creation of CCI files.
You must configure this variable between the include statements for commondefs and modulerules.

Default: $CTR-SDK/resources/specfiles/Application.rsf.
DESCRIPTOR Specifies the DESC file.
The specified file is passed to ctr_makerom with the -desc option, and the CCI files are created based on the settings in this file.
Default: $CTR-SDK/resources/specfiles/Application.desc.
MAKEROMFLAGS Set this variable when you want to specify the options passed to ctr_makerom.
You must configure this variable between the include statements for commondefs and modulerules.

Default: None
ROMFS_ROOT Specifies the root path of the file system to include in the ROM. Although setting this variable has the same effect as setting the HostRoot in the Rom section of the RSF file (except for the following point), if both are set HostRoot has precedence.
  • When HostRoot is specified in the RSF file, no dependency relationships are set between files and directories under the specified directory. Also, a rebuild is not performed even if the files under the ROM file system have been updated.
When you want to set the dependency relationships for files and directories under the directory specified in the RSF file, you must set them with ROMFS_DEPENDENCIES. This variable is also passed to ctr_makerom using -DROMFS_ROOT=. You can reference this value in RSF with the string "$(ROMFS_ROOT)". You must set this variable before referencing modulerules.

Default: None
ROMFS_DEPENDENCIES Sets dependency relationships for files under the specified ROM file system.

Files under the directory specified in ROMFS_ROOT are configured in ROMFS_DEPENDENCIES in the build system.
Note that when setting dependency relationships for files specified in the RSF file, they must be set explicitly with this variable.

You must set this variable before referencing modulerules.

Default: None
TITLE Specifies the value passed to ctr_makerom in -DTITLE=.
The value can be referenced in the RSF file by using $(TITLE).

Default: CtrApp.
CTR_BANNER Specifies the banner file. The specified value is passed to ctr_makerom by using the -banner option.
You must specify CTR_NO_BANNER = true or CTR_NO_BANNER_ICON = true when not using banners. The default value is used if this specification is omitted.
If CTR_BANNER_SPEC is set, these options are ignored.

Default: $CTR_SDK/resources/banner/Default.bnr.
CTR_ICON Specifies the icon file. You can pass the specified value to ctr_makerom by using the -icon option.
You must specify CTR_NO_BANNER_ICON = true if you are not using icons. The default value is used if this specification is omitted.
If CTR_BANNER_SPEC has been set, this setting is ignored.

Default: $CTR_SDK/resources/banner/Default.icn.
CTR_NO_BANNER This variable must be set to true if not using banners.
If CTR_BANNER_SPEC has been set, this setting is ignored.

Default: None
CTR_NO_BANNER_ICON This variable must be set to true if you are not using banners or icons.
If CTR_BANNER_SPEC has been set, this setting is ignored.

Default: None
CTR_BANNER_SPEC Specifies the BSF file to use as input to ctr_makebanner (BSF: BannerSpecFile).
The files generated by ctr_makebanner are input into ctr_makerom unchanged using the -banner and -icon options.
If these options are set, the CTR_BANNER, CTR_ICON, CTR_NO_BANNER, and CTR_NO_BANNER_ICON settings are ignored.

Default: None

Shader Assembler and Linker

The following settings relate to the shader assembler and linker, even though they are build variables that configure build conditions separately for each directory in the CTR-SDK OMakefile.

Build Variable Description
SHADER_SOURCES Enumerates the vertex shader assembler files (.vsh) to compile or assemble.

Default: None
SHADER_INCLUDES Specifies the directory containing include files referenced when compiling vertex shader assembler files.
By default, this variable is set to the $CTR_SDK/resources/shaders directory, so any additional settings must be specified using the += operator.
You must configure this variable between the include statements for commondefs and modulerules.

Default: $CTR_SDK/resources/shaders.
SHADER_OBJECTS Enumerates the object files to add during the shader binary build.

Default: None
SHADER_OBJECTS_PREBUILT Enumerates the object files to add during the shader binary build.
This variable is used only for reserved geometry shaders.
Specify the object files using paths relative to $CTR_SDK/resources/shader.

Default: None
TARGET_SHADER Specifies the names of the shader binary (SHBIN) files that are ultimately output. The extension is not needed.
If you explicitly specify an empty name, the build system only assembles without linking.

Default: shader.
SHBIN_INSTALL_ROOT Specifies the installation root directory for the shader binary file.

Default: Value of ROMFS_ROOT.
SHADER_BINARY Sets the full path of the shader binary file.
To use, set this path after including modulerules.

Default: Full path to the SHBIN file.
SHADER_ASFLAGS Set this variable to change the options assigned to the assembler when assembling vertex shader assembly language files (VSH files).
If you specify the -I or -O options, use the respective build options.

Although currently nothing is set by default, use the += operator to specify additional options.
You must configure this variable between the include statements for commondefs and modulerules.

Default: None
SHADER_LDFLAGS Set this variable when you want to change the options passed to the vertex shader linker.
If you specify the -I or -O options, use the respective build options.

Options are set in this variable by default. Use the += operator to specify additional options.
You must configure this variable between the include statements for commondefs and modulerules.

Default: -M.

3. Macros

This section describes the C/C++ macros defined by the CTR-SDK.
These macros can access values inside source code. They are used even inside CTR-SDK to switch various features.

Macros Description
NN_BUILD_DEVELOPMENT This macro is defined when building the image specified by TARGET_PROGRAM using the Development build type.
Note that this macro is not defined when building an image specified by TARGET_LIBRARY.

NN_BUILD_RELEASE This macro is defined when building the image specified by TARGET_PROGRAM using the Release build type.
Note that this macro is not defined when building an image specified by TARGET_LIBRARY.

NN_BUILD_VERBOSE This macro is defined when making builds using the Debug or Development build type.

NN_EFFORT_FAST This macro is defined when making builds using the "fast" optimization type.

NN_EFFORT_SMALL This macro is defined when making builds using the "small" optimization type.

NN_SWITCH_DISABLE_DEBUG_PRINT This macro is defined when making builds using the Release build type if false has been specified for DEBUG_PRINT, or if DEBUG_PRINT has not been specified.
NN_SWITCH_DISABLE_ASSERT_WARNING This macro is defined when making builds using the Release build type if false has been specified for ASSERT_WARNING, or if ASSERT_WARNING has not been specified.

4. OMakefile

Normally, projects that use OMake have an OMakefile in each directory and OMakeroot in the project's root directory. General build settings are specified in OMakeroot, and build parameters specific to each subdirectory are specified in each OMakefile.

This approach is also taken by the Sample Demos package in CTR-SDK: There is an OMakefile in each directory and an OMakeroot directly under SampleDemos. The OMakefile files include modulerules (build rules), while OMakeroot includes commondefs (general build options).

Note: The following description assumes that your project has the same structure as SampleDemos.

Start by describing the minimum settings needed to build an application.

4.1 Required Settings for Creating Applications

Required variables: SUPPORTED_TARGETS, SOURCES, TARGET_PROGRAM
SUPPORTED_TARGETS = CTR-TS.Process.MPCore.*    # Target both fast and small builds.

SOURCES[]         = main.cpp                   # Build the source file "main.cpp."

TARGET_PROGRAM    = test                       # The name of the image to generate is "test."


#---- In general, do not change the following line unless you want to define your own build rules.
include $(ROOT_OMAKE)/modulerules    # Include modulerules.

build: $(DEFAULT_TARGETS)            # Configure the rule to run when building.

4.2 Settings for Specific Uses

This section describes how to write an OMakefile. It is based on a specific real-world scenario.
Note: This code is generally placed before the include statement for modulerules in Required Settings for Creating Applications.

Settings Required to Create Applications for Master Submission

Required variables: TITLE, ROMFS_ROOT, CTR_BANNER, CTR_ICON, ROM_SPEC_FILE, DESCRIPTOR
#---- TITLE and ROMFS_ROOT can also be specified in the RSF file.
TITLE             = CtrApp     # Specify the title of the application.
ROMFS_ROOT        = ./romfs    # Specify the ROMFS root path.

#---- CTR_BANNER and CTR_ICON can also be specified in the BSF file using CTR_BANNER_SPEC.
CTR_BANNER        = $(CTRSDK_ROOT)/resources/banner/Default.bnr          # Specify the banner file.
CTR_ICON          = $(CTRSDK_ROOT)/resources/banner/Default.icn          # Specify the icon file.


ROM_SPEC_FILE     = $(CTRSDK_ROOT)/resources/specfiles/Application.rsf   # Specify the RSF file.
DESCRIPTOR        = $(CTRSDK_ROOT)/resources/specfiles/Application.desc  # Specify the DESC file.

Settings Required to Create Applications for Download Play

Required variables: CHILD_APPS, CTR_APPTYPE, ROM_SPEC_FILE, DESCRIPTOR, CTR_ICON

Parent
CHILD_APPS[]      = ../Child/images/CTR-TS.Process.MPCore.fast/Release/Child.cia  # Specify child programs.
Child
CTR_APPTYPE       = NAND
CTR_ICON          = Child.icn                                         # Specify the child icon.

ROM_SPEC_FILE     = Child.rsf                                         # Specify UniqueId and ChildIndex in the child RSF file.
DESCRIPTOR        = $(CTRSDK_ROOT)/resources/specfiles/DlpChild.desc  # Specify the DESC file for the children.

Settings Required to Create Downloadable Applications

Required variables: CTR_APPTYPE, MANUAL_DIR
CTR_APPTYPE       = SD
MANUAL_DIR        = ./manual    # Specify the directory where the e-manual is stored.

Branching Conditions by Build Type

Required variables: TARGET_BUILDTYPES

The following example illustrates how to create a Release build only in the "test" directory.
if $(equal $(filter Release,$(TARGET_BUILDTYPES)),Release)
    .SUBDIRS: $(exist-dirs test)

CTR-06-0205-002-J
CONFIDENTIAL