Difference between revisions of "Variable expansion"

From Code::Blocks
(Add $(PLATFORM) information)
 
(29 intermediate revisions by 8 users not shown)
Line 1: Line 1:
[[Category:Application Development]]
+
[[Category:User Documentation]]
== Scope ==
 
This article refers to builtin variables to be used in during the build process,
 
using '''Code::Blocks revision 1996 and newer'''.<br/>
 
Older versions may not support all of the listed types.
 
  
 
== Syntax ==
 
== Syntax ==
 
Code::Blocks treats the following functionally identical character sequences inside pre-build, post-build, or build steps  as variables:
 
Code::Blocks treats the following functionally identical character sequences inside pre-build, post-build, or build steps  as variables:
  
<tt>$VARIABLE</tt>, <tt>$(VARIABLE)</tt>, <tt>${VARIABLE}</tt>,  and <tt>%VARIABLE%</tt>
+
* <code>$VARIABLE</code>
 +
* <code>$(VARIABLE)</code>
 +
* <code>${VARIABLE}</code>
 +
* <code>%VARIABLE%</code>
  
 
+
Variable names must consist of alphanumeric characters and are not case-sensitive. Variables starting with a single hash sign (<code>#</code>) are interpreted as [[global compiler variables]].
Variable names must consist of alphanumeric characters and are not case-sensitive. Variables starting with a single hash sign (<tt>#</tt>) are interpreted as [[global user variables]].
 
 
The names listed below are interpreted as builtin types.
 
The names listed below are interpreted as builtin types.
  
 
Variables which are neither global user variables nor builtin types are replaced with a value provided in the project file, or with an environment variable if the latter should fail.
 
Variables which are neither global user variables nor builtin types are replaced with a value provided in the project file, or with an environment variable if the latter should fail.
Per-target definitions have precedence over per-project definitions.
+
 
 +
The use of these variables can follow the following example for the date :
 +
 
 +
<code>#include "include/manager.h"
 +
 
 +
wxString strdate = Manager::Get()->GetMacrosManager()->ReplaceMacros(_T("$TODAY"));</code>
 +
 
 +
'''Per-target definitions have precedence over per-project definitions.'''
 +
 
 +
Buildin variable expansion is much like pre-defined macro expansion in C preprocessor as it will be text replaced when processed.
  
 
== List of available builtins ==
 
== List of available builtins ==
  
<tt>$(PROJECT_FILENAME) $(PROJECT_FILE) $(PROJECTFILE)</tt><br/>
+
=== Code::Blocks workspace ===
The filename of the currently compiling project.
+
 
 +
<code>$(WORKSPACE_FILENAME)</code>, <code>$(WORKSPACE_FILE_NAME)</code>, <code>$(WORKSPACEFILE)</code>, <code>$(WORKSPACEFILENAME)</code>
 +
:The filename of the current workspace project (.workspace).
 +
 
 +
<code>$(WORKSPACENAME)</code>, <code>$(WORKSPACE_NAME)</code>
 +
:The name of the workspace that is displayed in the tab Projects of the Management panel.
 +
 
 +
<code>$(WORKSPACE_DIR)</code>, <code>$(WORKSPACE_DIRECTORY)</code>, <code>$(WORKSPACEDIR)</code>, <code>$(WORKSPACEDIRECTORY)</code>
 +
:The location of the workspace directory.
 +
 
 +
=== Files and directories ===
 +
 
 +
<code>$(PROJECT_FILENAME)</code>, <code>$(PROJECT_FILE)</code>, <code>$(PROJECTFILE)</code>, <code>$(PROJECTFILENAME)</code>, <code>$(PROJECT_FILE_NAME)</code>
 +
:The filename of the currently compiling project.
 +
 
 +
<code>$(PROJECT_NAME)</code>, <code>$(PROJECTNAME)</code>
 +
:The name of the currently compiling project.
 +
 
 +
<code>$(PROJECT_DIR)</code>, <code>$(PROJECTDIR)</code>, <code>$(PROJECT_DIRECTORY)</code>, <code>$(PROJECTDIRECTORY)</code>
 +
:The common directory of the currently compiling project.
 +
 
 +
<code>$(PROJECTTOPDIR)</code>, <code>$(PROJECT_TOPDIR)</code>, <code>$(PROJECTTOPDIRECTORY)</code>, <code>$(PROJECT_TOPDIRECTORY)</code>
 +
:The common top-directory of the currently compiling project.
 +
 
 +
<code>$(ACTIVE_EDITOR_FILENAME)</code>
 +
:The filename of the file opened in the currently active editor.
 +
 
 +
<code>$(ACTIVE_EDITOR_LINE)</code>
 +
:Return the current line in the active editor.
 +
 
 +
<code>$(ACTIVE_EDITOR_COLUMN)</code>
 +
:Return the column of the current line in the active editor.
 +
 
 +
<code>$(ACTIVE_EDITOR_DIRNAME)</code>
 +
:Currently active file's containing directory (relative to the common top level path)
 +
 
 +
<code>$(ACTIVE_EDITOR_STEM)</code>
 +
:Currently active file's base name (without extension).
 +
 
 +
<code>$(ACTIVE_EDITOR_EXT)</code>
 +
:Currently active file's extension.
 +
 
 +
<code>$(ACTIVE_EDITOR_SELECTION)</code>
 +
:Currently selected text from active editor.
 +
 
 +
<code>$(ALL_PROJECT_FILES)</code>
 +
:A string containing the names of all files in the current project.
 +
 
 +
<code>$(MAKEFILE)</code>
 +
:The filename of the makefile.
 +
 
 +
<code>$(CODEBLOCKS)</code>, <code>$(APP_PATH)</code>, <code>$(APPPATH)</code>, <code>$(APP-PATH)</code>
 +
:The path to the currently running instance of Code::Blocks
 +
 
 +
<code>$(DATAPATH)</code>, <code>$(DATA_PATH)</code>, <code>$(DATA-PATH)</code>
 +
:The 'shared' directory of the currently running instance of Code::Blocks
 +
 
 +
<code>$(PLUGINS)</code>
 +
:The 'plugins' directory of the currently running instance of Code::Blocks
 +
 
 +
<code>$(TARGET_COMPILER_DIR)</code>
 +
:The compiler installation directory so-called master path.
 +
 
 +
=== Build targets ===
 +
replace ''FOOBAR'' with the target name
 +
 
 +
<code>$(FOOBAR_OUTPUT_FILE)</code>
 +
:A ''specific'' target's output file.
 +
 
 +
<code>$(FOOBAR_OUTPUT_DIR)</code>
 +
:A ''specific'' target's output directory.
 +
 
 +
<code>$(FOOBAR_OUTPUT_BASENAME)</code>
 +
:A ''specific'' target's output file's base name (no path, no extension).
 +
 
 +
<code>$(FOOBAR_PARAMETERS)</code>
 +
:A ''specific'' target's execution parameters
 +
 
 +
<code>$(TARGET_OUTPUT_DIR)</code>
 +
:The ''current'' target's output directory.
 +
 
 +
<code>$(TARGET_OBJECT_DIR)</code>
 +
:The ''current'' target's object directory.
 +
 
 +
<code>$(TARGET_NAME)</code>
 +
:The ''current'' target's name.
 +
 
 +
<code>$(TARGET_OUTPUT_FILE)</code>
 +
:The ''current'' target's output file.
 +
 
 +
<code>$(TARGET_OUTPUT_FILENAME)</code>
 +
:The ''current'' target's output filename.
 +
 
 +
<code>$(TARGET_OUTPUT_BASENAME)</code>
 +
:The ''current'' target's output file's base name (no path, no extension).
 +
 
 +
<code>$(TARGET_CC), $(TARGET_CPP), $(TARGET_LD), $(TARGET_LIB)</code>
 +
:The ''current'' target's build tool executable (compiler, linker, etc).
 +
 
 +
<code>$(TARGET_COMPILER_DIR)</code>
 +
:The ''current'' target's build tool directory (compiler, linker, etc).
 +
 
 +
=== Language and encoding ===
 +
 
 +
<code>$(LANGUAGE)</code>
 +
:The system language in human readable form.
 +
 
 +
<code>$(ENCODING)</code>
 +
:The character encoding in human readable form.
 +
 
 +
=== Time and date ===
 +
 
 +
<code>$(TDAY)</code>
 +
:Current date in the form <code>YYYYMMDD</code> (for example 20051228)
 +
 
 +
<code>$(TODAY)</code>
 +
:Current date in the form <code>YYYY-MM-DD</code> (for example 2005-12-28)
 +
 
 +
<code>$(NOW)</code>
 +
:Timestamp in the form <code>YYYY-MM-DD-hh.mm</code> (for example 2005-12-28-07.15)
 +
 
 +
<code>$(NOW_L)</code>
 +
:Timestamp in the form <code>YYYY-MM-DD-hh.mm.ss</code> (for example 2005-12-28-07.15.45)
 +
 
 +
<code>$(WEEKDAY)</code>
 +
:Human-readable day of the week (for example "Wednesday")
 +
 
 +
<code>$(TDAY_UTC)</code>, <code>$(TODAY_UTC)</code>, <code>$(NOW_UTC)</code>, <code>$(NOW_L_UTC)</code>, <code>$(WEEKDAY_UTC)</code>
 +
:These are identical to the preceding types, but are expressed relative to UTC.
 +
 
 +
<code>$(DAYCOUNT)</code>
 +
:The number of the days passed since an arbitrarily chosen day zero (January 1, 2010). Useful as last component of a version/build number.
 +
 
 +
=== Platform dependence ===
 +
<code>$(PLATFORM)</code>
 +
: Expands to <code>msw</code> on windows and <code>unix</code> on linux and mac (Since revision r11793)
 +
 
 +
=== Command line expansions ===
 +
This commands can be used in the command line for the specific platform.
 +
 
 +
<code>$CMD_CP</code>
 +
:Will expand to a copy command for the specific platform. (on windows <code>copy</code> and on unix <code>cp --preserve=timestamps</code>)
 +
 
 +
<code>$CMD_RM</code>
 +
:delete command
 +
 
 +
<code>$CMD_MV</code>
 +
:move command
 +
 
 +
<code>$CMD_NULL</code>
 +
:NULL device (for redirecting streams)
 +
 
 +
<code>$CMD_MKDIR</code>
 +
:create a directory
 +
 
 +
<code>$CMD_RMDIR</code>
 +
:delete a directory
 +
 
 +
=== Random values ===
 +
 
 +
<code>$(COIN)</code>
 +
:This variable tosses a virtual coin (once per invokation) and returns 0 or 1.
 +
 
 +
<code>$(RANDOM)</code>
 +
:A 16bit positive random number (0-65535)
  
<tt>$(PROJECT_NAME)</tt><br/>
+
=== Standard path ===
The name of the currently compiling project.
+
<code>$(GET_DATA_DIR)</code>
 +
:Unix: prefix/share/appname  Windows: EXE path
  
<tt>$(PROJECT_DIR) $(PROJECTDIR) $(PROJECT_DIRECTORY)</tt><br/>
+
<code>$(GET_LOCAL_DATA_DIR)</code>
The common top-level directory of the currently compiling project.
+
:Unix: /etc/appname  Windows: EXE path
  
<tt>$(CODEBLOCKS) $(APP_PATH)  $(APPPATH) $(APP-PATH)</tt><br/>
+
<code>$(GET_DOCUMENTS_DIR)</code>
The path to the currently running instance of Code::Blocks
+
:Unix: ~  Windows: C:\Documents and Settings\username\Documents
  
<tt>$(DATAPATH) $(DATA_PATH) $(DATA-PATH)</tt><br/>
+
<code>$(GET_CONFIG_DIR)</code>
The 'shared' folder of the currently running instance of Code::Blocks
+
:Unix: /etc  Windows: C:\Documents and Settings\All Users\Application Data
  
<tt>$(PLUGINS)</tt><br/>
+
<code>$(GET_USER_CONFIG_DIR)</code>
The plugins folder of the currently running instance of Code::Blocks
+
:Unix: ~  Windows: C:\Documents and Settings\username\Application Data\appname
  
<tt>$(ACTIVE_EDITOR_FILENAME)</tt><br/>
+
<code>$(GET_USER_DATA_DIR)</code>
The filename of the file opened in the currently active editor.
+
:Unix: ~/.appname  Windows: C:\Documents and Settings\username\Application Data
  
<tt>$(ALL_PROJECT_FILES)</tt><br/>
+
<code>$(GET_USER_LOCAL_DATA_DIR)</code>
A string containing the names of all files in the current project.
+
:Unix: ~/.appname  Windows: C:\Documents and Settings\username\Local Settings\Application Data\appname
  
<tt>$(MAKEFILE)</tt><br/>
+
<code>$(GET_TEMP_DIR)</code>
The filename of the makefile.
+
:ALL platforms: A writable, temporary directory
  
<tt>$(FOOBAR_OUTPUT_FILE)</tt><br/>
+
== Build in functions for path conversion==
A ''specific'' target's output file.
+
There are build in macro functions to simplify path generation
  
<tt>$(FOOBAR_OUTPUT_DIR)</tt><br/>
 
A ''specific'' target's output directory.
 
  
<tt>$(TARGET_OUTPUT_DIR)</tt><br/>
+
<code>$TO_UNIX_PATH{}</code>
The ''current'' target's output directory.
+
:convert path to unix path (use '/' as separator)
  
<tt>$(TARGET_NAME)</tt><br/>
+
<code>$TO_WINDOWS_PATH{}</code>
The ''current'' target's name.
+
:convert path to windows  (use '\' as separator)
  
<tt>$(LANGUAGE)</tt><br/>
+
<code>$TO_NATIVE_PATH{}</code>
The system language in human readable form.
+
:convert to native path form the codeblocks instance is running on
  
<tt>$(ENCODING)</tt><br/>
+
=== Usage ===
The character encoding in human readable form.
 
  
<tt>$(ACTIVE_EDITOR_FILENAME)<br />$(ACTIVE_EDITOR_DIRNAME) $(ACTIVE_EDITOR_STEM) $(ACTIVE_EDITOR_EXT)</tt><br/>
+
<code>
The filename of the file being open in the active editor, its containing directory (relative to the common toplevel path), its base name (without extension), and its extension.
+
$TO_UNIX_PATH{$(TARGET_OUTPUT_FILE)}
 +
</code>
 +
:returns the current target output file as unix path
  
<tt>$(TDAY)</tt><br/>
+
== Conditional Evaluation ==
Current date in the form 20051228
 
  
<tt>$(TODAY)</tt><br/>
+
<code>$if(condition){true clause}{false clause}</code>
Current date in the form 2005-12-28
+
:Conditional evaluation will resolve to its <tt>true clause</tt> if
 +
::<tt>condition</tt> is a non-empty character sequence other than <tt>0</tt> or <tt>false</tt>
 +
::<tt>condition</tt> is a non-empty variable that does not resolve to <tt>0</tt> or <tt>false</tt>
 +
::<tt>condition</tt> is a variable that evaluates to <tt>true</tt> (implicit by previous condition)
 +
:Conditional evaluation will resolve to its <tt>false clause</tt> if
 +
::<tt>condition</tt> is empty
 +
::<tt>condition</tt> is <tt>0</tt> or <tt>false</tt>
 +
::<tt>condition</tt> is a variable that is empty or evaluates to <tt>0</tt> or <tt>false</tt>
  
<tt>$(NOW)</tt><br/>
+
Please do note that neither the variable syntax variants <tt>%if(...)</tt> nor <tt>$(if)(...)</tt> are supported for this construct.
Timestamp in the form 2005-12-28-07.15
 
  
<tt>$(NOW_L)</tt><br/>
+
== Script expansion ==
Timestamp in the form 2005-12-28-07.15.45
 
  
<tt>$(WEEKDAY)</tt><br/>
+
:For maximum flexibility, you can embed scripts using the <tt>[[</tt> <tt>]]</tt> operator as a special case of variable expansion. Embedded scripts have access to all standard functionality available to scrips and work pretty much like <tt>bash</tt> backticks (except for having access to Code::Blocks' namespace). As such, scripts are not limited to producing text output, but can also manipulate Code::Blocks state (projects, targets, etc.). Although this is technically possible, it is generally bad design and a very stupid idea to do so. Manipulating Code::Blocks state from a pre-build script is a much better solution.<br/>
Human-readable day of the week ("Wednesday")
 
  
<tt>$(TDAY_UTC) $(TODAY_UTC) $(NOW_UTC)</tt><br/>
+
:The script text is replaced with any output generated by your script, or discarded in case of a syntax error.
<tt>$(NOW_L_UTC) $(WEEKDAY_UTC)</tt><br/>
 
These are identical to the preceding types, but are expressed relative to UTC.
 
  
<tt>$(COIN)</tt><br/>
+
:As conditional evaluation runs prior to expanding scripts, conditional evaluation can be used for preprocessor functionality. Builtin variables (and user variables) are expanded after scripts, so it is possible to reference variables in a script's output.
This variable tosses a virtual coin (once per invokation) and returns 0 or 1.
 
  
<tt>$(RANDOM)</tt><br/>
+
:<u>Example:</u><br/>
A 16bit positive random number (0-65535)
+
:<tt><nowiki>[[ print(GetProjectManager().GetActiveProject().GetTitle()); ]]</nowiki></tt><br/>
 +
:inserts the active project's title into the command line.

Latest revision as of 21:53, 18 July 2019


Syntax

Code::Blocks treats the following functionally identical character sequences inside pre-build, post-build, or build steps as variables:

  • $VARIABLE
  • $(VARIABLE)
  • ${VARIABLE}
  • %VARIABLE%

Variable names must consist of alphanumeric characters and are not case-sensitive. Variables starting with a single hash sign (#) are interpreted as global compiler variables. The names listed below are interpreted as builtin types.

Variables which are neither global user variables nor builtin types are replaced with a value provided in the project file, or with an environment variable if the latter should fail.

The use of these variables can follow the following example for the date :

#include "include/manager.h"

wxString strdate = Manager::Get()->GetMacrosManager()->ReplaceMacros(_T("$TODAY"));

Per-target definitions have precedence over per-project definitions.

Buildin variable expansion is much like pre-defined macro expansion in C preprocessor as it will be text replaced when processed.

List of available builtins

Code::Blocks workspace

$(WORKSPACE_FILENAME), $(WORKSPACE_FILE_NAME), $(WORKSPACEFILE), $(WORKSPACEFILENAME)

The filename of the current workspace project (.workspace).

$(WORKSPACENAME), $(WORKSPACE_NAME)

The name of the workspace that is displayed in the tab Projects of the Management panel.

$(WORKSPACE_DIR), $(WORKSPACE_DIRECTORY), $(WORKSPACEDIR), $(WORKSPACEDIRECTORY)

The location of the workspace directory.

Files and directories

$(PROJECT_FILENAME), $(PROJECT_FILE), $(PROJECTFILE), $(PROJECTFILENAME), $(PROJECT_FILE_NAME)

The filename of the currently compiling project.

$(PROJECT_NAME), $(PROJECTNAME)

The name of the currently compiling project.

$(PROJECT_DIR), $(PROJECTDIR), $(PROJECT_DIRECTORY), $(PROJECTDIRECTORY)

The common directory of the currently compiling project.

$(PROJECTTOPDIR), $(PROJECT_TOPDIR), $(PROJECTTOPDIRECTORY), $(PROJECT_TOPDIRECTORY)

The common top-directory of the currently compiling project.

$(ACTIVE_EDITOR_FILENAME)

The filename of the file opened in the currently active editor.

$(ACTIVE_EDITOR_LINE)

Return the current line in the active editor.

$(ACTIVE_EDITOR_COLUMN)

Return the column of the current line in the active editor.

$(ACTIVE_EDITOR_DIRNAME)

Currently active file's containing directory (relative to the common top level path)

$(ACTIVE_EDITOR_STEM)

Currently active file's base name (without extension).

$(ACTIVE_EDITOR_EXT)

Currently active file's extension.

$(ACTIVE_EDITOR_SELECTION)

Currently selected text from active editor.

$(ALL_PROJECT_FILES)

A string containing the names of all files in the current project.

$(MAKEFILE)

The filename of the makefile.

$(CODEBLOCKS), $(APP_PATH), $(APPPATH), $(APP-PATH)

The path to the currently running instance of Code::Blocks

$(DATAPATH), $(DATA_PATH), $(DATA-PATH)

The 'shared' directory of the currently running instance of Code::Blocks

$(PLUGINS)

The 'plugins' directory of the currently running instance of Code::Blocks

$(TARGET_COMPILER_DIR)

The compiler installation directory so-called master path.

Build targets

replace FOOBAR with the target name

$(FOOBAR_OUTPUT_FILE)

A specific target's output file.

$(FOOBAR_OUTPUT_DIR)

A specific target's output directory.

$(FOOBAR_OUTPUT_BASENAME)

A specific target's output file's base name (no path, no extension).

$(FOOBAR_PARAMETERS)

A specific target's execution parameters

$(TARGET_OUTPUT_DIR)

The current target's output directory.

$(TARGET_OBJECT_DIR)

The current target's object directory.

$(TARGET_NAME)

The current target's name.

$(TARGET_OUTPUT_FILE)

The current target's output file.

$(TARGET_OUTPUT_FILENAME)

The current target's output filename.

$(TARGET_OUTPUT_BASENAME)

The current target's output file's base name (no path, no extension).

$(TARGET_CC), $(TARGET_CPP), $(TARGET_LD), $(TARGET_LIB)

The current target's build tool executable (compiler, linker, etc).

$(TARGET_COMPILER_DIR)

The current target's build tool directory (compiler, linker, etc).

Language and encoding

$(LANGUAGE)

The system language in human readable form.

$(ENCODING)

The character encoding in human readable form.

Time and date

$(TDAY)

Current date in the form YYYYMMDD (for example 20051228)

$(TODAY)

Current date in the form YYYY-MM-DD (for example 2005-12-28)

$(NOW)

Timestamp in the form YYYY-MM-DD-hh.mm (for example 2005-12-28-07.15)

$(NOW_L)

Timestamp in the form YYYY-MM-DD-hh.mm.ss (for example 2005-12-28-07.15.45)

$(WEEKDAY)

Human-readable day of the week (for example "Wednesday")

$(TDAY_UTC), $(TODAY_UTC), $(NOW_UTC), $(NOW_L_UTC), $(WEEKDAY_UTC)

These are identical to the preceding types, but are expressed relative to UTC.

$(DAYCOUNT)

The number of the days passed since an arbitrarily chosen day zero (January 1, 2010). Useful as last component of a version/build number.

Platform dependence

$(PLATFORM)

Expands to msw on windows and unix on linux and mac (Since revision r11793)

Command line expansions

This commands can be used in the command line for the specific platform.

$CMD_CP

Will expand to a copy command for the specific platform. (on windows copy and on unix cp --preserve=timestamps)

$CMD_RM

delete command

$CMD_MV

move command

$CMD_NULL

NULL device (for redirecting streams)

$CMD_MKDIR

create a directory

$CMD_RMDIR

delete a directory

Random values

$(COIN)

This variable tosses a virtual coin (once per invokation) and returns 0 or 1.

$(RANDOM)

A 16bit positive random number (0-65535)

Standard path

$(GET_DATA_DIR)

Unix: prefix/share/appname Windows: EXE path

$(GET_LOCAL_DATA_DIR)

Unix: /etc/appname Windows: EXE path

$(GET_DOCUMENTS_DIR)

Unix: ~ Windows: C:\Documents and Settings\username\Documents

$(GET_CONFIG_DIR)

Unix: /etc Windows: C:\Documents and Settings\All Users\Application Data

$(GET_USER_CONFIG_DIR)

Unix: ~ Windows: C:\Documents and Settings\username\Application Data\appname

$(GET_USER_DATA_DIR)

Unix: ~/.appname Windows: C:\Documents and Settings\username\Application Data

$(GET_USER_LOCAL_DATA_DIR)

Unix: ~/.appname Windows: C:\Documents and Settings\username\Local Settings\Application Data\appname

$(GET_TEMP_DIR)

ALL platforms: A writable, temporary directory

Build in functions for path conversion

There are build in macro functions to simplify path generation


$TO_UNIX_PATH{}

convert path to unix path (use '/' as separator)

$TO_WINDOWS_PATH{}

convert path to windows (use '\' as separator)

$TO_NATIVE_PATH{}

convert to native path form the codeblocks instance is running on

Usage

$TO_UNIX_PATH{$(TARGET_OUTPUT_FILE)}

returns the current target output file as unix path

Conditional Evaluation

$if(condition){true clause}{false clause}

Conditional evaluation will resolve to its true clause if
condition is a non-empty character sequence other than 0 or false
condition is a non-empty variable that does not resolve to 0 or false
condition is a variable that evaluates to true (implicit by previous condition)
Conditional evaluation will resolve to its false clause if
condition is empty
condition is 0 or false
condition is a variable that is empty or evaluates to 0 or false

Please do note that neither the variable syntax variants %if(...) nor $(if)(...) are supported for this construct.

Script expansion

For maximum flexibility, you can embed scripts using the [[ ]] operator as a special case of variable expansion. Embedded scripts have access to all standard functionality available to scrips and work pretty much like bash backticks (except for having access to Code::Blocks' namespace). As such, scripts are not limited to producing text output, but can also manipulate Code::Blocks state (projects, targets, etc.). Although this is technically possible, it is generally bad design and a very stupid idea to do so. Manipulating Code::Blocks state from a pre-build script is a much better solution.
The script text is replaced with any output generated by your script, or discarded in case of a syntax error.
As conditional evaluation runs prior to expanding scripts, conditional evaluation can be used for preprocessor functionality. Builtin variables (and user variables) are expanded after scripts, so it is possible to reference variables in a script's output.
Example:
[[ print(GetProjectManager().GetActiveProject().GetTitle()); ]]
inserts the active project's title into the command line.