Main Content

コメント付きのツールチェーン定義ファイル

ツールチェーン定義ファイルの作成に関する手順

この例は、ツールチェーン定義ファイルを作成する方法を示し、含まれる各手順を説明します。この例はMATLAB® Coder™ ビルド プロセスへのカスタム ツールチェーンの追加内で使用される定義ファイルを基にしています。ワークフローの詳細は、一般的なワークフローを参照してください。

ToolchainInfo オブジェクトを作成する関数の作成

function tc = intel_tc
% INTEL_TC Creates an Intel v12.1 ToolchainInfo object.
% This can be used as a template to add other toolchains on Windows.

tc = coder.make.ToolchainInfo('BuildArtifact','nmake makefile');
tc.Name             = 'Intel v12.1 | nmake makefile (64-bit Windows)';
tc.Platform         = 'win64';
tc.SupportedVersion = '12.1';

tc.addAttribute('TransformPathsWithSpaces');
tc.addAttribute('RequiresCommandFile');
tc.addAttribute('RequiresBatchFile');

上記のコードは以下を示します。

  • coder.make.ToolchainInfo オブジェクトを作成し、それをハンドル tc に割り当てる関数 intel_tc を定義。

  • BuildArtifact プロパティをオーバーライドして gmake の代わりに nmake 用に makefile を作成。

  • 情報提供および表示目的で、値を NamePlatform および SupportedVersion プロパティへ割り当て。

  • 3 つのカスタム属性をこのツールチェーンで必要な Attributes プロパティに追加。

  • 'TransformPathsWithSpaces' がスペースを含むパスを短い Windows® パスに変換。

  • 'RequiresCommandFile' がリンカーを呼び出すリンカー コマンド ファイルを生成。これにより、256 文字のコマンド ライン制限を超過する呼び出しに関する問題を回避します。

  • 'RequiresBatchFile' がビルダー アプリケーションを呼び出す .bat ファイルを作成。

設定

% ------------------------------
% Setup
% ------------------------------
% Below we are using %ICPP_COMPILER12% as root folder where Intel Compiler is
% installed. You can either set an environment variable or give full path to the
% compilervars.bat file
tc.ShellSetup{1} = 'call %ICPP_COMPILER12%\bin\compilervars.bat intel64';

上記のコードは以下を示します。

  • システム呼び出しの ShellSetup プロパティへの割り当て。

  • coder.make.ToolchainInfo.setup メソッドは PrebuildTools プロパティで指定されたツールを実行する前にこれらのシステム呼び出しを実行します。

  • Intel® コンパイラに同梱されている compilervars.bat を呼び出し、Intel コンパイラおよびリンカーの環境変数のセットを取得。

マクロ

