Building Generated Code

Once the model has been transformed to C++ code in a CDT project, the next step in the build process is to build the generated code (i.e. to compile and link it). This is done by building the CDT project. Depending on the TC property "Automatically create and update target project" the CDT project will be configured to be built in different ways. If this property is unset the CDT project is assumed to have been properly set-up so it can be built directly. However, if the property is set the model compiler will also generate a makefile which the CDT project will build using a make tool (acting as an external builder from CDT's point of view). You can open the Properties dialog on a CDT project if you are uncertain how it will be built. Here is an example of a CDT project that will be built using a make file:

To learn more about how a CDT project is built you may refer to the Eclipse CDT documentation. In the rest of this chapter we will look at the case when the build takes place using a generated makefile.

A big advantage with building a generated C++ project using a makefile is that the workspace will only be locked for modifications during the time it takes to run the C++ transformation. Once all code has been generated (including CDT projects and makefiles), the rest of the build is done by make on the makefiles and during this time the workspace is not locked. This means that you can continue to work in the model as soon as the transformation phase is completed. Usually this phase is much shorter than the time it takes to run make on the makefile.

If you use the model compiler as your build tool, this can be further improved so that the workspace only is locked when generating the makefile. This makefile can then drive the complete build, including C++ transformations. This feature is, however, currently only supported for batch builds.

Makefile Generation

There are two kinds of makefiles that may be generated by the model compiler (controlled by the preference RealTime Development Build/Transformations – Type of Generated Make Files):

The default is to generate recursive makefiles, since it yields makefiles that are shorter and easier to read. However, the performance of the build may be improved if you instead choose to generate inclusive makefiles. This is in particular true for make tools that support parallel builds, since the distribution of build tasks on different computers often can be done more efficiently with a single makefile as input.

The makefile that is generated for the TC that is built is called batch.mk. Note that in spite of its name this makefile is used both for interactive builds and batch builds. The build is done by running the following make command:

<make-command> <make-arguments> -f batch.mk all

where and are specified in the "Target Configuration" tab in the TC.

In addition to batch.mk a makefile called Makefile is also generated. This makefile (and included makefile fragments 0.mk, 1.mk etc.) is invoked from batch.mk.