Add Build Process Dependencies - MATLAB & Simulink (original) (raw)

When you specify a system target file for code generation, the code generator can build a standalone executable program that can run on the development computer. To build the executable program, the code generator uses the selected compiler and the makefile generated by the toolchain or template makefile (TMF) build process approach. Part of the makefile generation process is to add source file, header file, and library file information (the dependencies) in the generated makefile for a compilation. Or, for a specific application, you can add the generated files and file dependencies through a configuration management system.

The generated code for a model consists of a small set of files. (See Manage Build Process Files.) These files have dependencies on other files, which occur due to:

The model or external code introduces dependencies for various reasons:

File Dependency Information for the Build Process

The code generator provides several mechanisms to input file dependency information into the build process. The mechanisms depend on whether your dependencies are block-based or are model- or system target file-based.

For block dependencies, consider using:

For model- or system target file-based dependencies, such as external header files, consider using:

Generated Makefile Dependencies

For toolchain approach or template makefile (TMF) approach build processes, the code generator generates a makefile. For TMFs, the generated makefile provides token expansion in which the build process expands different tokens in the makefile to include the additional dependency information. The resulting makefile contains the complete dependency information. See Customize Template Makefiles.

The generated makefile contains:

A property of make utilities is that you do not have to specify the specific location for a given source C or C++ file. If a rule exists for that folder and the source filename is a prerequisite in the makefile, the make utility can find the source file and compile it. The C or C++ compiler (preprocessor) does not require absolute paths to the headers. The compiler finds header file with the name of the header file by using an #include directive and an include path. The generated C or C++ source code depends on this standard compiler capability.

Libraries are created and linked against, but occlude the specific functions that the program calls.

These properties can make it difficult to determine the minimum list of file dependencies manually. You can use the makefile as a starting point to determine the dependencies in the generated code.

Another approach to determining the dependencies is using linker information, such as a linker map file, to determine the symbol dependencies. The map file provides the location of code generator and blockset source and header files to help in locating the dependencies.

Code Generator Static File Dependencies

Several locations in the MATLABĀ® folder tree contain static file dependencies specific to the code generator:

Blockset Static File Dependencies

Blockset products with S-function code apply the rtwmakecfg.m mechanism to provide the code generator with dependency information. Thertwmakecfg.m file from the blockset contains the list of include path and source path dependencies for the blockset. Typically, blocksets create a library from the source files to which the generated model code can link. The libraries are created and identified when you use the rtwmakecfg.m mechanism.

To locate the rtwmakecfg.m files for blocksets in your MATLAB installed tree, use the following command:

which -all rtwmakecfg.m

If the model that you are compiling uses one or more of the blocksets listed by thewhich command, you can determine folder and file dependency information from the respective rtwmakecfg.m file.

Folder Dependency Information for the Build Process

You can add #include statements to generated code. Such references can come from several sources, including TLC scripts for inlining S-functions, custom storage classes, bus objects, and data type objects. The included files consist of header files for external code or other customizations. You can specify compiler include paths with the -I compiler option. The build process uses the specified paths to search for included header files.

Usage scenarios for the generated code include, but are not limited to, the following:

Use #include Statements and Include Paths

Consider the following approaches for using #include statements and include paths with the build process to generate code that remains portable and minimizes compatibility problems with future versions.

Assume that additional header files are:

c:\work\feature1\foo.h c:\work\feature2\bar.h

#include "foo.h"
#include "bar.h"
Then, the include path passed to the compiler contains folders in which the headers files exist:
cc -Ic:\work\feature1 -Ic:\work\feature2 ...

#include "feature1\foo.h"
#include "feature2\bar.h"

Then, specify the anchor folder (for example \work) to the compiler:

Avoid These Folder Dependencies

When using the build process, avoid dependencies on folders in the build process Code generation folder, such as the_`model`__ert_rtw folder or theslprj folder. Do not use paths in #include statements that are relative to the location of the generated source file. For example, if your MATLAB code generation folder is c:\work, the build process generates the _`model`_.c source file into a subfolder such as:

c:\work\model_ert_rtw\model.c

The _`model`_.c file has#include statements of the form:

#include "..\feature1\foo.h" #include "..\feature2\bar.h"

It is preferable to use one of the other suggested approaches because the relative path creates a dependency on the code generator folder structure.

See Also

Topics