#if (!$singlePage) --- layout: documentation title: Make Variables --- #end #if (!$singlePage) #parse("com/google/devtools/build/docgen/templates/be/header.vm") #end

"Make" Variables

#if (!$singlePage)
#end

This section describes how to use a special class of built-in string variables that are called the "Make" environment. Defining custom "Make" variables is not supported.

(The reason for the term "Make" is historical: the syntax and semantics of these variables are somewhat similar to those of GNU Make.)

To see the list of all common "Make" variables and their values, run bazel info --show_make_env.

Build rules can introduce additional rule specific variables. One example is the cmd attribute of a genrule.

"Make" variable substitution

Variables can be referenced in attributes using $(FOO) where FOO is the variable name. In the attribute documentation of rules, it is mentioned when an attribute is subject to "Make" variable substitution. For those attributes this means that any substrings of the form $(X) within those attributes will be interpreted as references to the "Make" variable X, and will be replaced by the appropriate value of that variable for the applicable build configuration. The parens may be omitted for variables whose name is a single character.

It is an error if such attributes contain embedded strings of the form $(X) where X is not the name of a "Make" variable, or unclosed references such as $( not matched by a corresponding ).

Within such attributes, literal dollar signs must be escaped as $$ to prevent this expansion.

Those attributes that are subject to this substitution are explicitly indicated as such in their definitions in this document.

Predefined "Make" Variables

Bazel defines a set of "Make" variables for you.

The build system also provides a consistent PATH environment variable for genrules and tests which need to execute shell commands. For genrules, you can indirect your commands using the "Make" variables below. For basic Unix utilities, prefer relying on the PATH environment variable to guarantee correct results. For genrules involving compiler and platform invocation, you must use the "Make" variable syntax. The same basic command set is also available during tests. Simply rely on the PATH.

Compiler and Platforms available to genrules

These tools may not be in the PATH, therefore you must use "Make" variable syntax in your genrule's cmd attribute.

Tool option Variables

Path Variables

Architecture Variables

Other Variables available to the cmd attribute of a genrule

"$(location)" substitution

In attributes that support it, all occurrences of $(location label) are replaced by the path to the file denoted by label. Use location if the label outputs exactly one filename. This allows bazel to perform a check and give an error if no or more than one files are represented by the given label; a label referring to a source file always represents a single file, but a label referring to a rule refers to all output files of that rule. Otherwise use $(locations label); bazel will then raise an error if no files are generated. In both cases, if the label is malformed then an error is raised.

The label needs not be in canonical form: foo, :foo and //somepkg:foo are all fine. It may also be the name of an output file from the outs attribute.

The expanded paths are relative to the runfiles directory of the *_test or *_binary rule.

#if (!$singlePage) #parse("com/google/devtools/build/docgen/templates/be/footer.vm") #end