| Real-Time Workshop® | ![]() |
| On this page… |
|---|
Deciding on a Structure for the Zip File Deciding on a Name for the Zip File Packaging Model Code Files in a Zip File Inspecting the Generated Zip File |
If you need to relocate the static and generated code files for a model to another development environment, such as a secure system or an integrated development environment (IDE) that does not include MATLAB® and Simulink® products, use the Real-Time Workshop® pack-and-go utility. This utility uses the tools for customizing the build process after code generation and a packNGo function to find and package all files needed to build an executable image. The files are packaged in a compressed file that you can relocate and unpack using a standard zip utility.
To relocate a model's code files,
Before you generate and package the files for a model build, decide whether you want the files to be packaged in a flat or hierarchical directory structure. By default, the packNGo function packages all the necessary files in single, flat directory structure. This is the simplest approach and might be the optimal choice.
| If... | Then Use a... |
|---|---|
| You are relocating files to an IDE that does not use the generated makefile or the code is not dependent on the relative location of required static files | Single, flat directory structure |
| The target development environment must maintain the directory structure of the source environment because it uses the generated makefile or the code is dependent on the relative location of files | Hierarchical structure |
If you use a hierarchical structure, the packNGo function creates two levels of zip files, a primary zip file, which in turn contains the following secondary zip files:
mlrFiles.zip — files in your matlabroot directory tree
sDirFiles.zip — files in and under your build directory where you initiated the model's code generation
otherFiles.zip — required files not in the matlabroot or start directory trees
Paths for the secondary zip files are relative to the root directory of the primary zip file, maintaining the source development directory structure.
By default, the packNGo function names the primary zip file model.zip. You have the option of specifying a different name. If you specify a file name and omit the file type extension, the function appends .zip to the name you specify.
You package model code files by using the PostCodeGenCommand configuration parameter, packNGo function, and the model's build information object. You can set up the packaging operation to use
A system generated build information object.
In this case, use set_param to set the configuration parameter PostCodeGenCommand to an explicit call to the packNGo function before generating the model code. For example:
set_param(bdroot, 'PostCodeGenCommand', 'packNGo(buildInfo);');
This command instructs the Real-Time Workshop build process to evaluate the call to packNGo, using the system generated build information object for the currently selected model, after generating and writing the model's code to disk and before generating a makefile.
A build information object that you construct programmatically, as explained in Customizing Post Code Generation Build Processing.
In this case, you might use other build information functions to selectively include paths and files in the build information object that you then specify with the packNGo function. For example:
.
.
.
myModelBuildInfo = RTW.BuildInfo;
addSourceFiles(myModelBuildInfo, {'test1.c' 'test2.c' 'driver.c'});
.
.
.
packNGo(myModelBuildInfo);To change the default behavior of packNGo, see the following examples:
| To... | Specify... |
|---|---|
| Change the structure of the file packaging to hierarchical | packNGo(buildInfo, {'packType' 'hierarchical'}); |
| Rename the primary zip file | packNGo(buildInfo, {'fileName' 'zippedsrcs'}); |
| Change the structure of the file packaging to hierarchical and rename the primary zip file | packNGo(buildInfo, {'packType' 'hierarchical'... 'fileName' 'zippedsrcs'}); |
Inspect the resulting zip file in your working directory on the source system to verify that it is ready for relocation to the destination system. Depending on the zip tool you use you might be able to open and inspect the file without unpacking it. If you need to unpack the file and you packaged the model code files as a hierarchical structure, you will need to unpack the primary and secondary zip files. When you unpack the secondary zip files, relative paths of all files are preserved.
Relocate the resulting zip file to the destination development environment and unpack the file.
The following example guides you through the steps for packaging code files generated for the demo model rtwdemo_f14.
Set your working directory to a writable directory.
Open the model rtwdemo_f14 and save a copy to your working directory.
Enter the following command in the MATLAB Command Window:
set_param('rtwdemo_f14', 'PostCodeGenCommand',...
'packNGo(buildInfo, {''packType'' ''hierarchical''})'); Note that it is necessary to double the single-quotes due to the nesting of character arrays 'packType' and 'hierarchical' within the character array that specifies the call to packNGo.
Generate code for the model.
Inspect the generated zip file, rtwdemo_f14.zip. The zip file contains the two secondary zip files, mlrFiles.zip and sDirFiles.zip.
Inspect the zip files mlrFiles.zip and sDirFiles.zip.
Relocate the zip file to a destination environment and unpack it.
The following limitations apply to use of the packNGo function:
The function operates on source files, such as *.c, *.cpp, *.h files, only. The function does not support compile flags, defines, or makefiles.
Unnecessary files may be included. For example, the function includes all S-function libraries in an all-or-nothing manner and all header files from every include directory, even if they are not used.
![]() | Integrating Legacy and Custom Code | Generated Code Formats | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |