If you require relocating the static and generated code files for a model to another development environment, use the pack-and-go utility. This condition occurs when your system or integrated development environment (IDE) does not include MATLAB® and Simulink® products.
The pack-n-go utility uses the tools for customizing the build process after code
generation and a packNGo
function to find and package
files for building an executable image. The files are packaged in a compressed file
that you can relocate and unpack using a standard zip
utility.
To package and relocate code for your model using the user interface:
In the Configuration Parameters dialog box, select Package code and artifacts. This option
configures the build process to run the packNGo
function after code
generation to package generated code and artifacts for relocation.
In the Zip file
name field, enter the name of the
zip
file in which to package generated code and
artifacts for relocation. You can specify the file name with or without the
.zip
extension. If you do not specify an extension or
an extension other than .zip
, the zip
utility adds the.zip
extension. If you do not specify a
value, the build process uses the name
, where
model
.zip
is the name of
the top model for which code is being generated.model
Apply changes and generate code for your model. To verify that it is ready
for relocation, inspect the resulting zip
file. Depending
on the zip
tool that you use, you could be able to open
and inspect the file without unpacking it.
Relocate the zip
file to the destination development
environment and unpack the file.
To package and relocate code for your model using the command-line interface:
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 folder structure. By
default, the packNGo
function packages the
files in a single, flat folder structure.
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 folder structure |
The destination development environment must maintain the folder structure of the source environment because it uses the generated makefile, or the code depends 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
folder
treematlabroot
sDirFiles.zip
— files in and under your
build folder where you initiated code generation for the model
otherFiles.zip
— required files not in the
or
matlabroot
start
folder trees
Paths for the secondary zip
files are relative to the root
folder of the primary zip
file, maintaining the source
development folder structure.
By default, the packNGo
function names the primary
zip
file
. You have the option of
specifying a different name. If you specify a file name and omit the file type
extension, the function appends model
.
to the name that you
specify.
Package model code files by using the PostCodeGenCommand
configuration parameter, packNGo
function, and build
information object for the model. You can set up the packaging operation to
use:
A system generated build information object.
In this case, before generating the model code, use set_param
to set the
configuration parameter PostCodeGenCommand
to an
explicit call to the packNGo
function. For
example:
set_param(bdroot, 'PostCodeGenCommand', 'packNGo(buildInfo);');
After generating and writing the model code to disk and before
generating a makefile, this command instructs the build process to
evaluate the call to packNGo
. This command uses
the system generated build information object for the currently selected
model.
A build information object that you construct programmatically.
In this case, you could use other build information functions to
include paths and files selectively 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);
The following examples show how you can change the default behavior of
packNGo
.
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'... |
Include header files found on the include path in the
zip file | packNGo(buildInfo, 'minimalHeaders'
false); |
Generate warnings for parse errors and missing files | packNGo(buildInfo, 'ignoreParseError'
true... |
Note
The packNGo
function can
potentially modify the build information passed in the first
packNGo
argument. As part of packaging model code,
packNGo
could find additional files from source and
include paths recorded in build information for the model and add them to
the build information.
To verify that it is ready for relocation, inspect the generated
zip
file. Depending on the zip
tool
that you use, you could be able to open and inspect the file without unpacking
it. If unpacking the file and you packaged the model code files as a
hierarchical structure, unpacking requires you to unpack the primary and
secondary zip
files. When you unpack the secondary
zip
files, relative paths of the files are
preserved.
Relocate the generated zip
file to the destination
development environment and unpack the file.
This example shows how to package code files generated for the example model
rtwdemo_rtwintro
using the command-line interface:
Set your working folder to a writable folder.
Open the model rtwdemo_rtwintro
and save a copy to your
working folder.
Enter the following MATLAB command:
set_param('rtwdemo_rtwintro', 'PostCodeGenCommand',... 'packNGo(buildInfo, ''packType'' ''hierarchical'')');
You must 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_rtwintro.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.
For information about limitations that apply to this function, see packNGo
.
If a build process uses the template makefile approach, then packNGo
uses the executable file
extension specified by the linker tool to determine binary artifacts that
require packaging.
If you generate an executable file with an extension that is not a default value, check that the extension is saved in the toolchain associated with the template makefile. For more information, see Associate the Template Makefile with a Toolchain.
If the build process generates an executable file with an extension that is
different from the extension saved in the toolchain, packNGo
does not package the executable file.