Main Content

Template Makefiles and Make Options

The code generator includes a set of built-in template makefiles that build programs for specific system target files.

Types of Template Makefiles

There are two types of template makefiles:

  • Compiler-specific template makefiles are for a particular compiler or development system.

    By convention, compiler-specific template makefiles names correspond to the system target file and compiler (or development system). For example, grt_vcx64.tmf is the template makefile for building a generic real-time program under the Visual C++® compiler.

  • Default template makefiles make your model designs more portable, by choosing the compiler-specific makefile and compiler for your installation. Select and Configure C or C++ Compiler describes the operation of default template makefiles in detail.

    Default template makefiles have names that follow the pattern target_default_tmf. They are MATLAB® language files that, when run, select the TMF for the specified system target file configuration. For example, grt_default_tmf is the default template makefile for building a generic real-time program; ert_default_tmf is the default template makefile for building an Embedded Coder® program.

For details on the structure of template makefiles, see Customize Template Makefiles. This section describes compiler-specific template makefiles and common options you can use with each.

Specify Template Makefile Options

You can specify template makefile options through the Make command configuration parameter. Append the options after make_rtw (or other make command), as in the following example:

make_rtw OPTS="-DMYDEFINE=1"

The syntax for make command options differs slightly for different compilers.

Note

To control compiler optimizations for a makefile build, use the Compiler optimization level configuration parameter, which provides:

  • System target file-independent values Optimizations on (faster runs) and Optimizations off (faster builds), which easily allow you to toggle compiler optimizations on and off during code development

  • The value Custom for entering custom compiler optimization flags at Simulink® GUI level (rather than at other levels of the build process)

If you specify compiler options for your makefile build using OPT_OPTS, MEX_OPTS (except MEX_OPTS="-v"), or MEX_OPT_FILE, the value of Compiler optimization level is ignored and a warning is issued about the ignored parameter.

Template Makefiles for UNIX Platforms

The template makefiles for UNIX® platforms are for the Free Software Foundation's GNU® Make. These makefiles conform to the guidelines specified in the IEEE®1 Std 1003.2-1992 (POSIX) standard:

  • ert_unix.tmf

  • grt_unix.tmf

You can supply options to makefiles through the Make command configuration parameter. Options specified in Make command are passed to the command-line invocation of the make utility, which adds them to the overall flags passed to the compiler. The following options can be used to modify the behavior of the build:

  • OPTS — User-specific options, for example,

    OPTS="-DMYDEFINE=1"
  • OPT_OPTS— Optimization options. Default is -O. To enable debugging, specify the option as OPT_OPTS=-g. Because of optimization problems in IBM_RS, the default is to not optimize.

  • CPP_OPTS — C++ compiler options.

  • USER_SRCS — Additional user sources, such as files used by S-functions.

  • USER_INCLUDES — Additional include paths, for example,

    USER_INCLUDES="-Iwhere-ever -Iwhere-ever2"
  • DEBUG_BUILD — Add debug information to generated code, for example,

    DEBUG_BUILD=1

These options are also documented in the comments at the head of the respective template makefiles.

Template Makefiles for the Microsoft Visual C++ Compiler

To build an executable file using the Visual C++ compiler, use one of the target_vcx64.tmf template makefiles:

  • ert_vcx64.tmf

  • grt_vcx64.tmf

You can supply options to makefiles through the Make command configuration parameter. Options specified in Make command are passed to the command-line invocation of the make utility, which adds them to the overall flags passed to the compiler. The following options can be used to modify the behavior of the build:

  • OPT_OPTS — Optimization option. Default is -O2. To enable debugging, specify the option as OPT_OPTS=-Zi.

  • OPTS — User-specific options. For example:

    OPTS="/D MYDEFINE=1"

  • CPP_OPTS — C++ compiler options.

  • USER_SRCS — Additional user sources, such as files used by S-functions.

  • USER_INCLUDES — Additional include paths, for example,

    USER_INCLUDES="-Iwhere-ever -Iwhere-ever2"
  • DEBUG_BUILD — Add debug information to generated code, for example,

    DEBUG_BUILD=1

These options are also documented in the comments at the head of the respective template makefiles.

Related Topics


1 IEEE is a registered trademark of The Institute of Electrical and Electronics Engineers, Inc.