CodeBlocks Built-in Variables (Macros)

CodeBlocks has a rich set of built-in variables. They can be used in the Build Options edit boxes for executing commands or specifying file paths, or in the Tools->Configure Tools... dialog box.

A variable reference is in the form of $(NAME) or ${NAME}. Note that directory references do not expand the ending slash directory separator.

Program Environment

$(IMAGECRAFT_DIR) – expands to the root directory of the installation, e.g. c:\iccv9cortex.

$(TARGET_COMPILER_DIR) – expands to the build tool executable root directory, e.g. c:\iccv9cortex\GnuARM\bin.

$(TARGET_CC), $(TARGET_CPP), $(TARGET_LD), $(TARGET_LIB) – these expand to the build tool executable (compiler, linker, etc.) of the current target, e.g. $(TARGET_CC) usually expands to arm-none-eabi-gcc.exe.

CodeBlocks Workspace

$(WORKSPACE_FILENAME), $(WORKSPACE_FILE_NAME), $(WORKSPACEFILE), $(WORKSPACEFILENAME) – these expand to the filename of the current workspace project.

$(WORKSPACENAME), $(WORKSPACE_NAME) – these expand to the name of the workspace that is displayed in tab Projects of the Management panel.

$(WORKSPACE_DIR), $(WORKSPACE_DIRECTORY), $(WORKSPACEDIR), $(WORKSPACEDIRECTORY) – these expand to the location of the workspace directory.

Files and directories

$(PROJECT_FILENAME), $(PROJECT_FILE_NAME), $(PROJECT_FILE), $(PROJECTFILE) – these expand to the filename of the currently compiled project.

$(PROJECT_NAME) – expands to the name of the currently compiled project.

$(PROJECT_DIR), $(PROJECTDIR), $(PROJECT_DIRECTORY) – these expand to the top-level directory of the currently compiled project.

$(ACTIVE_EDITOR_FILENAME) – expands to the filename of the file opened in the currently active editor.

$(ACTIVE_EDITOR_DIRNAME) – expands to the directory containing the currently active file (relative to the common top-level path).

$(ACTIVE_EDITOR_STEM) – expands to the base name (without extension) of the currently active file.

$(ACTIVE_EDITOR_EXT) – expands to the extension of the currently active file.

$(ALL_PROJECT_FILES) – expands to a string containing the names of all files in the current project.

$(MAKEFILE) – expands to the filename of the makefile.

$(CODEBLOCKS), $(APP_PATH), $(APPPATH), $(APP-PATH) – these expand to the path to the currently running instance of CodeBlocks.

$(DATAPATH), $(DATA_PATH), $(DATA-PATH) – these expand to the “shared” directory of the currently running instance of CodeBlocks.

$(PLUGINS) – expands to the plugins directory of the currently running instance of CodeBlocks.

Build targets

$(<target_name>_OUTPUT_FILE) – expands to the output file of a specific target.

$(<target_name>_OUTPUT_DIR) – expands to the output directory of a specific target.

$(<target_name>_OUTPUT_BASENAME) – expands to the output file’s base name (no path, no extension) of a specific target.

$(TARGET_OUTPUT_DIR) – expands to the output directory of the current target.

$(TARGET_OBJECT_DIR) – expands to the object directory of the current target.

$(TARGET_NAME) – expands to the name of the current target.

$(TARGET_OUTPUT_FILE) – expands to the output file of the current target.

$(TARGET_OUTPUT_BASENAME) – expands to the output file’s base name (no path, no extension) of the current target.

Language and encoding

$(LANGUAGE) – expands to the system language in plain language.

$(ENCODING) – expands to the character encoding in plain language.

Time and date

$(TDAY) – expands to the current date in the form YYYYMMDD (for example, 20051228).

$(TODAY) – expands to the current date in the form YYYY-MM-DD (for example 2005-12-28).

$(NOW) – expands to the timestamp in the form YYYY-MM-DD-hh.mm (for example 2005-12-28-07.15).

$(NOW_L) – expands to the timestamp in the form YYYY-MM-DD-hh.mm.ss (for example 2005-12-28-07.15.45).

$(WEEKDAY) – expands to the plain-language day of the week (for example, “Wednesday”).

$(TDAY_UTC), $(TODAY_UTC), $(NOW_UTC), $(NOW_L_UTC), $(WEEKDAY_UTC) – these expansions are similar to the corresponding variables without the _UTC suffix with the time expressed in TUC format.

$(DAYCOUNT) – expands to the number of days passed since an arbitrarily chosen day zero (January 1, 2009). Useful as the last component of a version/build number.

Random values

$(COIN) – expands to 0 or 1 in some random manner, emulating a coin toss.

$(RANDOM) – expands to a 16-bit positive random number (0-65535).

Operating System Commands

As “generic” CodeBlocks can run on different operating systems, these commands are useful to reference OS commands in generic forms.

$(CMD_CP) – expands to the “file copy” command, i.e. copy.

$(CMD_RM) – expands to the “delete file” command, i.e. delete.

$(CMD_MV) – expands to the “move file” command, i.e. rename.

$(CMD_MKDIR) –  expands to the “make directory” (create directory) command, i.e. mkdir.

$(CMD_RMDIR) – expands to the “remove directory” command, i.e. rmdir.