coder.make.BuildTool クラス
名前空間: coder.make
ビルド ツールを表す
説明
coder.make.BuildTool
を使用して、既存の既定 coder.make.BuildTool
オブジェクトを取得して定義するか、新しい coder.make.BuildTool
オブジェクトを作成します。
既定の BuildTool
オブジェクトを使用するには、ToolchainInfo
プロパティから取得して定義する方法を使用します。
coder.make.ToolchainInfo.BuildTools
coder.make.ToolchainInfo.PostbuildTools
取得して定義する方法の例については、以下を参照してください。
チュートリアルの例: MATLAB® Coder™ ビルド プロセスへのカスタム ツールチェーンの追加チュートリアル
取得して定義する方法の代替方法は、新規作成方法です。新規作成方法を示す例については、既定以外のビルド ツールの作成を参照してください。
次の図は、既定の BuildTool
オブジェクトと ToolchainInfo
の関係を示します。生成された makefile の PHONY TARGETS
セクションを調べると、BuildTools
、PostbuildTools
および PrebuildTools
の間の差異が明確になります。
prebuild
– プレビルド ツールのみを実行します。build
– プレビルドを実行した後にビルド ツールを実行します。build
は、ビルドPRODUCT
を生成します。postbuild
– ビルドを実行した後にポストビルド ツールを実行します。all
– プレビルド、ビルドおよびポストビルドを実行します。Ctrl+B でビルドした場合、ビルド プロセスはこのルールを使用します。clean
– ツールチェーン内のすべてのツールの出力ファイルの拡張子と派生ファイルの拡張子をすべてクリーンアップします。info
– makefile で使われるすべてのマクロを展開して出力します。
coder.make.BuildTool
クラスは handle
クラスです。
作成
は h
= coder.make.BuildTool(bldtl_name
)coder.make.BuildTool
オブジェクトを作成し、その Name
プロパティを設定します。
入力引数
ビルド ツール名。文字ベクトルまたは string スカラーとして指定します。
データ型: char
| string
プロパティ
以下を使用してビルド ツール コマンドを表します。
次のような、オプションのマクロ名。
CC
.次のような、ビルド ツールを起動するシステム コール (コマンド)。
gcc
.
マクロ名およびシステム コールはともに生成された makefile に記載されます。以下に例を示します。CC = gcc
このプロパティへの値の代入はオプションです。
Command
で以下のメソッドを使用できます。
属性:
GetAccess | public |
SetAccess | public |
プリプロセッサ定義用の -D
など、任意のツール固有の命令を定義します。このプロパティへの値の代入はオプションです。
Directives
で以下のメソッドを使用できます。
属性
GetAccess | public |
SetAccess | public |
任意のツール固有のファイル拡張子を定義します。この値はオプションです。
FileExtensions
で以下のメソッドを使用できます。
属性
GetAccess | public |
SetAccess | public |
任意のツール固有の出力形式を定義します。使用可能なすべての形式がツールでサポートされる場合、この値はオプションになります。
既定値の {'*'}
は、使用可能なすべての形式がサポートされていることを示します。
データ型は cell 配列です。cell 配列の内容は coder.make.BuildOutput
列挙値または '*'
のいずれかでなければなりません。
このプロパティには関連するメソッドがありません。SupportedOutputs
に直接値を代入します。addPrebuildToolToToolchainInfo.m
の例または addPostbuildToolToToolchainInfo.m
の例を参照してください。有効な列挙値は以下のとおりです。
coder.make.BuildOutput.STATIC_LIBRARY | プレビルド ツール、ビルド ツールおよびポストビルド ツールに適用 |
coder.make.BuildOutput.SHARED_LIBRARY | ビルド ツールおよびポストビルド ツールに適用。Embedded Coder® ライセンスが必要 |
coder.make.BuildOutput.EXECUTABLE | ビルド ツールおよびポストビルド ツールに適用 |
属性
GetAccess | public |
SetAccess | public |
メソッド
addDirective | Directives への命令の追加 |
addFileExtension | FileExtensions への新規ファイル拡張子エントリの追加 |
getCommand | ビルド ツール コマンドの取得 |
getDirective | Directives からの名前付き命令の値の取得 |
getFileExtension | FileExtensions 内の名前付きファイル タイプのファイル拡張子の取得 |
getName | ビルド ツール名の取得 |
getPath | Path 内のビルド ツールのパスおよびマクロの取得 |
info | ビルド ツールのプロパティおよび値の表示 |
setCommand | ビルド ツール コマンドの設定 |
setCommandPattern | ビルド ツールのコマンド パターンの設定 |
setCompilerOptionMap | 選択したビルド ツール (コンパイラ) に C/C++ 言語標準とコンパイラ オプションを設定します。 |
setDirective | Directives 内の命令値の設定 |
setFileExtension | FileExtensions 内の名前付きファイル タイプへのファイル拡張子の設定 |
setName | ビルド ツール名の設定 |
setPath | Path 内のビルド ツールのパスおよびマクロの設定 |
validate | ビルド ツール プロパティの検証 |
例
MATLAB® Coder™ ビルド プロセスへのカスタム ツールチェーンの追加の intel_tc.m
ファイルは以下の行を使用して、tc
と呼ばれる ToolchainInfo
オブジェクトから既定のビルド ツール C Compiler
を取得し、さらにそのプロパティを設定します。
% ------------------------------ % 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<|');
以下の例はすべて、"取得と定義" を行う場合の詳細を説明しています。
チュートリアルの例: MATLAB® Coder™ ビルド プロセスへのカスタム ツールチェーンの追加チュートリアル
ビルド ツールを作成するには、次を行います。
createBuildTool_1.m
またはcreateBuildTool_2
など、BuildTool
オブジェクトを定義するファイルを作成します。addBuildToolToToolchainInfo.m
などのファイルを作成します。これは以下を行います。ToolchainInfo
オブジェクトを作成するか、または既存のオブジェクトを使用します。createBuildTool_1.m
またはcreateBuildTool_2
からBuildTool
オブジェクトを作成します。BuildTool
オブジェクトをToolchainInfo
オブジェクトに追加します。
addBuildToolToToolchainInfo.m
を実行します。
以下の addBuildToolToToolchainInfo.m
、createBuildTool_1.m
および createBuildTool_2.m
の例を参照してください。
addBuildToolToToolchainInfo.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Adding a build tool to ToolchainInfo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Create a toolchain object h = coder.make.ToolchainInfo(); % User function for creating and populating a build tool tool = createBuildTool_1(); % or tool = createBuildTool_2(); % Add the build tool to ToolchainInfo h.addBuildTool('My C Compiler',tool);
createBuildTool_1.m
function buildToolObj = createBuildTool_1() toolinfo.Name = 'My GNU C Compiler'; toolinfo.Language = 'C'; toolinfo.Command.Macro = 'CC'; toolinfo.Command.Value = 'gcc'; toolinfo.Path.Macro = 'CC_PATH'; toolinfo.Path.Value = ''; toolinfo.OptionsRegistry = {'My C Compiler','MY_CFLAGS'}; % Key name of this directive toolinfo.Directives(1).Key = 'IncludeSearchPath'; % Macro of this directive (directives can have empty macros) toolinfo.Directives(1).Macro = ''; % Value of this directive toolinfo.Directives(1).Value = '-I'; toolinfo.Directives(2).Key = 'PreprocessorDefine'; toolinfo.Directives(2).Macro = ''; toolinfo.Directives(2).Value = '-D'; toolinfo.Directives(3).Key = 'Debug'; toolinfo.Directives(3).Macro = 'CDEBUG'; toolinfo.Directives(3).Value = '-g'; toolinfo.Directives(4).Key = 'OutputFlag'; toolinfo.Directives(4).Macro = 'C_OUTPUT_FLAG'; toolinfo.Directives(4).Value = '-o'; % Key name of this file extension toolinfo.FileExtensions(1).Key = 'Source'; % Macro of this file extension toolinfo.FileExtensions(1).Macro = 'C_EXT'; % Value of this file extension toolinfo.FileExtensions(1).Value = '.c'; toolinfo.FileExtensions(2).Key = 'Header'; toolinfo.FileExtensions(2).Macro = 'H_EXT'; toolinfo.FileExtensions(2).Value = '.h'; toolinfo.FileExtensions(3).Key = 'Object'; toolinfo.FileExtensions(3).Macro = 'OBJ_EXT'; toolinfo.FileExtensions(3).Value = '.obj'; toolinfo.DerivedFileExtensions = {'$(OBJ_EXT)'}; % '*' means all outputs are supported toolinfo.SupportedOutputs = {'*'}; % put actual extension (e.g. '.c') or keyname if already registered % under 'FileExtensions' toolinfo.InputFileExtensions = {'Source'}; toolinfo.OutputFileExtensions = {'Object'}; % Create a build tool object and populate it with the above data buildToolObj = createAndpopulateBuildTool(toolinfo); function buildToolObj = createAndpopulateBuildTool(toolinfo) % ------------------------- % Construct a BuildTool % ------------------------- buildToolObj = coder.make.BuildTool(); % ------------------------- % Set general properties % ------------------------- buildToolObj.Name = toolinfo.Name; buildToolObj.Language = toolinfo.Language; buildToolObj.Command = coder.make.BuildItem ... (toolinfo.Command.Macro,toolinfo.Command.Value); buildToolObj.Path = coder.make.BuildItem ... (toolinfo.Path.Macro,toolinfo.Path.Value); buildToolObj.OptionsRegistry = toolinfo.OptionsRegistry; buildToolObj.SupportedOutputs = toolinfo.SupportedOutputs; % ------------------------- % Directives % ------------------------- for i = 1:numel(toolinfo.Directives) directiveBuildItem = coder.make.BuildItem(... toolinfo.Directives(i).Macro,toolinfo.Directives(i).Value); buildToolObj.addDirective(toolinfo.Directives(i).Key,directiveBuildItem); end % ------------------------- % File extensions % ------------------------- for i = 1:numel(toolinfo.FileExtensions) fileExtBuildItem = coder.make.BuildItem(... toolinfo.FileExtensions(i).Macro,toolinfo.FileExtensions(i).Value); buildToolObj.addFileExtension(toolinfo.FileExtensions(i).Key,fileExtBuildItem); end % ------------------------- % Derived file extensions % ------------------------- for i = 1:numel(toolinfo.DerivedFileExtensions) if buildToolObj.FileExtensions.isKey(toolinfo.DerivedFileExtensions{i}) buildToolObj.DerivedFileExtensions{end+1} = ... ['$(' buildToolObj.getFileExtension (toolinfo.DerivedFileExtensions{i}) ')']; else buildToolObj.DerivedFileExtensions{end+1} = toolinfo.DerivedFileExtensions{i}; end end % ------------------------- % Command pattern % ------------------------- if isfield(toolinfo,'CommandPattern') buildToolObj.CommandPattern = toolinfo.CommandPattern; end % -------------------------------- % [Input/Output]FileExtensions % -------------------------------- if isfield(toolinfo,'InputFileExtensions') buildToolObj.InputFileExtensions = toolinfo.InputFileExtensions; end if isfield(toolinfo,'OutputFileExtensions') buildToolObj.OutputFileExtensions = toolinfo.OutputFileExtensions; end
createBuildTool_2.m
function buildToolObj = createBuildTool_2() % ------------------------- % Construct a BuildTool % ------------------------- buildToolObj = coder.make.BuildTool(); % ------------------------- % Set general properties % ------------------------- buildToolObj.Name = 'My GNU C Compiler'; buildToolObj.Language = 'C'; buildToolObj.Command = coder.make.BuildItem('CC','gcc'); buildToolObj.Path = coder.make.BuildItem('CC_PATH',''); buildToolObj.OptionsRegistry = {'My C Compiler','MY_CFLAGS'}; buildToolObj.SupportedOutputs = {'*'}; % '*' means all outputs are supported % ------------------------- % Directives % ------------------------- directiveBuildItem = coder.make.BuildItem('','-I'); buildToolObj.addDirective('IncludeSearchPath',directiveBuildItem); directiveBuildItem = coder.make.BuildItem('','-D'); buildToolObj.addDirective('PreprocessorDefine',directiveBuildItem); directiveBuildItem = coder.make.BuildItem('CDEBUG','-g'); buildToolObj.addDirective('Debug',directiveBuildItem); directiveBuildItem = coder.make.BuildItem('C_OUTPUT_FLAG','-o'); buildToolObj.addDirective('OutputFlag',directiveBuildItem); % ------------------------- % File Extensions % ------------------------- fileExtBuildItem = coder.make.BuildItem('C_EXT','.c'); buildToolObj.addFileExtension('Source',fileExtBuildItem); fileExtBuildItem = coder.make.BuildItem('H_EXT','.h'); buildToolObj.addFileExtension('Header',fileExtBuildItem); fileExtBuildItem = coder.make.BuildItem('OBJ_EXT','.obj'); buildToolObj.addFileExtension('Object',fileExtBuildItem); % ------------------------- % Others % ------------------------- buildToolObj.DerivedFileExtensions = {'$(OBJ_EXT)'}; buildToolObj.InputFileExtensions = {'Source'}; % put actual extension (e.g. '.c') % or keyname if already registered under 'FileExtensions' buildToolObj.OutputFileExtensions = {'Object'}; % put actual extension (e.g. '.c') % or keyname if already registered under 'FileExtensions'
addPrebuildToolToToolchainInfo.m
と addPostbuildToolToToolchainInfo.m
の例におけるコードは、プレビルド ツールとポストビルド ツールをツールチェーンに追加する方法を示しています。
addPrebuildToolToToolchainInfo.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Adding a pre-build tool with selected SupportedOutputs to ToolchainInfo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Create a toolchain object tc = coder.make.ToolchainInfo(coder.make.getToolchainInfoFromRegistry(coder.make.getDefaultToolchain)); % Set inlined commands for source to dependency tool tc.InlinedCommands = ['define sourceToDep=', 10, ... '$(foreach source, $(1), $(CC) $(CFLAGS) -E -MMD -MP -MF"$(notdir $(source:%.c=%.d))" -MT"$(notdir $(source:%.c=%.o))" $(source) )', 10, ... 'endef']; % Set makefile includes make = tc.BuilderApplication(); make.IncludeFiles = {'*.d'}; % Dependency File Generator for GCC-based toolchain prebuildToolName = 'Dependency File Generator'; prebuildTool = tc.addPrebuildTool(prebuildToolName); % Set command macro and value prebuildTool.setCommand('SRC2DEP', '$(call sourceToDep, $(SRCS))'); % Set tool options macro prebuildTool.OptionsRegistry = {prebuildToolName, 'SRC2DEP_OPTS'}; % Set output type from tool prebuildTool.SupportedOutputs = {'*'}; tc.addBuildConfigurationOption(prebuildToolName, prebuildTool); tc.setBuildConfigurationOption('all', prebuildToolName, ''); % displays pre-build tool properties tc.getPrebuildTool('Dependency File Generator')
addPostbuildToolToToolchainInfo.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Adding a post-build tool to ToolchainInfo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % ELF (executable and linkable format) to hexadecimal converter postbuildToolName = 'elf2hex converter'; % Create and populate a post-build tool tc = coder.make.ToolchainInfo; postbuild = tc.addPostbuildTool(postbuildToolName); % Set command macro and value for tool postbuild.setCommand('OBJCOPY', 'arm-none-eabi-objcopy'); % Set path for tool postbuild.setPath('OBJCOPYPATH','$(MW_GNU_ARM_TOOLS_PATH)'); % Set options for tool postbuild.OptionsRegistry = {postbuildToolName, 'OBJCOPYFLAGS_HEX'}; % Set output type from tool postbuild.SupportedOutputs = {coder.make.enum.BuildOutput.EXECUTABLE}; % Create build configuration for tool tc.addBuildConfigurationOption(postbuildToolName, postbuild); % Set build configuration for tool tc.setBuildConfigurationOption('all', postbuildToolName, '-O ihex $(PRODUCT) $(PRODUCT_HEX)'); % displays post-build tool properties tc.getPostbuildTool('elf2hex converter')
バージョン履歴
R2013a で導入
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)