Macros
From this content, you will understand the order of precedence of macros in a clearmake build, and the different types of macros.
The following sections describe the order of precedence of macros in a clearmake build, and the different types of macros.
Order of precedence of make macros and environment variables
By default, the order of precedence of macros and environment variables is as follows:
- Target-dependent macro definitions
- Macros specified on the clearmake command line
- Make macros set in a BOS file
- Make macro definitions in a makefile
- Environment variables
For example, target-dependent macro definitions override all other macro definitions, and macros specified on the clearmake command line override those set in a BOS file.
If you use the -e option to clearmake, environment variables override macro definitions in the makefile.
All BOS file macros (except those overridden on the command line) are placed in the environment of a build script. If a build script recursively starts clearmake:
- The higher-level BOS file setting (now transformed into an EV) is overridden by a make macro set in the lower-level makefile. However, if the recursive invocation uses the -e option of clearmake, the BOS file setting prevails.
- If another BOS file (associated with another makefile) is read at the lower level, its make macros override those from the higher-level BOS file.
For a list of all environment variables, see the env_ccase reference page.
Make macros
A macro definition takes this form:
macro_name= string
Macros can appear in the makefile, on the command line, or in a build options specification file. (For more information, see Build options specification files.)
Macro definitions require no quotes or delimiters, except for the equal sign
(=
), which separates the macro name from the value. Leading and trailing
white-space characters are stripped. Lines can be continued using a \<NL> sequence; this
sequence and all surrounding white space are effectively converted to a single <SPACE>
character. macro_name
cannot include white space, but the
string
can; it includes all characters up to an unescaped <NL>
character.
clearmake performs macro substitution whenever it encounters either of the following in the makefile:
$(macro_name)
$(macro_name:subst1=subst2)
It substitutes the string
for the macro invocation. In the latter form,
clearmake performs an additional substitution within the
string
: all occurrences of subst1
at the end of a word
within the string
are replaced by subst2
. If
subst1
is empty, subst2
is appended to each word in the
value of macro_name
. If subst2
is empty,
subst1
is removed from each word in the value of
macro_name
.
For example:
z:\myvob> type Makefile
C_SOURCES = one.c two.c three.c four.c
test:
echo OBJECT FILES are: $(C_SOURCES:.c=.obj)
echo EXECUTABLES are: $(C_SOURCES:.c=.exe)
z:\myvob> clearmake test
OBJECT FILES are: one.obj two.obj three.obj four.obj
EXECUTABLES are: one.exe two.exe three.exe four.exe
Internal macros
clearmake maintains these macros internally. They are useful in rules for building targets.
- $*
- (Defined only for inference rules) The file name part of the inferred dependency, with the file name extension deleted.
- $@
- The full target name of the current target.
- $<
- (Defined only for inference rules) The file name of the implicit dependency.
- $?
- (Defined only when explicit rules from the makefile are evaluated) The list of
dependencies that are out of date with respect to the target. When configuration lookup
is enabled (default), it expands to the list of all dependencies, unless that behavior
is modified with the
.INCREMENTAL_TARGET
special target. In that case,$?
expands to the list of all dependencies different from the previously recorded versions.When a dependency is an archive library member of the form
lib(file.obj)
, the name of the member,file.obj
, appears in the list. - $%
- (Defined only when the target is an archive library member) For a target of the form
lib(file.obj)
,$@
evaluates to lib and$%
evaluates to the library member,file.obj.
- MAKE
- The name of the make processor (that is, clearmake). This macro is useful for the recursive invocation of clearmake.
- MAKEFILE
- During makefile parsing, this macro expands to the path name of the current makefile.
After makefile parsing is complete, it expands to the path name of the last makefile
that was parsed. This holds only for top-level makefiles, not for included makefiles or
for built-in rules; in these cases, it echoes the name of the including makefile.
Use this macro as an explicit dependency to include the version of the makefile in the CR produced by a target rebuild. For example:
supersort: main.obj sort.obj cmd.obj $(MAKEFILE)
link /out:$@ $?
For more information, see Including a makefile version in a configuration record.
- MAKEFLAGS
- This macro passes flags to sub-makes, including flags that take arguments and macro
definitions. clearmake reads the contents of MAKEFLAGS at startup and
amends it to include any flags not specific to HCL
VersionVault passed at the command line.
Any flags specific to HCL
VersionVault
are passed through CCASE_MAKEFLAGS and if clearmake detects these
flags in MAKEFLAGS, it moves them to CCASE_MAKEFLAGS. You can use the CCASE_MAKEFLAGS
environment variable as an alternative mechanism for specifying
clearmake commands. CCASE_MAKEFLAGS allows
clearmake to be used in recursive builds that use both
clearmake and native makefile programs. Options of the
clearmake command line override the CCASE_MAKEFLAGS environment
variable.
Flags passed through MAKEFLAGS:
-I, -p, -N, -w, -e, -r, -i, -k, -n, -q, -s
Flags passed through CCASE_MAKEFLAGS:
-A, -B, -N, -b, -v, -C, -U, -M, -V, -O, -T, -F, -R, -c, -u, -d
This functionality is available for all compatibility modes.
VPATH macro
The VPATH
macro specifies a search path for targets and dependencies.
clearmake searches directories in VPATH
when it fails
to find a target or dependency in the current working directory.
clearmake searches only in the current view. The value of
VPATH
can be one directory path name, or a semicolon-separated list of
directory path names. (In Gnu compatibility mode, you can also use spaces as
separators.)
As clearmake qualifies makefile dependencies (explicit dependencies in
the makefile), the process of configuration lookup is VPATH
-sensitive.
Thus, if a newer version of a dependent file appears in a directory on the search path
before the path name in the CR (the version used in the previous build),
clearmake rejects the previous build and rebuilds the target with the
new file.
The VPATH
setting might affect the expansion of internal macros, such as
$<
.