SDK Build Switches

# Build Switches

## Environment Variables Required When Building the SDK

Below are the environment variables you must set when building the TWL-SDK tree. The default values are used if a given setting is missing. For more information about the range in which each build switch can be set, see the Build Switch Usage Table.

TWLSDK_ROOT (NITROSDK_ROOT) * Important | Directory where the TWL-SDK is installed (the directory into which `$TwlSDK` is extracted). Initial value: `C:/TwlSDK`

TWLSDK_PLATFORM
* Important

Platform to build for.
By using this environment variable, you can compile for only the desired platform.
For example, if developing only TWL applications with TWL-SDK, set the environment variable to "`TWLSDK_PLATFORM=TWL`". Doing so causes the compiler to generate code only for TWL, without generating any unnecessary NITRO code.
When not specified, the build halts with an error.

TWL | Generates code for TWL.
NITRO | Generates code for NITRO.
ALL | Generates code for both TWL and NITRO.
TWL NITRO

Initial value: Unspecified

CWFOLDER_TWL
(CWFOLDER_NITRO)

Directory where CodeWarrior is installed.
If you install CodeWarrior for NITRO, `CWFOLDER_NITRO` is configured automatically.
When making this setting with Cygwin bash, you must enclose the directory in single quotes as follows.
`% export CWFOLDER_NITRO='D:/Program Files/Freescale/CW for NINTENDO DS V2.0'`
When making this setting with a Windows environment variable, the specification takes the form given below.
`D:/Program Files/Freescale/CW for NINTENDO DS V2.0`
Both `/` and `\` work as path delimiters.
Initial value: None (usually set when CodeWarrior is installed)

LM_LICENSE_FILE | License file path for CodeWarrior. Initial value: None (usually set when CodeWarrior is installed)
IS_TWL_DEBUGGER_DIR (IS_NITRO_DIR) | Installation folder for IS-TWL-DEBUGGER-related files. It is automatically set when IS-TWL-DEBUGGER is installed. If this environment variable exists, the IS-TWL-DEBUGGER-related libraries are linked automatically. Initial value: None (usually set when IS-TWL-DEBUGGER is installed)

## Build Switches When Building the SDK

The build switches that change the build conditions for the TWL-SDK tree are shown below.
Normally, these values are set by specifying them as parameters to the `make` command (for example, `make TWL_DEBUG=TRUE`) and including them in makefiles, though they can also be set with standard environment variables. The default values are used if a given setting is missing. For more information about the ranges in which each build switch can be set, see the Build Switch Usage Table.
The values of the TWL environment variables (`TWL_*`) are given priority if changes are made to the environment variables below. (If `TWL_PROC=ARM9` and `NITRO_PROC=ARM7` are both present in a makefile at the same time, `ARM9` is set.)

TWL_PROC
(NITRO_PROC)
* No change necessary

Sets which processor to generate code for: the ARM9 (main processor), or the ARM7 (subprocessor).
Use the default value unchanged.

ARM9 | Generates code for the ARM9 (main processor). Default Value
ARM7 | Generates code for the ARM7 (subprocessor).

TWL_ARCHGEN

For TWL code, sets whether to generate TWL-exclusive code or NITRO/TWL hybrid code.
This build switch may be rewritten in the build system.
Specifically, this sets whether limited or hybrid code is being built.
If you want to reference this build switch in the makefile, do so after `commondefs`.

LIMITED | Generates TWL-exclusive code.
HYBRID | Generates NITRO/TWL hybrid code. Default Value
ALL | Generates both limited and hybrid code.
LIMITED HYBRID

TWL_CODEGEN
(NITRO_CODEGEN)

Sets whether binary code generated by the compiler and assembler should use the ARM or THUMB instruction set.
If this is not set explicitly in the source code, the code is generated according to this setting.
If you want to reference the value set for this build switch in the makefile, do so after `commondefs`.

ARM | Generates ARM code. Default Value
THUMB | Generates THUMB code.
ALL | Generates both ARM code and THUMB code.
ARM THUMB

TWL_DEBUG
(NITRO_DEBUG)
TWL_RELEASE
(NITRO_RELEASE)
TWL_FINALROM
(NITRO_FINALROM)
* Important

Select from the following build types: DEBUG, RELEASE, and FINALROM.
When the `make` command is executed, the compile options and the linked libraries change according to this setting.
Unlike other variables, this variable is enabled by setting it to one of the three values (such as `TRUE`).
See `$TwlSDK/man/en_US/information/compiletarget.html` (Description of Compile Targets) for more information about these three options.
Initial value: When not specified, the RELEASE version is built.

TWL_STD_PCHDR
(NITRO_STD_PCHDR)
TWL_NO_STD_PCHDR
(NITRO_NO_STD_PCHDR)

When a value is set for `TWL_STD_PCHDR`, the build system precompiles `$TwlSDK/include/twl.h` and loads the result during the file build. This should result in a faster build.
To temporarily suppress this compile, set a value in `TWL_NO_STD_PCHDR`.
Initial value: `TWL_STD_PCHDR`=True

TWLSDK_LANG
(NITROSDK_LANG)

Switches the TWL-SDK compile options between Japanese and English.
For Japanese, the `-enc SJIS` option is set. For English, the `-enc ascii` option is set.

jp | Japanese [Default value]
en | English

TWL_ROMSPEED
(NITRO_ROMSPEED)

When you use the default RSF file, this assigns the specified value to the `RomSpeedType` parameter in the Property section. Specifically, the value of the `MAKEROM_ROMSPEED` symbol passed to the `makerom.TWL.exe` tool is used. When you use an original file instead of the default RSF file, this is ignored. For information on the `RomSpeedType` parameter, see the documentation for the `makerom.TWL.exe` tool. MROM cannot be used with TWL.

1TROM | One-time PROM
MROM | Mask ROM
UNDEFINED | None specified [Default value]

TWL_COMPRESS (NITRO_COMPRESS) * Important | When some value is specified here, the STATIC and OVERLAY segments are compressed after linking. Initial value: None (no compression)
TWL_DIGEST (NITRO_DIGEST) | This build switch is enabled only for applications. It is ignored when building the SDK. If some value is set here, the application is built as a DS Download Play child program that uses overlays. Initial value: None.

TWL_PROFILE
(NITRO_PROFILE)

If some value is set here, the `-profile` option is added when compiling. This is primarily used with DEBUG builds so that input and output of each function can be traced when the application runs.
For details of use, see the `OS_DumpCallTrace` function.
Initial value: None (`-profile` option is disabled)

TWL_MEMSIZE
(NITRO_MEMSIZE)
* No change necessary

Specifies the main memory size of TWL compile targets. Specifying this with a build switch is the old method, which was retained for backward compatibility. The current, more convenient method is to use the `OS_EnableMainExArena` function instead. We recommend the current method because it does not require you to rebuild the SDK.
Use the default value unchanged.

TWL_MEMSIZE
16M | 16 MB [Default value]
32M | 32 MB

NITRO_MEMSIZE
4M | 4 MB [Default value]
8M | 8 MB

TWL_NO_OPT_G (NITRO_NO_OPT_G) | When some value is set here, the `-g` option specified during normal compilation and linking is removed. Programmers can expect a reduction in linking times that become an issue in large projects. Initial value: None (`-g` option enabled)

TWL_SVC_WAITVBLANK_COMPATIBLE
(NITRO_SVC_WAITVBLANK_COMPATIBLE)

Define this when you do not want to automatically replace `SVC_WaitVBlankIntr` function calls with `OS_WaitVBlankIntr` function calls. However, by specification the `SVC_WaitVBlankIntr` function does not release resources to low-priority threads, and that may cause problems depending on how the function is used. If you absolutely must use the old system calls, you should do so only after thorough verification.
Note: This replacement is made using a `#define` statement inside a header file, so it is valid only after the TWL-SDK is rebuilt.
If this environment variable is defined during `make`, `SDK_SVC_WAITVBLANK_COMPATIBLE` is defined, and you can find it in the source through `#ifdef`/`#endif` statements.
This switch is not defined by default, so `SVC_WaitVBlankIntr` function calls are automatically replaced with `OS_WaitVBlankIntr` function calls.
Initial value: None.

