www.gusucode.com > rtwdemos 工具箱matlab源码程序 > rtwdemos/rtwdemo_custom_toolchain_script.m
%% Adding a Custom Toolchain % % This example shows how to register and use a toolchain to compile an % executable. This example uses the Intel(R) Compiler, but the concepts and % APIs shown below can be used for any toolchain. % The registered toolchain can be selected from a list of toolchains and a % makefile will be generated to build the code using that toolchain. % Copyright 2013 The MathWorks, Inc. %% Create a New Folder and Copy Relevant Files % The following code creates a folder in your current working folder (pwd). % The new folder only contains files for this example. If you do not want to % affect the current folder, or cannot generate files in this folder, change % your working folder before invoking the command. copyfile(fullfile(matlabroot,'toolbox','rtw','rtwdemos','toolchain_demo'),'toolchain_demo','f') cd toolchain_demo %% Open a Model % Open the |rtwdemo_counter| model. By default, this model is configured % for GRT and is therefore using the Toolchain approach. The capability % demonstrated in this example is available only on models configured to use the Toolchain approach. % Click % <matlab:helpview(fullfile(docroot,'toolbox','rtw','helptargets.map'),'toolchain_approach') here> % for more information about the Toolchain approach. model = 'rtwdemo_counter'; open_system(model) %% Toolchain % A toolchain is a collection of tools required to compile, link, download % and run on specified platform. A toolchain has multiple tools, such as a % compiler, linker and archiver. Each of these tools can take multiple % options, which can be grouped into configurations like *Faster Builds*, % *Faster Runs*, *Debug*. %% Choosing a Toolchain % In the model, click *Simulation* > *Model Configuration Parameters* to open the % *Configuration Parameters* dialog. Select the *Code Generation* node. On % the right side of the dialog, inside the *Toolchain settings* group, you % will see the *Toolchain* drop-down list. This drop-down list enables you to select % the toolchain that will be used to build the generated code, granted the % toolchain is installed. % %% % By default, the *Faster Runs* build configuration is selected. If you % click *Show settings* hyperlink next to the *Build configuration* % drop-down list, you will see the toolchain flags that will be used to build the % generated code. Choose a different build configuration based on how you % want the generated code to build. %% % Close the *Configuration Parameters* dialog before proceeding. %% ToolchainInfo % This example shows how you can register your custom toolchain into the % *Toolchain* drop-down list. %% % The first step to registering a custom toolchain is to create a |ToolchainInfo| % object that contains all the information about the toolchain. % A |ToolchainInfo| object describes the basic information of % the toolchain. The |ToolchainInfo| object has methods to set the % toolchain specifications. The |ToolchainInfo| object can be shared across % installations. %% % Open the toolchain definition file for an Intel Compiler. % This file creates a |ToolchainInfo| object that contains information % about the Intel toolchain on a 64-bit Windows(R) platform. edit intel_tc type intel_tc %% % Run the toolchain definition file to generate the |ToolchainInfo| object. tc = intel_tc; %% % Save the |ToolchainInfo| object |tc| to a MAT file. save intel_tc tc %% Registering a Toolchain % After creating the |ToolchainInfo| object for the new toolchain, you need % to register it. Toolchains are registered through |RTW.TargetRegistry|. % To register the toolchain, you need to write an |rtwTargetInfo.m| file, % then put this file in the MATLAB path in order for it to be loaded by the % system automatically. type rtwTargetInfo %% % Now, you can reset the |TargetRegistry| to pick up the new |rtwTargetInfo.m| % file. RTW.TargetRegistry.getInstance('reset'); %% Choosing the New Toolchain % Re-open the *Configuration Parameters* dialog. Expand the *Toolchain* % drop-down list and notice that the new toolchain is now added to the % selection. Select the "Intel v12.1" toolchain from the drop-down list. %% % Programmatically, you can accomplish the same task through the following % commands: cs = getActiveConfigSet(model); set_param(cs, 'Toolchain', tc.Name) %% % Verify your selection. toolchain = get_param(cs, 'Toolchain') %% Build Model Using the Custom Toolchain % You can now build the model with the new custom toolchain. %% % Note: If you do not have the Intel toolchain installed, you can use the % following command to generate the code and makefile only. set_param(cs, 'GenCodeOnly', 'on') %% % Build the model to generate the code and makefile that uses the new % toolchain. rtwbuild(model) %% % Examine the generated makefile. type(fullfile([model '_grt_rtw'], [model '.mk'])) %% % Once the build process is finished, and you had Intel compilers installed, % you can run the generated executable. % if ispc % system([model '.exe']) % else % system(model) % end %% Restore % You can optionally remove the folder you created earlier. cd .. % rmdir('toolchain_demo', 's') %% % Reset the |TargetRegistry| to remove the toolchain that you registered % above. RTW.TargetRegistry.getInstance('reset'); %% % Close the model. close_system(model, 0) %% % Clear the variables introduced in the workspace. clear INC K LIMIT RESET model tc cs toolchain