# Variables defined by Bakefile

Bakefile rulesets define lots of variables; this chapter provides brief summary of variables that are available for makefile writers.

## Format independent variables

### Changing Bakefile behaviour

These variables are meant to be changed using `-D` command line argument (see manual page for details).

Variable name | Description | Default
--- | --- | ---
OPTIONS_FILE | If set, then user-configurable part of generated makefile (i.e. options list) is written into another file instead that the makefile will include. `OPTIONS_FILE` value must be relative to `OUTPUT_FILE`. | (not set, empty)
WRITE_OPTIONS_FILE | If `OPTIONS_FILE` is set and `WRITE_OPTIONS_FILE` is 1, then file `OPTIONS_FILE` is created. If 0, then it is not, but it is still included by the main makefile. This allows you to generate options file shared by lots of subproject makefiles and don't repeatedly generate it. | 1

Variables for fine-tuning Bakefile's output (rarely needed):

Variable name | Description | Default
--- | --- | ---
VARS_DONT_ELIMINATE | Bakefile normally eliminates all unused variables from the output. In some rare situations, it may not detect that a variable is used, in which case you can tell it to keep the variable by adding its name to this variable. So far this is only useful if the variables is used in makefile code included using . | (empty)
LIB_PAGESIZE | Set this variable to a large power of two if your linker (on Windows) complains that page size is too small when building static library. | `4096`

### Directories

Variable name | Description | Default
--- | --- | ---
SRCDIR | Directory to which names of source files are relative to. This value is relative to (the only exception is the `autoconf` format, which prefixes the value with `$(srcdir)` in order to allow out-of-tree compilation). Note that the value of `SRCDIR` cannot be set manually; if you want to change it, you must use the `set-srcdir` command as early in your bakefile as possible. For example:
    <makefile>
      <set-srcdir>../..</set-srcdir>
      ..
    </makefile>
The argument to `set-srcdir` must be a constant expression. | .
BUILDDIR | Directory where object files and executables are built. This value is relative to . | (depends on format)

#### Installation Directories

These are standard installation directories as used on Unix (most notably in Autoconf). They are used by `install` target if the backend supports it. They are defined on all platforms. You can change their values freely (unless you are using Autoconf backend).

Variable name | Description | Default
--- | --- | ---
PREFIX | Base directory for installed files. | /usr/local on Unix
BINDIR | Directory where programs are installed. | $(PREFIX)/bin on Unix
LIBDIR | Directory where libraries are installed. | $(PREFIX)/lib on Unix
DLLDIR | Directory where DLLs are installed. | $(PREFIX)/lib on Unix, $(PREFIX)/bin when targetting win32
INCLUDEDIR | Directory where C and C++ headers are installed. | $(PREFIX)/include on Unix
DATADIR | Directory where data files are installed. | $(PREFIX)/share on Unix

### Recognizing Platform

All of these are variables defined to either 0 or 1, with the exception of `autoconf` format backend where they are options.

Variable name | Description
--- | ---
PLATFORM_UNIX | UNIX variant
PLATFORM_WIN32 | 32bit Windows
PLATFORM_MSDOS | MS-DOS
PLATFORM_MAC | Mac OS X or Mac Classic
PLATFORM_MACOSX | Mac OS X
PLATFORM_OS2 | OS/2
PLATFORM_BEOS | BeOS
PLATFORM_SYMBIAN | Symbian OS

### Format features

Variable name | Description
--- | ---
FORMAT_HAS_VARIABLES | This boolean flag indicates whether the output format supports variables. If it does, then some space and time optimization are possible and long Bakefile variables that would otherwise be expanded into literals are left as variables in generated makefile/project.
FORMAT_SUPPORTS_CONDITIONS | Whether the output format can handle conditions (i.e. variable values depending on conditions and conditionally built targets) at all. Most make-tools do, but e.g. MSVC project files can't do it. If set to 0, then the targets and variables are "flattened", i.e. expanded into multiple 'configurations' as in many IDEs.
FORMAT_SUPPORTS_CONFIGURATIONS | Whether it is at least possible to have multiple configurations if conditions are not supported (such as in IDEs). Meaningless if FORMAT_SUPPORTS_CONDITIONS=1. If both FORMAT_SUPPORTS_CONDITIONS and FORMAT_SUPPORTS_CONFIGURATIONS are 0, then we're in deep trouble and we can only generate makefiles that are not configurable.
FORMAT_SUPPORTS_ACTIONS | Whether the output format can handle s at all. Most make-tools do, but IDE project files typically don't.
FORMAT_SUPPORTS_SUBPROJECTS | Whether the output format can handle s at all. Most make-tools do, but IDE project files typically don't.
FORMAT_NEEDS_OPTION_VALUES_FOR_CONDITIONS | Whether the output format needs to have options that are used by conditions listed in the output file. This is true in majority of cases because the conditions take form such as `"!if $(OPT) == value"` and OPT must be defined, but there's one exception: autoconf. It decides on whether the condition is true or false in autoconf_inc.m4 and Makefile.in does not need the variables, so we can safely purge them and save some space.

