| Contents | Index |
| On this page… |
|---|
Using Makefiles to Generate and Build Software Making an XMakefile Configuration Operational Working with Microsoft Visual Studio |
You can use makefiles instead of IDE projects during the automated software build process. This approach is described in Using Makefiles to Generate and Build Software.
The XMakefile feature lets you choose the configuration of a specific software build tool chain to use during the automated build process. The configuration contains paths and settings for your make utility, compiler, linker, archiver, pre-build, post-build, and execute tools.
You can choose one built-in configuration described in and Available XMakefile Configurations.
You can also create a new configuration for a new tool chain, as described in Example: Creating a New XMakefile Configuration.
Your requirements for specific features may determine whether you choose makefiles or IDE projects. See Feature Support.
Simulink Coder includes support for the following IDEs and tool chains.
| Tool Chain | Processor Family/Target Operating System | Host Operating System |
|---|---|---|
| GNU development tools | Linux | Linux |
| MinGW development tools | Windows | Windows |
| Microsoft Visual Studio | Windows | Windows |
Embedded Coder includes support for other IDEs and tool chains. See Supported Tool Chains in Embedded Coder.
The following list describes the configurations in the XMakefile dialog box that this product supports:
gcc_target: GNU Compiler Collection & Host Operating System or Embedded Operating System
mingw_host: Minimalist GNU for Windows & Host Operating System
msvs_host: Microsoft Visual Studio & Host Operating System
For more information about supported versions of third-party software, see Support for Third Party Products
With makefiles, you cannot use features that rely on direct communications between your MathWorks software and third-party IDEs.
You cannot use the following features with makefiles:
IDE Project Generation
IDE Automation Interface
IDE debugger communications during Processor-in-the-loop (PIL) simulation
In addition to this chapter, see the Makefile Generator Tutorial demo for more information about using makefiles to generate code.
Update your model Configuration Parameters to use a makefile instead of an IDE when you build software from the model:
Add a Target Preferences block to your model and configure it for your target processor. For more information, see Target Preferences.
In your model window, select Simulation > Configuration Parameters.
Under Code Generation, select IDE Link.
Set Build format to Makefile. For more information, see Build format.
Set Build action to Build_and_execute. For more information, see Build action.
Configure how to generate makefiles:
Enter xmakefilesetup on the MATLAB command line. The software opens an XMakefile User Configuration dialog box.