% ------------------------------
% Macros
% ------------------------------
tc.addMacro('MW_EXTERNLIB_DIR',['$(MATLAB_ROOT)\extern\lib\' tc.Platform '\microsoft']);
tc.addMacro('MW_LIB_DIR',['$(MATLAB_ROOT)\lib\' tc.Platform]);
tc.addMacro('CFLAGS_ADDITIONAL','-D_CRT_SECURE_NO_WARNINGS');
tc.addMacro('CPPFLAGS_ADDITIONAL','-EHs -D_CRT_SECURE_NO_WARNINGS');
tc.addMacro('LIBS_TOOLCHAIN','$(conlibs)');
tc.addMacro('CVARSFLAG','');

tc.addIntrinsicMacros({'ldebug','conflags','cflags'});

上記のコードは以下を示します。

  • coder.make.ToolchainInfo.addMacro メソッドを使用したマクロの定義と、それらへの値の割り当て。

  • coder.make.ToolchainInfo.addIntrinsicMacros を使用して、MathWorks® ソフトウェアの範囲外でツールチェーンによって値を指定されるマクロを定義。

C コンパイラ

% ------------------------------
% 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<|');

上記のコードは以下を示します。

  • C コンパイラ用のビルド ツール オブジェクトの作成。

  • ビルド ツール オブジェクト プロパティへの値の割り当て。

  • 名と値のペアを使用して命令とファイル拡張子を作成。

  • コマンドのパターンを設定。

  • setCommandPattern メソッドを使用してコマンド内でのスペース文字の使用を管理できます。たとえば、OUTPUT_FLAG<||>OUTPUT のように 2 本のバーがある場合は、出力フラグと出力の間にスペース文字は使用できません。

C++ コンパイラ

% ------------------------------
% 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','.cpp');
tool.setFileExtension('Header','.hpp');
tool.setFileExtension('Object','.obj');

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

上記のコードは以下を示します。

  • C++ コンパイラ用のビルド ツール オブジェクトの作成。

  • C コンパイラ用のビルド ツール オブジェクトに非常によく類似。

リンカー

% ------------------------------
% Linker
% ------------------------------

tool = tc.getBuildTool('Linker');

tool.setName('Intel C/C++ Linker');
tool.setCommand('xilink');
tool.setPath('');

tool.setDirective('Library','-L');
tool.setDirective('LibrarySearchPath','-I');
tool.setDirective('OutputFlag','-out:');
tool.setDirective('Debug','');

tool.setFileExtension('Executable','.exe');
tool.setFileExtension('Shared Library','.dll');

tool.DerivedFileExtensions = horzcat(tool.DerivedFileExtensions,{ ...
                                            ['_' tc.Platform '.lib'],...
                                            ['_' tc.Platform '.exp']});

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

上記のコードは以下を示します。

  • リンカー用のビルド ツール オブジェクトの作成。

  • coder.make.BuildTool.DerivedFileExtensions に値を代入。

アーカイバー

% ------------------------------
% Archiver
% ------------------------------

tool = tc.getBuildTool('Archiver');

tool.setName('Intel C/C++ Archiver');
tool.setCommand('xilib');
tool.setPath('');

tool.setDirective('OutputFlag','-out:');

tool.setFileExtension('Static Library','.lib');

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

上記のコードは以下を示します。

  • アーカイバー用のビルド ツール オブジェクトの作成。

ビルダー

% ------------------------------
% Builder
% ------------------------------

tc.setBuilderApplication(tc.Platform);

上記のコードは以下を示します。

  • coder.make.ToolchainInfo.Platform の値を BuilderApplication の値を設定するための引数として与える。これにより、プラットフォームに基づいてビルダー アプリケーションの既定値を設定します。たとえば、Platformwin64 の場合、この行は 'del' を削除コマンド、'echo' を表示コマンド、'\' をファイル区切り、'!include' をインクルード命令として設定します。

ビルド構成

% --------------------------------------------
% BUILD CONFIGURATIONS
% --------------------------------------------

optimsOffOpts = {'/c /Od'};
optimsOnOpts = {'/c /O2'};
cCompilerOpts    = '$(cflags) $(CVARSFLAG) $(CFLAGS_ADDITIONAL)';
cppCompilerOpts  = '$(cflags) $(CVARSFLAG) $(CPPFLAGS_ADDITIONAL)';
linkerOpts       = {'$(ldebug) $(conflags) $(LIBS_TOOLCHAIN)'};
sharedLinkerOpts = horzcat(linkerOpts,'-dll -def:$(DEF_FILE)');
archiverOpts     = {'/nologo'};

% Get the debug flag per build tool
debugFlag.CCompiler   = '$(CDEBUG)';   
debugFlag.CppCompiler = '$(CPPDEBUG)';
debugFlag.Linker      = '$(LDDEBUG)';  
debugFlag.Archiver    = '$(ARDEBUG)';  

cfg = tc.getBuildConfiguration('Faster Builds');
cfg.setOption('C Compiler',horzcat(cCompilerOpts,optimsOffOpts));
cfg.setOption('C++ Compiler',horzcat(cppCompilerOpts,optimsOffOpts));
cfg.setOption('Linker',linkerOpts);
cfg.setOption('Shared Library Linker',sharedLinkerOpts);
cfg.setOption('Archiver',archiverOpts);

cfg = tc.getBuildConfiguration('Faster Runs');
cfg.setOption('C Compiler',horzcat(cCompilerOpts,optimsOnOpts));
cfg.setOption('C++ Compiler',horzcat(cppCompilerOpts,optimsOnOpts));
cfg.setOption('Linker',linkerOpts);
cfg.setOption('Shared Library Linker',sharedLinkerOpts);
cfg.setOption('Archiver',archiverOpts);

cfg = tc.getBuildConfiguration('Debug');
cfg.setOption('C Compiler',horzcat(cCompilerOpts,optimsOffOpts,debugFlag.CCompiler));
cfg.setOption ...
('C++ Compiler',horzcat(cppCompilerOpts,optimsOffOpts,debugFlag.CppCompiler));
cfg.setOption('Linker',horzcat(linkerOpts,debugFlag.Linker));
cfg.setOption('Shared Library Linker',horzcat(sharedLinkerOpts,debugFlag.Linker));
cfg.setOption('Archiver',horzcat(archiverOpts,debugFlag.Archiver));

tc.setBuildConfigurationOption('all','Make Tool','-f $(MAKEFILE)');

上記のコードは以下を示します。

  • 各ビルド構成オブジェクトの作成。

  • 任意のビルド構成オブジェクト用の各オプションの値を設定。