### Miscellaneous

Variable name | Description
--- | ---
BAKEFILE_VERSION | String with Bakefile version number. The version is formed from three numbers delimined by period. Read only.
OPTIONS | Space-separation list of options defined in the makefiles. Note that the value of this variable changes during processing as new options are defined! |
INPUT_FILE | Name of input file. The name is always absolute path. Read only.
INPUT_FILE_ARG | Same as INPUT_FILE, but the name is in exactly same form as it was passed on command line, it's not made absolute as in case of `INPUT_FILE`.
OUTPUT_FILE | Name of the file where generated native makefile will be written. Read only.
FORMAT | Format of makefile currently being generated, e.g. `autoconf`. Always constant expression.
COMPILER | Short identifier of used compiler (e.g. "bcc" or "vc6"). This variable is only defined for Windows compilers and is guaranteed to evaluate to constant expression.
TOOLSET | What kind of tools the makefile uses. Use this to determine what commands to put into tags. Can be one of `win32`, `unix`. Always a constanst expression.
EOL_STYLE | Default line endings style for current format, one of `unix`, `dos` and `mac`.
LF | Line feed character (\n in C).
TAB | Tabelator character (\t in C).
DOLLAR | Dollar sign ($).
SPACE | Space character (" "). Note that `SPACE` is not evaluated and so you can't use it in places where constant expression is expected.
DIRSEP | Character used to separate directory components in paths on target platform (/ on Unix, \ on Windows).

## Standard makefile variables

Makefile-based formats (`gnu`, `msvc` etc.) define standard options `CC`, `CXX`, `CFLAGS`, `CXXFLAGS`, `CPPFLAGS`, `LDFLAGS` for specifying the compiler and its flags. Their default values are set to the default or typical compiler. If necessary, the defaults for `FOO` can be overriden by setting the `DEFAULT_FOO` (e.g. `DEFAULT_CXX` for the C++ compiler) variable to a constant value anywhere in user bakefiles.

## Format specific variables

### autoconf

Variable name | Description | Default
--- | --- | ---
AUTOCONF_MACROS_FILE | Where `configure.in` macros for setting options and conditional variables (mostly `AC_SUBST` calls) are written. This file must be included by your `configure.in` script. Set it to empty string to disable creation of this file (e.g. for subprojects of main project, see also `OPTIONS_FILE` ). Note that the value of `AUTOCONF_MACROS_FILE` shouldn't be set manually; if you want to change it, use the `autoconf-needs-macro` command. For example:
    <makefile>
      <autoconf-needs-macro>AC_BAKEFILE_PYTHON</autoconf-needs-macro>
      ..
    </makefile>
The argument to `autoconf-needs-macro` must be a constant expression. It can be repeated more than once. | autoconf_inc.m4

### dmars, dmars_smake

Variable name | Description | Default
--- | --- | ---
DMARS_MEM_POOL_SIZE | Specifies size of memory pool used by the `dmc` compiler. The default should be sufficient most of the time and only needs increasing if the compiler fails to compile source code with out of memory errors. | 99

### msvs2005prj, msvs2008prj

Variable name | Description | Default
--- | --- | ---
MSVS_PLATFORMS | Comma-separated list of platforms to generate project configurations for. Can be set by the user using the `-D` command line argument. See MS VisualStudio 2005/2008 format documentation for details. | win32
MSVS_PLATFORM | This variable is not meant to be set by the user. It's an option created by the format itself. It's allowed values are values from variable set by the user. It can be used by the bakefiles to generate different project settings for different platform, in the same way user-added options are used. |
MSVS_PROJECT_FILE | Unlike other variables in this section, this variable can optionally be set on targets to specify the location of `.vcproj` file created for them. The location is relative to . See an example:
    <exe id="hello_world">
      ...
      <!-- create subdirectory for projects if needed and put it there -->
      <set var="MSVS_PROJECT_FILE">examples/HelloWorld.vcproj</set>
    </exe>
| (derived from )

### msvs2003prj

The option is present in this format as well, but it is always set to `win32`. is fully supported.