Leave Template set to gmake.
For Configuration, select gcc_target or msvs_host to match the compiler toolchain you are using — gcc or Microsoft Visual Studio, respectively. Click Apply.
Note Changing some elements of the XMakefile dialog box disables other elements until you apply the changes. Click Apply or OK after changing any of the following:
|
Note With the XMakefile User Configuration dialog, if you have a Simulink Coder license but no Embedded Coder license, the only valid settings for Configuration are gcc_target, mingw_host, or msvs_host. The other configurations, though visible, are only supported by the Embedded Coder product. |
Note If you set Configuration to msvs_host, restart MATLAB as described in Working with Microsoft Visual Studio before building your model software. |
Things to consider while setting Configuration:
Selecting Display operational configurations only hides configurations that contain incomplete or invalid information. For a configuration to be operational, the vendor tool chain must be installed, and the configuration must have the valid paths for each component of the vendor tool chain. For more information, see Making an XMakefile Configuration Operational.
To display all of the configurations, including non-operational configurations, clear Display operational configurations only.
The list of configurations can include non-editable configurations defined in the software and editable configurations defined by you.
To create a new editable configuration, use the New button.
For more information, see XMakefile User Configuration Dialog Box.
In your model, click the build button or enter Ctrl+B. This action creates a makefile and performs the other actions you specified in Build action.
By default, this process outputs files in the <builddir>/<buildconfiguration> folder. For example, in model_name/CustomMW.
When the XMakefile utility starts, it checks each configuration file to verify that the specified paths for the vendor tool chain are valid. If the paths are not valid, the configuration is non-operational. Typically, the cause of this problem is a difference between the path in the configuration and the actual path of the vendor toolchain.
To make a configuration operational:
Clear Display operational configurations only to display non-operational configurations.
Select the non-operational configuration from the Configuration options.
When you click Apply, a new dialog box prompts you for the folder path of any missing resources the configuration requires.
Use mapped network drives instead of UNC paths to specify directory locations. Using UNC paths with compilers that do not support them causes build errors.
If you set Configuration to msvs_host, restart MATLAB from a Visual Studio® command prompt before building your model software with makefiles. The vsvars32.bat file associated with the Visual Studio command prompt configures the Visual Studio environment. Starting MATLAB from this command prompt results in a session that can generate makefiles from the msvs_host configuration.
To restart MATLAB from a Visual Studio command prompt:
Open a Visual Studio command prompt:
Select your MSVS product from the Windows Start > Programs menu.
In Visual Studio Tools, select the Visual Studio Command Prompt. For example:
![]()
Enter matlab at the Visual Studio Command Prompt.
In MATLAB, open and build your model.
If you do not restart MATLAB from Microsoft Visual Studio command prompt, building your model software generates an error whose ending is similar to the following text:
The build failed with the following message: "C:/Program Files/Microsoft Visual Studio... 3792 Abort C:/Program Files/Microsoft Visual Studio 8/VC/bin/cl gmake: *** [MW_csl.obj] Error 134
A related article is available on the Microsoft Web site at: http://msdn.microsoft.com/en-us/library/1700bbwd.aspx
This example shows you how to add support for a software development toolchain to the XMakefile utility. This example uses the Intel Compiler and Eclipse IDE, which provides an open framework and allows for otherwise unsupported toolchains.
Note To specify directory locations, use mapped network drives instead of UNC paths. UNC paths cause build errors with compilers that do not support them. |
When you click New, the new configuration inherits values and behavior from the current configuration. To create a configuration for the Intel Compiler, clone a configuration from any of these configurations: msvs_host, mingw_host and gcc_target.
Note The linker used by the Intel Compiler uses the Microsoft Visual Studio tool chain and therefore the execution environment must have access to these tools (vcvars.bat). For more information, see Working with Microsoft Visual Studio. |
Open the XMakefile User Configuration UI by typing xmakefilesetup at the MATLAB prompt. This action displays the following dialog box.

Select an existing configuration, such as msvs_host, mingw_host, montavista_arm or gcc_target. Click the New button.
A pop-up dialog prompts you for the name of the new configuration. Enter intel_compiler and click OK.

The dialog box displays a new configuration called intel_compiler, based on the previous configuration.

Adjust the compiler, linker, and archiver settings of the newly created configuration. This example assumes the location of the Intel compiler is C:\Program Files\Intel\Compiler\.
Make Utility. You do not need to make any changes. This configuration uses the gmake tool that ships with MATLAB.

Compiler. For Compiler, enter the location of icl.exe in the Intel installation.

Linker. For Linker, enter the location of the linker executable, xilink.exe.
For Arguments, add the /LIBPATH path to the Intel libraries.

Archiver. For Archiver, enter the location of the archiver, xilib.exe. Confirm that File extensions for library files includes .lib.

Other tabs. For this example, ignore the remaining tabs. In other circumstances, you can use them to configure additional build actions. In a later step of this example, you will configure the software to automatically build and run the generated code.

Open the "sumdiff" model by entering sumdiff on the MATLAB prompt.

Use a Target Preferences block to configure the model for use with the Eclipse IDE. In the Simulink Library Browser, search for "Target Preferences". Drag and drop the Target Preferences block from the search results to the summdiff model.

Configure the Target Preferences block as follows: set IDE/Tool Chain to Eclipse, set Board to Custom, and set Processor to Intel x86/Pentium.
Open the Target Preferences block and set Operating System to None or select Windows. Click OK.

Open the Configuration Parameters for the summdiff model by pressing Ctrl+E. Set Build format to Makefile and Build action to Build_and_execute.
Save the model to a temporary location, such as C:\Temp\IntelTest\.
Set that location as a Current Folder by typing cd C:\temp\IntelTest\ at the MATLAB prompt.
Build the model by pressing Ctrl+B. The MATLAB Command Window displays something like:
### TLC code generation complete. ### Creating HTML report file sumdiff_codegen_rpt.html ### Creating project: c:\temp\IntelTest\sumdiff_eclipseide\sumdiff.mk ### Project creation done. ### Building project... ### Build done. ### Downloading program: c:\temp\IntelTest\sumdiff_eclipseide\sumdiff ### Download done.
A command window comes up showing the running model. Terminate the generated executable by pressing Ctrl+C.

