Customizing the Build Process

Controlling the Compiling and Linking Phases of the Build Process

After generating code for a model, the Real-Time Workshop build process determines whether or not to compile and link an executable program. This decision is governed by the following:

Cross-Compiling Code Generated on a Microsoft Windows System

If you need to generate code with the Real-Time Workshop software on a Microsoft Windows system but compile the generated code on a different supported platform, you can do so by modifying your TMF and model configuration parameters. For

example, you would need to do this if you develop applications with the MATLAB and Simulink products on a Windows system, but you run your generated code on a Linux system.

To set up a cross-compilation development environment, do the following (here a Linux system is the destination platform):

  1. On your Windows system, copy the UNIX TMF for your target to a local directory. This will be your working directory for initiating code generation. For example, you might copy matlabroot/rtw/c/grt/grt_unix.tmf to D:/work/my_grt_unix.tmf.

  2. Make the following changes to your copy of the TMF:

  3. Open your model and make the following changes in the Real-Time Workshop pane of the Configuration Parameters dialog:

  4. Generate the code.

  5. If the build directory (directory from which the model was built) is not already Linux accessible, copy it to a Linux accessible path. For example, if your build directory for the generated code was D:\work\mymodel_grt_rtw, copy that entire directory tree to a path such as /home/user/mymodel_grt_rtw.

  6. If the MATLAB directory tree on the Windows system is Linux accessible, skip this step. Otherwise, you must copy all the include and source directories to a Linux accessible drive partition, for example, /home/user/myinstall. These directories appear in the makefile after MATLAB_INCLUDES = and ADD_INCLUDES = and can be found by searching for $(MATLAB_ROOT). Any path that contains $(MATLAB_ROOT) must be copied. Here is an example list (your list will vary depending on your model):

    $(MATLAB_ROOT)/rtw/c/grt 
    $(MATLAB_ROOT)/extern/include 
    $(MATLAB_ROOT)/simulink/include 
    $(MATLAB_ROOT)/rtw/c/src 
    $(MATLAB_ROOT)/rtw/c/tools

    Additionally, paths containing $(MATLAB_ROOT) in the build rules (lines with %.o :) must be copied. For example, based on the build rule

    %.o : $(MATLAB_ROOT)/rtw/c/src/ext_mode/tcpip/%.c

    the following directory should be copied:

    $(MATLAB_ROOT)/rtw/c/src/ext_mode/tcpip

  7. Make the following changes to the generated makefile:

  8. From a Linux shell, compile the code you generated on the Windows system. You can do this by running the generated model.bat file or by typing the make command line as it appears in the .bat file.

Controlling the Location and Naming of Libraries During the Build Process

Two configuration parameters, TargetPreCompLibLocation and TargetLibSuffix, are available for you to use to control values placed in Real-Time Workshop generated makefiles during the token expansion from template makefiles (TMFs). You can use these parameters to

Targets can set the parameters inside the system target file (STF) select callback. For example:

function mytarget_select_callback_handler(varargin)
    hDig=varargin{1};
    hSrc=varargin{2};
    slConfigUISetVal(hDig, hSrc,...
    'TargetPreCompLibLocation', 'c:\mytarget\precomplibs');
    slConfigUISetVal(hDig, hSrc, 'TargetLibSuffix',...
    '_diab.library');

The TMF has corresponding expansion tokens:

    |>EXPAND_LIBRARY_LOCATION<|
    |>EXPAND_LIBRARY_SUFFIX<|

Alternatively, you can use a call to the set_param function. For example:

set_param(model,'TargetPreCompLibLocation',...
'c:\mytarget\precomplibs');

Specifying the Location of Precompiled Libraries

Use the TargetPreCompLibLocation configuration parameter to:

For a precompiled library, such as a blockset library or the Real-Time Workshop library, the location specified in rtwmakecfg.m is typically a location specific to the blockset or the Real-Time Workshop product. It is expected that the library will exist in this location and it is linked against during Real-Time Workshop builds.

However, for some applications, such as custom targets, it is preferable to locate the precompiled libraries in a target-specific or other alternate location rather than in the location specified in rtwmakecfg.m. For a custom target, the library is expected to be created using the target-specific cross-compiler and placed in the target-specific location for use during the Real-Time Workshop build process. All libraries intended to be supported by the target should be compiled and placed in the target-specific location.

You can set up the TargetPreCompLibLocation parameter in its select callback. The path that you specify for the parameter must be a fully qualified absolute path to the library location. Relative paths are not supported. For example:

slConfigUISetVal(hDlg, hSrc, 'TargetPreCompLibLocation',...
'c:\mytarget\precomplibs');

Alternatively, you set the parameter with a call to the set_param function. For example:

set_param(model,'TargetPreCompLibLocation',...
'c:\mytarget\precomplibs');

During the TMF-to-makefile conversion, the Real-Time Workshop build process replaces the token |>EXPAND_LIBRARY_LOCATION<| with the specified location in the rtwmakecfg.m file. For example, if the library name specified in the rtwmakecfg.m file is 'rtwlib', the TMF expands from:

LIBS += |>EXPAND_LIBRARY_LOCATION<|\|>EXPAND_LIBRARY_NAME<|\
|>EXPAND_LIBRARY_SUFFIX<|

to:

LIBS += c:\mytarget\precomplibs\rtwlib_diab.library

By default, TargetPreCompLibLocation is an empty string and the Real-Time Workshop build process uses the location specified in rtwmakecfg.m for the token replacement.

Controlling the Location of Model Reference Libraries

