Difference between revisions of "Variable expansion"

From Code::Blocks
m (edit category)
(wikify; create separate categories)
Line 1: Line 1:
 
[[Category:User Documentation]]
 
[[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 user 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.
+
 
 +
'''Per-target definitions have precedence over per-project definitions.'''
  
 
== List of available builtins ==
 
== List of available builtins ==
  
<tt>$(PROJECT_FILENAME) $(PROJECT_FILE) $(PROJECTFILE)</tt><br/>
+
=== Files and directories ===
The filename of the currently compiling project.
+
 
 +
<code>$(PROJECT_FILENAME)</code>, <code>$(PROJECT_FILE)</code>, <code>$(PROJECTFILE)</code>
 +
:The filename of the currently compiling project.
 +
 
 +
<code>$(PROJECT_NAME)</code>
 +
:The name of the currently compiling project.
 +
 
 +
<code>$(PROJECT_DIR)</code>, <code>$(PROJECTDIR)</code>, <code>$(PROJECT_DIRECTORY)</code>
 +
:The common top-level 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_FILENAME)</code>, <code>$(ACTIVE_EDITOR_DIRNAME)</code>, <code>$(ACTIVE_EDITOR_STEM)</code>, <code>$(ACTIVE_EDITOR_EXT)</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.
  
<tt>$(PROJECT_NAME)</tt><br/>
+
<code>$(ALL_PROJECT_FILES)</code>
The name of the currently compiling project.
+
:A string containing the names of all files in the current project.
  
<tt>$(PROJECT_DIR) $(PROJECTDIR) $(PROJECT_DIRECTORY)</tt><br/>
+
<code>$(MAKEFILE)</code>
The common top-level directory of the currently compiling project.
+
:The filename of the makefile.
  
<tt>$(CODEBLOCKS) $(APP_PATH) $(APPPATH) $(APP-PATH)</tt><br/>
+
<code>$(CODEBLOCKS)</code>, <code>$(APP_PATH)</code>, <code>$(APPPATH)</code>, <code>$(APP-PATH)</code>
The path to the currently running instance of Code::Blocks
+
:The path to the currently running instance of Code::Blocks
  
<tt>$(DATAPATH) $(DATA_PATH) $(DATA-PATH)</tt><br/>
+
<code>$(DATAPATH)</code>, <code>$(DATA_PATH)</code>, <code>$(DATA-PATH)</code>
The 'shared' folder of the currently running instance of Code::Blocks
+
:The 'shared' directory of the currently running instance of Code::Blocks
  
<tt>$(PLUGINS)</tt><br/>
+
<code>$(PLUGINS)</code>
The plugins folder of the currently running instance of Code::Blocks
+
:The 'plugins' directory of the currently running instance of Code::Blocks
  
<tt>$(ACTIVE_EDITOR_FILENAME)</tt><br/>
+
=== Build targets ===
The filename of the file opened in the currently active editor.
 
  
<tt>$(ALL_PROJECT_FILES)</tt><br/>
+
<code>$(FOOBAR_OUTPUT_FILE)</code>
A string containing the names of all files in the current project.
+
:A ''specific'' target's output file.
  
<tt>$(MAKEFILE)</tt><br/>
+
<code>$(FOOBAR_OUTPUT_DIR)</code>
The filename of the makefile.
+
:A ''specific'' target's output directory.
  
<tt>$(FOOBAR_OUTPUT_FILE)</tt><br/>
+
<code>$(TARGET_OUTPUT_DIR)</code>
A ''specific'' target's output file.
+
:The ''current'' target's output directory.
  
<tt>$(FOOBAR_OUTPUT_DIR)</tt><br/>
+
<code>$(TARGET_NAME)</code>
A ''specific'' target's output directory.
+
:The ''current'' target's name.
  
<tt>$(TARGET_OUTPUT_DIR)</tt><br/>
+
=== Language and encoding ===
The ''current'' target's output directory.
 
  
<tt>$(TARGET_NAME)</tt><br/>
+
<code>$(LANGUAGE)</code>
The ''current'' target's name.
+
:The system language in human readable form.
  
<tt>$(LANGUAGE)</tt><br/>
+
<code>$(ENCODING)</code>
The system language in human readable form.
+
:The character encoding in human readable form.
  
<tt>$(ENCODING)</tt><br/>
+
=== Time and date ===
The character encoding in human readable form.
 
  
<tt>$(ACTIVE_EDITOR_FILENAME)<br />$(ACTIVE_EDITOR_DIRNAME) $(ACTIVE_EDITOR_STEM) $(ACTIVE_EDITOR_EXT)</tt><br/>
+
<code>$(TDAY)</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.
+
:Current date in the form <code>YYYYMMDD</code> (for example 20051228)
  
<tt>$(TDAY)</tt><br/>
+
<code>$(TODAY)</code>
Current date in the form 20051228
+
:Current date in the form <code>YYYY-MM-DD</code> (for example 2005-12-28)
  
<tt>$(TODAY)</tt><br/>
+
<code>$(NOW)</code>
Current date in the form 2005-12-28
+
:Timestamp in the form <code>YYYY-MM-DD-hh.mm</code> (for example 2005-12-28-07.15)
  
<tt>$(NOW)</tt><br/>
+
<code>$(NOW_L)</code>
Timestamp in the form 2005-12-28-07.15
+
:Timestamp in the form <code>YYYY-MM-DD-hh.mm.ss</code> (for example 2005-12-28-07.15.45)
  
<tt>$(NOW_L)</tt><br/>
+
<code>$(WEEKDAY)</code>
Timestamp in the form 2005-12-28-07.15.45
+
:Human-readable day of the week (for example "Wednesday")
  
<tt>$(WEEKDAY)</tt><br/>
+
<code>$(TDAY_UTC)</code>, <code>$(TODAY_UTC)</code>, <code>$(NOW_UTC)</code>, <code>$(NOW_L_UTC)</code>, <code>$(WEEKDAY_UTC)</code>
Human-readable day of the week ("Wednesday")
+
:These are identical to the preceding types, but are expressed relative to UTC.
  
<tt>$(TDAY_UTC) $(TODAY_UTC) $(NOW_UTC)</tt><br/>
+
=== Random values ===
<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/>
+
<code>$(COIN)</code>
This variable tosses a virtual coin (once per invokation) and returns 0 or 1.
+
:This variable tosses a virtual coin (once per invokation) and returns 0 or 1.
  
<tt>$(RANDOM)</tt><br/>
+
<code>$(RANDOM)</code>
A 16bit positive random number (0-65535)
+
:A 16bit positive random number (0-65535)

Revision as of 10:50, 10 July 2006


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 user 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.

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

List of available builtins

Files and directories

$(PROJECT_FILENAME), $(PROJECT_FILE), $(PROJECTFILE)

The filename of the currently compiling project.

$(PROJECT_NAME)

The name of the currently compiling project.

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

The common top-level directory of the currently compiling project.

$(ACTIVE_EDITOR_FILENAME)

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

$(ACTIVE_EDITOR_FILENAME), $(ACTIVE_EDITOR_DIRNAME), $(ACTIVE_EDITOR_STEM), $(ACTIVE_EDITOR_EXT)

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.

$(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

Build targets

$(FOOBAR_OUTPUT_FILE)

A specific target's output file.

$(FOOBAR_OUTPUT_DIR)

A specific target's output directory.

$(TARGET_OUTPUT_DIR)

The current target's output directory.

$(TARGET_NAME)

The current target's name.

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.

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)