CW_LIBFP

Specify any one of the following floating-point libraries to the CodeWarrior compiler.
If nothing is specified, the default value is used.
For details on the differences in performance between the libraries, see the CodeWarrior reference.

FP_fastI_v5t_LE.a | Fast IEEE [Default value]
FP_fixedI_v5t_LE.a | Fixed-rounding IEEE
FP_fullI_v5t_LE.a | Full IEEE
FP_flush0_v5t_LE.a | Flush to zero (not IEEE compatible)

## Build Switches Set in the SDK Makefiles

The following table shows the build switches that configure the build conditions for each directory in the TWL-SDK makefiles.
These settings specify the locations in source code as well as the makefiles to concatenate.
When not configured, the default value is used.

TARGET_PLATFORM
* Important

In the makefile, sets whether to actually perform the build based on the build target platform.
For example, to create a demo that you want to build only in TWL mode, include `TARGET_PLATFORM=TWL` in the makefile for that demo. This builds the demo only in TWL mode, and prevents it from being built in NITRO mode.
If this setting is not present in a makefile, there are no restrictions on the platforms for which code is generated.

TWL | Build only when the build target is TWL.
NITRO | Build only when the build target is NITRO.
ALL | Always build. (Build only when the build target is TWL or NITRO.) [Default value]
TWL NITRO