Template. Select the template that matches your toolchain and processor. The template defines the syntax rules for writing the contents of the makefile or buildfile. The default template is gmake, which works with the GNU make utility.
To add templates to this parameter, save them as .mkt files to the location specified by the User Templates parameter. For more information, see User Templates.
Configuration. Select the configuration that best describes your toolchain and target processor.
You cannot edit or delete the configurations provided by MathWorks. You can, however, edit and delete the configurations that you create.
Use the New button to create an editable copy of the currently selected configuration.
Use the Delete button to delete a configuration you created.
Note Use mapped network drives instead of UNC paths to specify directory locations. Using UNC paths with compilers that do not support them causes build errors. |
Display operational configurations only. When you open the XMakefile User Configuration dialog box, the software verifies that each configuration provided by MathWorks contains valid paths to the executable files it uses. If all of the paths are valid, the configuration is operational. If any of the paths are not valid, the configuration is not operational.
This setting only affects configurations provided by MathWorks, not configurations you create.
To display valid configurations, select Display operational configurations only.
To display all of the configurations, including non-operational configurations, clear Display operational configurations only.
For more information, see Making an XMakefile Configuration Operational.
User Templates. Set the path of the folder to which you can add template files. Saving templates files with the .mkt extension to this folder adds them to the Templates options.
User Configurations. Set the location of configuration files you create with the New button.

Make utility. Set the path and filename of the make utility executable.
Arguments. Define the command-line arguments to pass to the make utility. For more information, consult the third-party documentation for your make utility.
Optional include. Set the path and file name of an optional makefile to include.

Compiler. Set the path and file name of the compiler executable.
Arguments. Define the command-line arguments to pass to the compiler. For more information, consult the third-party documentation for your compiler.
Source. Define the file name extension for the source files. Use commas to separate multiple file extensions.
Header. Define the file name extension for the header files. Use commas to separate multiple file extensions.
Object. Define the file name extension for the object files.

Linker. Set the path and file name of the linker executable.
Arguments. Define the command-line arguments to pass to the linker. For more information, consult the third-party documentation for your linker.
File extensions for library files. Define the file name extension for the file library files. Use commas to separate multiple file extensions.
Generated output file extension. Define the file name extension for the generated libraries or executables.

Archiver. Set the path and file name of the archiver executable.
Arguments. Define the command-line arguments to pass to the archiver. For more information, consult the third-party documentation for your archiver.
Generated output file extension. Define the file name extension for the generated libraries.

Enable Prebuild Step. Select this check box to define a prebuild tool that runs before the compiler.
Prebuild tool. Set the path and file name of the prebuild tool executable.
Arguments. Define the command-line arguments to pass to the prebuild tool. For more information, consult the third-party documentation for your prebuild tool.

Enable Postbuild Step. Select this check box to define a postbuild tool that runs after the compiler or linker.
Postbuild tool. Set the path and file name of the postbuild tool executable.
Arguments. Define the command-line arguments to pass to the postbuild tool. For more information, consult the third-party documentation for your postbuild tool.

Use Default Execute Tool. Select this check box to use the generated derivative as the execute tool when the build process is complete. Uncheck it to specify a different tool. The default value, echo, simply displays a message that the build process is complete.
Note On Linux, multirate multitasking executables require root privileges to schedule POSIX threads with real-time priority. If you are using makefiles to build multirate multitasking executables on your Linux development system, you cannot use Execute tool to run the executable. Instead, use the Linux command, sudo, to run the executable. |
Execute tool. Set the path and file name of the execute tool executable or built-in command.
Arguments. Define the command-line arguments to pass to the execute tool. For more information, consult the third-party documentation for your execute tool.

Installation. Use the Tool Directories tab to change the toolchain path of an operational configuration.
For example, if you installed two versions of a vendor build tool in separate folders, you can use the Installation path to change which one the configuration uses.
![]() | IDE Projects | Verification Code Generated for Desktop Targets | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |