Skip to Main Content Skip to Search
Product Documentation

Customize the Target Build Process with sl_customization.m

About sl_customization.m

The Simulink customization file sl_customization.m is a mechanism that allows you to use MATLAB to customize the standard Simulink user interface. The Simulink software reads the sl_customization.m file, if present on the MATLAB path, when it starts and the customizations specified in the file are applied to the Simulink session. For more information on the sl_customization.m customization file, see Customizing the Simulink User Interface in the Simulink documentation.

The sl_customization.m file can be used to register installation-specific hook functions to be invoked during the Simulink Coder build process. The hook functions that you register through sl_customization.m complement System Target File (STF) hooks (described in Customize the Target Build Process with the STF_make_rtw Hook File) and post-code generation commands (described in Customize Post-Code-Generation Build Processing).

The following figure shows the relationship between installation-level hooks and the other available mechanisms for customizing the build process.

Register Build Process Hook Functions Using sl_customization.m

To register installation-level hook functions that will be invoked during the Simulink Coder build process, you create a MATLAB function called sl_customization.m and include it on the MATLAB path of the Simulink installation that you want to customize. The sl_customization function accepts one argument: a handle to a customization manager object. For example,

function sl_customization(cm)

As a starting point for your customizations, the sl_customization function must first get the default (factory) customizations, using the following assignment statement:

hObj = cm.RTWBuildCustomizer;

You then invoke methods to register your customizations. The customization manager object includes the following method for registering Simulink Coder build process hook customizations:

Your instance of the sl_customization function should use this method to register installation-specific hook functions.

The Simulink software reads the sl_customization.m file when it starts. If you subsequently change the file, you must restart the Simulink session or enter the following command at the MATLAB command line to effect the changes:

sl_refresh_customizations

Variables Available for sl_customization.m Hook Functions

The following variables are available for sl_customization.m hook functions to use:

A hook script can directly access the valid variables. A hook function can pass the valid variables as arguments to the function. For example:

hObj.addUserHook('after_make', 'afterMakeFunction(modelName,dependencyObject);');

Example Build Process Customization Using sl_customization.m

The sl_customization.m file shown in Example 1: sl_customization.m for Simulink Coder Build Process Customizations uses the addUserHook method to specify installation-specific build process hooks to be invoked at the 'entry' and 'after_tlc' stages of the Simulink Coder build. For the hook function source code, see Example 2: CustomRTWEntryHook.m and Example 3: CustomRTWPostProcessHook.m.

Example 1: sl_customization.m for Simulink Coder Build Process Customizations

function sl_customization(cm)
% Register user customizations

% Get default (factory) customizations
hObj = cm.RTWBuildCustomizer;

% Register build process hooks
hObj.addUserHook('entry', 'CustomRTWEntryHook(modelName);');
hObj.addUserHook('after_tlc', 'CustomRTWPostProcessHook(modelName);');

end

Example 2: CustomRTWEntryHook.m

function [str, status] = CustomRTWEntryHook(modelName)
str =sprintf('Custom entry hook for model ''%s.''',modelName);
disp(str)
status =1;

Example 3: CustomRTWPostProcessHook.m

function [str, status] = CustomRTWPostProcessHook(modelName)
str =sprintf('Custom post process hook for model ''%s.''',modelName);
disp(str)
status =1;

If you include the above three files on the MATLAB path of the Simulink installation that you want to customize, the coded hook function messages will appear in the displayed output for Simulink Coder builds. For example, if you open the ERT-based model rtwdemo_udt, open the Code Generation pane of the Configuration Parameters dialog box, and click the Build button to initiate a Simulink Coder build, the following messages are displayed:

>> rtwdemo_udt

### Starting build procedure for model: rtwdemo_udt
Custom entry hook for model 'rtwdemo_udt.'
Custom post process hook for model 'rtwdemo_udt.'
### Successful completion of build procedure for model: rtwdemo_udt
>> 
  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

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