Skip to main content

IAR Embedded Workbench for Arm 9.70.x

Using build actions

In this section:

You can use build actions to execute commands in a specific order during the build process. This way you can customize the build process and use dependencies between commands.

A build action consists of a command, a set of input and output files, a directory in which the command is executed, and a build order. The build action is sent to Ninja, which uses the information to create the order in which the commands are executed during the build process.

The Project>Options>Build Actions options let you specify the required actions. For more information about the build actions options, see Build actions options.

Tips for using build actions

You can create dependencies between build actions by listing fake output files as input to other build actions. A fake output file is a file that is listed as output in a build action, but which is not generated from that build action.

A build action is executed in a build process if:

  • Any of the listed output is a fake output file.

  • Any of the listed input has a newer timestamp than any of the listed output

  • The command line or working directory has been changed since the previous build.

Using a build action for time stamping

You can use a pre-build action to embed a time stamp for the build in the resulting binary file. Follow these steps:

  1. Create a dedicated time stamp file, for example, timestamp.c, and add it to your project.

  2. In this source file, use the preprocessor macros __TIME__ and __DATE__ to initialize a string variable.

  3. Choose Project>Options>Build Actions to open the Build Actions Configuration page.

  4. Click New to display the New Build Action dialog box.

  5. In the Command line text field, specify this command line:

    del "$OBJ_DIR$\timestamp.o"

    This command removes the timestamp.o object file.

    Alternatively, you can use the open source command line utility touch for this purpose (or any other suitable utility that updates the modification time of the source file). For example:

    touch $PROJ_DIR$\timestamp.c
  6. Set the Build order to Run after linking and click OK.

  7. Every time you build the project, timestamp.c will be recompiled and the correct timestamp will end up in the binary file.

Using a build action to copy files

You can use a build action to automatically copy files from a remote location, such as a network drive. Follow these steps:

  1. Choose Project>Options>Build Actions to open the Build Actions Configuration page.

  2. Click New to display the New Build Action dialog box.

  3. In the Command line text field, specify, for example, this command line:

    copy \\my-network-drive\remotefile.c localcopy.c

    This command copies the file from the network drive to your project directory.

  4. In the Output files box, specify localcopy.c.

  5. In the Input files box, specify \\my-network-drive\remotefile.c.

  6. Let the Build order setting remain Automatic (based on input and output), and click OK.

  7. Every time you use the Make command, and localcopy.c does not exist or is older than remotefile.c, the build action will copy the file from the network drive to your project directory.