TWL_BUILD_TYPE NITRO_BUILD_TYPE Rewriting Prohibited | The target build type is set here as DEBUG, RELEASE, or FINALROM. If you want to reference the build type in the makefile, reference this variable after `commondefs`.

DEFAULT_COMP_ARM7
* Important

Sets in the makefile what ARM7 components to use.
For more information on ARM7 components, see `$TwlSDK/docs/TechnicalNotes/AboutComponents.pdf`.

mongoose | Uses the `mongoose` component for NITRO ROMs and the `mongoose.TWL` component for hybrid ROMs.
ichneumon | Uses the `ichneumon` component for NITRO ROMs and the `ichneumon.TWL` component for hybrid ROMs.
racoon | Uses the `racoon.TWL` component for limited ROMs.
ferret | Uses the `ferret.TWL` component for limited ROMs.

Initial value: `mongoose` for NITRO or hybrid ROMs, `racoon` for limited ROMs

SUBDIRS * Important | Enumerates the directories you want the make process to concatenate. Initial value: None.
SUBMAKES | Enumerates the makefiles you want the make process to concatenate. Initial value: None.

SRCS
* Important

Enumerates the source files you want to compile and assemble.
The `make` command tries to generate an object file by the compiler or assembler of the programming language shown in the following table, according to the extension of each file.

Extension | Programming Language
`.c` | C
`.cpp` | C++
`.s` | Assembler (assembly language)

Initial value: None.

SRCS_OVERLAY For overlay | Enumerates the source files you want to compile and assemble. The object files generated from the files specified here are registered as belonging to an OVERLAY group.
SRCDIR | Specifies the directory for source code files. Initial value: `./src` (indicates the specified directory using `src`, a relative path from the make directory)
INCDIR | Specifies the directory of any private include files (module-specific include files). Initial value: `./include`
OBJDIR BINDIR LIBDIR Rewriting Prohibited | Specifies the directory where the `make` command outputs temporary files. Because this directory may change to accommodate the source tree, avoid overwriting this in the makefiles in individual directories.
LCFILE | Specify this to use your own link command file (LCF). Initial value: `$TwlSDK/include/nitro/ARM9.TS.lcf`
LCFILE_SPEC | Specifies the configuration file to use as the base when automatically generating link command files with the `makelcf` command. Initial value: Unspecified
ROM_SPEC | Specifies the file that describes the contents of the ROM file. This file is passed to the `makerom` command, and the ROM is generated based on the configuration of this file.

TARGET_BIN
* Important

Specifies a target file in SRL or TEF format.
It compiles or assembles the source files specified by `SRCS` and links the resulting object files, making them the target files. A TEF file is created automatically if an SRL file is specified as the target.
The following values cannot be set for this variable.

- Values that include hyphens ("`-`")
- Values that begin with an underscore ("`_`")
- Values that begin with a number

TARGET_LIB | Specify this to create a library file. It compiles or assembles the source files specified by `SRCS` and links the resulting object files, making them a library. Normally, `TARGET_BIN` and `TARGET_LIB` are not configured at the same time.
TARGET_OBJ | Specify this to create an object file as a target. This is not normally used. In the library, this is used when `crt0.c` is compiled and installed as a library.

TARGETS
Rewriting Prohibited

When this is specified, items appended with relative paths are configured automatically in `TARGET_BIN` and `TARGET_LIB`.
The storage directories for SRL and `.a` files change depending on the `TWL_PLATFORM` and `TWL_DEBUG/TWL_RELEASE/TWL_FINALROM` settings.
This macro was prepared to absorb this change.

