Build System

Build System

Table of Contents


1. Using the omake Tool

This document describes the features of OMake. OMake is the CTR-SDK's command-line build environment. 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. Upon launch, the omake command loads a file containing build rules (OMakefile in the current directory) and then calls the compiler and linker in accordance with 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 behavior 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. See OMakefile for instructions on coding an OMakefile.

1.2 omake Options

The table below 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
--verboseBuilding While Displaying the Command Being Run
--dependIgnore dependencies in build
-U Ignore dependencies and cache in build. (This is handy 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 thus perform the action of omake build simply by entering omake.

OMake starts by checking all dependencies under OMakeroot. Thus 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]. See Build Switches below, for information about how to change the target's build type and other attributes.

[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 Variables 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 specifiable hardware is TS, and the specifiable optimization types 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 are build options used when building the CTR-SDK (using the build system).
These 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 Yes
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.

Default: For release builds: false; Otherwise: true.
FILTER Sets the target hardware and optimization type.
The only specifiable hardware is TS, and the specifiable optimization types 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 CTR-SDK's OMakefile

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 build variables below, 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 specifiable hardware is TS, and the specifiable optimization types 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 be compiled or assembled.
The build system attempts to generate object files using the compiler or assembler that is appropriate for a given file extension, such as .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 file name 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 here.

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 you want 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 you want 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 file name 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 and TARGET_LIBRARY.

Default: None.
TARGET_LIBRARY
* CAUTION
Specifies the names of the library to build. The file name 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 and 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.
The warning options should always be set 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 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.
HOST_IO If set to true, HostIO is enabled regardless of build type.

Default: For release builds: false; Otherwise: true.
TARGET_BUILDTYPES Specifies the build type specified on the command line.
Use this variable if you want 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 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 file specified here is passed to ctr_makerom using the -rsf option, and the CCI files are created based on the settings in this file.
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 file specified here 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 one point below), if both are set then HostRoot has precedence.
  • When HostRoot is specified in the RSF file, it is not set in the dependency relationships for files and directories under the specified directory. And a build will not be performed, even if the files under the ROM file system are updated.
When you would like to set the dependency relationships for files and directories under the directory specified in the RSF file, they must be set with ROMFS_DEPENDENCIES. This variable is also passed to ctr_makerom using -DROMFS_ROOT=, so 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. However, when setting dependency relationships for files specified in the RSF file, note that 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 value specified here 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, otherwise 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. The value specified here can be passed to ctr_makerom by using the -icon option.
You must specify CTR_NO_BANNER_ICON = true if not using icons, otherwise 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.icn
CTR_NO_BANNER This variable must be set to true if not using banners.
If CTR_BANNER_SPEC is set, these options are ignored.

Default: None.
CTR_NO_BANNER_ICON This variable must be set to true if not using banners or icons.
If CTR_BANNER_SPEC is set, these options are 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 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 be compiled or assembled.

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 be added during the shader binary build.

Default: None.
SHADER_OBJECTS_PREBUILT Enumerates the object files to be added during the shader binary build.
This variable is only used 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 file name extension is not needed.
If you explicitly specify an empty name, the build system assembles without linking.

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

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

Default: Full path to 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, however, 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, however, 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 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 a "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 a "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 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 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 is also the approach 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.

We 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 source file "main.cpp"

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


#---- In general, you should 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 concrete 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 application's title
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 banner file
CTR_ICON          = $(CTRSDK_ROOT)/resources/banner/Default.icn          # Specify icon file


ROM_SPEC_FILE     = $(CTRSDK_ROOT)/resources/specfiles/Application.rsf   # Specify RSF file
DESCRIPTOR        = $(CTRSDK_ROOT)/resources/specfiles/Application.desc  # Specify 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 child icon

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

Settings Required to Create Download Applications

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

Branching Conditions by Build Type

Required variables: TARGET_BUILDTYPES

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

CTR-06-0205-002-I
CONFIDENTIAL