5.11.2 Execute this line before/after the build

Type in a command to be executed at the very beginning or at the very end of the build process. These commands are inserted into the nbproject/Makefile-$CONF.mk file and allow you to customize the build process. If you need to refer to some of the project-related items (like the image name) in the script or program you are calling, use the supplied macros.

You can type the macros yourself or click Insert Macro to copy the macro name into the current position in the edit box. Commands are run in the make process with the current directory being set to the MPLAB X IDE project directory. The project directory is defined as the project that contains the nbproject folder.

Table 5-3. Macros
Name* Function
_/_ path delimiter based on PC operating system
ShExtension shell extension based on PC operating system
Device device for the currently-selected project configuration
ProjectDir location of the project files on the PC
ProjectName name of the currently-selected project
ConfName name of the currently-selected project configuration
ImagePath path to the build image
ImageDir directory containing the build image
ImageName name of the build image
IsDebug “true” for Debug mode; “false” otherwise
* Additional macros may be available, depending on which compiler is used.

Example: Execute a Process Only During Debug

Click the IsDebug macro (as shown in the window below) to select it, then click Insert Macro to insert it into a script.

Figure 5-28. Build Properties – Pre/Post Build

Check the value of $1 (Linux or macOS) or %1 (Windows OS) in the script being run.

Bash Code Example

#!/bin/bash
echo is $1
if [ "$1" == "true" ]; then
echo We are in debug
else
echo We are in production
fi

Batch Code Example

@echo off
if "%1" == "true" goto debug
:production
@echo We are in production
goto end
:debug
@echo We are in debug
:end