INSTALL_TARGETS | Enumerates the files you want to install. The `TARGETS` setting described above is valid to specify here. Initial value: None.
INSTALL_DIR | Sets the installation directory. Initial value: None.
LINCLUDES | Specifies the directory of any other include files. Initial value: None.
LLIBRARY_DIRS LLIBRARIES | If there are other library files, this enumerates their directories with `LLIBRARY_DIRS` and the library files with `LLIBRARIES`.
LDIRT_CLEAN LDIRT_CLOBBER | Specifies the file(s) to delete along with object files when executing the `make clean` or `make clobber` command. With `make clean`, all files specified with `LDIRT_CLEAN` are deleted. With `make clobber`, all files specified with `LDIRT_CLEAN` and `LDIRT_CLOBBER` are deleted.
MAKELCF_FLAGS | Define this build variable when you want to give your own additional run options to `makelcf`. Initial value: None.
MAKEROM_FLAGS | Define this build variable when you want to give your own additional run options to `makerom`. Initial value: None.

FORCE_DISABLE_IS_NITRO_DEBUGGER

Although this option disables the IS-NITRO-DEBUGGER and IS-NITRO-EMULATOR debugging features, it conserves the amount of memory used. Define this when you will debug only with IS-TWL-DEBUGGER (software/hardware). This is not defined by default, so by default all debugging features of all debuggers installed on the build PC are available.
Initial value: None.

## Build Switch Usage Table

This table indicates the ranges in which the SDK build switches can be set.
It includes only the `TWL_*` build switches, but the same information applies to the `NITRO_*` switches as well.

#### Environment Variables Required When Building the SDK

Build Switch | Command Line | Makefile (Before `commondefs`) | Makefile (After `commondefs`) | Environmental Variables | Initial Value
TWLSDK_ROOT | W | W | R | W | `C:/TwlSDK`
TWLSDK_PLATFORM | W | W | R | W | -
CWFOLDER_TWL | W | W | R | W | -
LM_LICENSE_FILE | W | W | R | W | -
IS_TWL_DEBUGGER_DIR | W | W | R | W | -
"WR" = Can be changed and referenced "W" = Can be changed "R" = Can be referenced "-" = Cannot be used

#### Build Switches When Building the SDK

Build Switch | Command Line | Makefile (Before `commondefs`) | Makefile (After `commondefs`) | Environmental Variables | Initial Value
TWL_PROC | W | W | - | W | ARM9
TWL_ARCHGEN (TWL-exclusive) | W | W | WR | W | HYBRID
TWL_CODEGEN | W | W | WR | W | ARM
TWL_DEBUG | W | W | - | W | -
TWL_RELEASE | W | W | - | W | TRUE
TWL_FINALROM | W | W | - | W | -
TWL_STD_PCHDR | W | W | - | W | True
TWL_NO_STD_PCHDR | W | W | - | W | -
TWLSDK_LANG | W | W | W | W | jp
TWL_ROMSPEED | W | W | W | W | UNDEFINED
TWL_COMPRESS | W | W | W | W | -
TWL_DIGEST | W | W | W | W | -
TWL_PROFILE | W | W | W | W | -
TWL_PROFILE_TYPE | W | W | W | W | -
TWL_MEMSIZE | W | W | - | W | 16M
TWL_NO_OPT_G | W | W | W | W | -
TWL_SVC_WAITVBLANK_COMPATIBLE | W | W | W | W | -
CW_LIBFP | W | W | R | W | FP_fastI_v5t_LE.a
"WR" = Can be changed and referenced "W" = Can be changed "R" = Can be referenced "-" = Cannot be used

#### Build Switches Set in the SDK Makefiles

Build Switch | Command Line | Makefile (Before `commondefs`) | Makefile (After `commondefs`) | Environmental Variables | Initial Value
TARGET_PLATFORM | - | W | R | - | ALL
TWL_BUILD_TYPE | - | - | R | - | -
DEFAULT_COMP_ARM7 | - | W | R | - | `mongoose` for NITRO or hybrid ROMs, `racoon` for limited ROMs
FORCE_DISABLE_IS_NITRO_DEBUGGER | - | W | R | - | -
"WR" = Can be changed and referenced "W" = Can be changed "R" = Can be referenced "-" = Cannot be used

TWL-06-0010-001-E
CONFIDENTIAL