Main Content

coder.make.BuildTool class

Package: coder.make

Represent build tool

Description

Use coder.make.BuildTool to get and define an existing default coder.make.BuildTool object, or to create a coder.make.BuildTool object.

To work with default BuildTool objects, use the get and define approach from the ToolchainInfo properties:

  • coder.make.ToolchainInfo.BuildTools

  • coder.make.ToolchainInfo.PostbuildTools

Examples showing the get and define approach are:

An alternative to the get and define approach is the create new approach. An example showing the create new approach appears in Create a Non-Default BuildTool.

The illustration shows the relationship between the default BuildTool objects and ToolchainInfo. When you examine the PHONY TARGETS section of the generated makefile, the difference between the BuildTools, PostbuildTools, and PrebuildTools becomes clearer.

  • prebuild – runs only the prebuild tool.

  • build – runs the build tools after running prebuild. The build generates the build PRODUCT.

  • postbuild – runs the postbuild tool after running build.

  • all – runs prebuild, build, and postbuild. The build process uses this rule on a Ctrl+B build.

  • clean – cleans up all output file extensions and derived file extensions of all the tools in the toolchain.

  • info – expands and prints all macros used in the makefile.

Construction

h = coder.make.BuildTool(bldtl_name) creates a coder.make.BuildTool object and sets its Name property.

Input Arguments

expand all

Build tool name, specified as a character vector or string scalar.

Data Types: char | string

Output Arguments

expand all

Object handle for a coder.make.BuildTool object, specified as a variable.

Example: tool

Properties

expand all

Represents the build tool command using:

  • An optional macro name, such as: CC.

  • The system call (command) that starts the build tool, such as: gcc.

The macro name and system call appear together in the generated makefile. For example: CC = gcc

Assigning a value to this property is optional.

You can use the following methods with Command:

Attributes:

GetAccesspublic
SetAccesspublic

Defines any tool-specific directives, such as -D for preprocessor defines. Assigning a value to this property is optional.

You can use the following methods with Directives:

Attributes:

GetAccesspublic
SetAccesspublic

Defines any tool-specific file extensions. This value is optional.

You can use the following methods with FileExtensions:

Attributes:

GetAccesspublic
SetAccesspublic

Defines the name of the build tool.

You can use the following methods with Name.

Attributes:

GetAccesspublic
SetAccesspublic

Defines any tool-specific paths. If the command is on the system path, this value is optional.

You can use the following methods with Path:

Attributes:

GetAccesspublic
SetAccesspublic

Defines any tool-specific output formats. If the tool supports all available formats, this value is optional.

The default value is {'*'}, which indicates support for all available formats.

The datatype is cell array. The contents of the cell array must be either coder.make.BuildOutput enumeration values, or '*'.

This property does not have any associated methods. Assign the value directly to the SupportedOutputs. See the addPrebuildToolToToolchainInfo.m example or the addPostbuildToolToToolchainInfo.m example. Valid enumeration values are:

coder.make.BuildOutput.STATIC_LIBRARYapplies for pre-build tools, build tools, and post-build tools
coder.make.BuildOutput.SHARED_LIBRARYapplies for build tools and post-build tools; requires Embedded Coder® license
coder.make.BuildOutput.EXECUTABLEapplies for build tools and post-build tools

Attributes:

GetAccesspublic
SetAccesspublic

Methods

addDirectiveAdd directive to Directives
addFileExtensionAdd new file extension entry to FileExtensions
getCommandGet build tool command
getDirectiveGet value of named directive from Directives
getFileExtensionGet file extension for named file type in FileExtensions
getNameGet build tool name
getPathGet path and macro of build tool in Path
infoDisplay build tool properties and values
setCommandSet build tool command
setCommandPatternSet pattern of commands for build tools
setCompilerOptionMapSet C/C++ language standard and compiler options for selected build tool (compiler)
setDirectiveSet value of directive in Directives
setFileExtensionSet file extension for named file type in FileExtensions
setNameSet build tool name
setPathSet path and macro of build tool in Path
validateValidate build tool properties

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects.

Example

Get a Default Build Tool and Set Its Properties

The intel_tc.m file from Adding a Custom Toolchain uses the following lines to get a default build tool, C Compiler, from a ToolchainInfo object called tc, and then sets its properties.

% ------------------------------
% C Compiler
% ------------------------------
 
tool = tc.getBuildTool('C Compiler');

tool.setName('Intel C Compiler');
tool.setCommand('icl');
tool.setPath('');

tool.setDirective('IncludeSearchPath','-I');
tool.setDirective('PreprocessorDefine','-D');
tool.setDirective('OutputFlag','-Fo');
tool.setDirective('Debug','-Zi');

tool.setFileExtension('Source','.c');
tool.setFileExtension('Header','.h');
tool.setFileExtension('Object','.obj');

tool.setCommandPattern('|>TOOL<| |>TOOL_OPTIONS<| |>OUTPUT_FLAG<||>OUTPUT<|');

The following examples show the same “get and define” approach in more detail:

Create a Non-Default BuildTool

To create a build tool:

  1. Create a file that defines a BuildTool object, such as createBuildTool_1.m or createBuildTool_2.

  2. Create a file like addBuildToolToToolchainInfo.m, that:

    • Creates a ToolchainInfo object, or uses an existing one.

    • Creates a BuildTool object from createBuildTool_1.m or createBuildTool_2.

    • Adds the BuildTool object to the ToolchainInfo object.

  3. Run addBuildToolToToolchainInfo.m.

Refer to the following examples of addBuildToolToToolchainInfo.m, createBuildTool_1.m, and createBuildTool_2.m.

 addBuildToolToToolchainInfo.m

 createBuildTool_1.m

 createBuildTool_2.m

Add Prebuild and Postbuild Tools to Toolchain

The code in the addPrebuildToolToToolchainInfo.m and the addPostbuildToolToToolchainInfo.m examples show how to add prebuild and postbuild tools to a toolchain.

 addPrebuildToolToToolchainInfo.m

 addPostbuildToolToToolchainInfo.m