On platforms other than the Apple® Macintosh® platform, when building a model that uses referenced models, the Real-Time Workshop build process by default:

For example, if a model includes a referenced model sub, the Real-Time Workshop build process assigns the library name sub_rtwlib.lib to MODELREF_LINK_LIBS and copies the library file to the parent model's build directory. This definition is then used in the final link line, which links the library into the final product (usually an executable). This technique minimizes the length of the link line.

On the Macintosh platform, and optionally on other platforms, the Real-Time Workshop build process:

When using this technique, the Real-Time Workshop build process assigns a relative path such as ../slprj/grt/sub/sub_rtwlib.lib to MODELREF_LINK_LIBS and uses the path to gain access to the library file at link time.

To change to the non-default behavior on platforms other than the Macintosh platform, enter the following command in the Make command field of the Real-Time Workshop pane of the Configuration Parameters dialog box:

make_rtw USE_MDLREF_LIBPATHS=1 

If you specify other Make command arguments, such as OPTS="-g", you can specify the multiple arguments in any order.

To return to the default behavior, set USE_MDLREF_LIBPATHS to 0, or remove it.

Controlling the Suffix Applied to Library File Names

Use the TargetLibSuffix configuration parameter to control the suffix applied to library names (for example, _target.lib or _target.a). The specified suffix string must include a period (.). You can apply TargetLibSuffix to the following libraries:

Recompiling Precompiled Libraries

You can recompile precompiled libraries included as part of the Real-Time Workshop product, such as rtwlib or dsplib, by using a supplied M-file function, rtw_precompile_libs. You might consider doing this if you need to customize compiler settings for various platforms or environments. For details on using rtw_precompile_libs, see Precompiling S-Function Libraries.

Customizing Post Code Generation Build Processing

The Real-Time Workshop product provides a set of tools, including a build information object, you can use to customize build processing that occurs after code generation. You might use such customizations for target development or the integration of third-party tools into your application development environment. The next figure and the steps that follow show the general workflow for setting up such customizations.

  1. Program the post code generation command.

  2. Define the post code generation command.

  3. Suppress makefile generation, if appropriate for your application.

  4. Build the model.

  5. Modify the command, if necessary, and rebuild the model. Repeat this step until the build results are acceptable.

Build Information Object

At the start of a model build, the Real-Time Workshop build process logs the following build option and dependency information to a temporary build information object:

You can retrieve information from and add information to this object by using an extensive set of functions. For a list of available functions and detailed function descriptions, see Functions — Alphabetical List in the Real-Time Workshop documentation. Programming a Post Code Generation Command explains how to use the functions to control post code generation build processing.

Programming a Post Code Generation Command

For certain applications, it might be necessary to control aspects of the build process after the code generation. For example, this is necessary when you develop your own target, or you want to apply an analysis tool to the generated code before continuing with the build process. You can apply this level of control to the build process by programming and then defining a post code generation command.

A post code generation command is an M-file that typically calls functions that get data from or add data to the model's build information object. You can program the command as a script or function.

If You Program the Command as a...Then the...
ScriptScript can gain access to the model name and the build information directly
FunctionFunction can pass the model name and the build information as arguments

If your post code generation command calls user-defined functions, make sure the functions are on the MATLAB path. If the Real-Time Workshop build process cannot find a function you use in your command, the build process errors out.

You can then call any combination of build information functions to customize the model's post code generation build processing.

The following example shows a fragment of a post code generation command that gets the filenames and paths of the source and include files generated for a model for analysis.

function analyzegencode(buildInfo)
% Get the names and paths of all source and include files
% generated for the model and then analyze them.

% buildInfo - build information for my model.

% Define cell array to hold data.
MyBuildInfo={};

% Get source file information.
MyBuildInfo.srcfiles=getSourceFiles(buildInfo, true, true);
MyBuildInfo.srcpaths=getSourcePaths(buildInfo, true);

% Get include (header) file information.
MyBuildInfo.incfiles=getIncludeFiles(buildInfo, true, true);
MyBuildInfo.incpaths=getIncludePaths(buildInfo, true);

% Analyze generated code.
.
.
.

For a list of available functions and detailed function descriptions, see Functions — Alphabetical List in the Real-Time Workshop documentation.

Defining a Post Code Generation Command

After you program a post code generation command, you need to inform the Real-Time Workshop build process that the command exists and to add it to the model's build processing. You do this by defining the command with the PostCodeGenCommand model configuration parameter. When you define a post code generation command, the Real-Time Workshop build process evaluates the command after generating and writing the model's code to disk and before generating a makefile.

As the following syntax lines show, the arguments that you specify when setting the configuration parameter varies depending on whether you program the command as a script, function, or set of functions.

Script

set_param(model, 'PostCodeGenCommand',...
'pcgScriptName');

Function

set_param(model, 'PostCodeGenCommand',...
 'pcgFunctionName(modelName)');

Multiple Functions

pcgFunctions=...
'pcgFunction1Name(modelName);...
pcgFunction2Name(buildInfo)';
set_param(model, 'PostCodeGenCommand',...
 pcgFunctions);

The following call to set_param defines PostCodGenCommand to evaluate the function analyzegencode.

set_param(model, 'PostCodeGenCommand',...
'analyzegencode(buildInfo)');

Suppressing Makefile Generation

The Real-Time Workshop product provides the ability to suppress makefile generation during the build process. For example, you might do this to integrate tools into the build process that are not driven by makefiles.

To instruct the Real-Time Workshop build process to not generate a makefile, do one of the following:

When you suppress makefile generation,

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS