Main Content

Relocate Code to Another Development Environment

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.

Code Relocation

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.

Package Code Using the User Interface

To package and relocate code for your model using the user interface:

  1. 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.

  2. 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 model.zip, where model is the name of the top model for which code is being generated.

  3. 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.

  4. Relocate the zip file to the destination development environment and unpack the file.

Package Code Using the Command-Line Interface

To package and relocate code for your model using the command-line interface:

Select a Structure for the Zip File

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 filesSingle, 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 filesHierarchical 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 folder tree

  • sDirFiles.zip — files in and under your build folder where you initiated code generation for the model

  • otherFiles.zip — required files not in the matlabroot or 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.

Select a Name for the Zip File

By default, the packNGo function names the primary zip file model. You have the option of specifying a different name. If you specify a file name and omit the file type extension, the function appends . to the name that you specify.

Package Model Code in a Zip File

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 hierarchicalpackNGo(buildInfo, 'packType' 'hierarchical');
Rename the primary zip filepackNGo(buildInfo, 'fileName' 'zippedsrcs');
Change the structure of the file packaging to hierarchical and rename the primary zip filepackNGo(buildInfo, 'packType' 'hierarchical'...
'fileName' 'zippedsrcs');
Include header files found on the include path in the zip filepackNGo(buildInfo, 'minimalHeaders' false);
Generate warnings for parse errors and missing filespackNGo(buildInfo, 'ignoreParseError' true...
'ignoreFileMissing' 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.

Inspect a Generated Zip File

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 and Unpack a Zip File

Relocate the generated zip file to the destination development environment and unpack the file.

Code Packaging Example

This example shows how to package code files generated for the example model rtwdemo_rtwintro using the command-line interface:

  1. Set your working folder to a writable folder.

  2. Open the model rtwdemo_rtwintro and save a copy to your working folder.

  3. 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.

  4. Generate code for the model.

  5. Inspect the generated zip file, rtwdemo_rtwintro.zip. The zip file contains the two secondary zip files, mlrFiles.zip and sDirFiles.zip.

  6. Inspect the zip files mlrFiles.zip and sDirFiles.zip.

  7. Relocate the zip file to a destination environment and unpack it.

Limitations

packNGo Function

For information about limitations that apply to this function, see packNGo.

Executable File with Nondefault Extension

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.

Related Topics