Main Content

Customize Build Process with sl_customization.m

The Simulink® customization file sl_customization.m is a mechanism that allows you to use MATLAB® to customize the build process 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 Registering Customizations.

The sl_customization.m File

The sl_customization.m file can be used to register installation-specific hook functions to be invoked during the build process. The hook functions that you register through sl_customization.m complement System Target File (STF) hooks (described in Customize Build Process with 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 are invoked during the 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 build process hook customizations:

  • addUserHook(hObj, hookType, hook)

    Registers the MATLAB hook script or function specified by hook for the build process stage represented by hookType. The valid values for hookType are 'entry', 'before_tlc', 'after_tlc', 'before_make', 'after_make', and 'exit'.

Use this method to register installation-specific hook functions in your instance of the sl_customization function.

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 in the Command Window to enable 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:

  • modelName — The name of the Simulink model (valid for all stages)

  • dependencyObject — An object containing the dependencies of the generated code (valid only for the 'after_make' stage)

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 of Build Process Customization with sl_customization.m

The sl_customization.m file shown in the example, sl_customization.m for 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 build process. For the hook function source code, see the CustomRTWEntryHook.m and CustomRTWPostProcessHook.m examples.

Example 1. sl_customization.m for 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 appear in the displayed output for builds. For example, if you open the ERT-based model rtwdemo_udt, open the Code Generation pane of the Configuration Parameters dialog box, and press Ctrl+B to initiate a 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
>>