Internal macros

The make command has built-in macro definitions for use in the description file.

These macros help specify variables in the description file. The make command replaces the macros with one of the following values:

Macro Value
$@ Name of the current target file
$$@ Label name on the dependency line
$? Names of the files that have changed more recently than the target
$< Parent file name of the out-of-date file that caused a target file to be created
$* Name of the current parent file without the suffix
$% Name of an archive library member

Target file name

If the $@ macro is in the command sequence in the description file, the make command replaces the symbol with the full name of the current target file before passing the command to the shell to be run. The make command replaces the symbol only when it runs commands from the description file to create the target file.

Label name

If the $$@ macro is on the dependency line in a description file, the make command replaces this symbol with the label name that is on the left side of the colon in the dependency line. For example, if the following is included on a dependency line:

cat:     $$@.c

The make command translates it to:

cat:     cat.c

when the make command evaluates the expression. Use this macro to build a group of files, each of which has only one source file. For example, to maintain a directory of system commands, use a description file similar to:

# Define macro CMDS as a series
# of command names
CMDS = cat dd echo date cc cmp comm ar ld chown
# Each command depends on a .c file
$(CMDS):      $$@.c
# Create the new command set by compiling the out of
# date files ($?) to the target file name ($@)
         $(CC) -O $? -o $@

The make command changes the $$(@F) macro to the file part of $@ when it runs. For example, use this symbol when maintaining the usr/include directory while using a description file in another directory. That description file is similar to the following:

# Define directory name macro INCDIR
INCDIR = /usr/include
# Define a group of files in the directory
# with the macro name INCLUDES
INCLUDES = \
         $(INCDIR)/stdio.h \
         $(INCDIR)/pwd.h \
         $(INCDIR)/dir.h \
         $(INCDIR)/a.out.h \
# Each file in the list depends on a file
# of the same name in the current directory
$(INCLUDES):       $$(@F)
# Copy the younger files from the current
# directory to /usr/include
         cp $? $@
# Set the target files to read only status
         chmod 0444 $@

The preceding description file creates a file in the /usr/include directory when the corresponding file in the current directory has been changed.

Changed Files

If the $? macro is in the command sequence in the description file, the make command replaces the symbol with a list of parent files that have been changed since the target file was last changed. The make command replaces the symbol only when it runs commands from the description file to create the target file.

First out-of-date file

If the $< macro is in the command sequence in the description file, the make command replaces the symbol with the name of the file that started the file creation. The Out-of-Date file name is the name of the parent file whose timestamp did not match the timestamp of the target file, and therefore caused the make command to create the target file again.

In addition, use a letter (D or F) after the < (less-than sign) to get either the directory name (D) or the file name (F) of the first out-of-date file. For example, if the first out-of-date file is:

/home/linda/sample.c

then the make command gives the following values:

$(<D)   =   /home/linda
$(<F)   =   sample.c
$<      =   /home/linda/sample.c

The make command replaces this symbol only when the program runs commands from its internal rules or from the .DEFAULT list.

Current file-name prefix

If the $* macro is in the command sequence in the description file, the make command replaces the symbol with the file-name part (without the suffix) of the parent file that the make command is currently using to generate the target file. For example, if the make command is using the file:

test.c

then the $* macro represents the file name test.

In addition, use a letter (D or F) after the * (asterisk) to get either the directory name (D) or the file name (F) of the current file.

For example, the make command uses many files (specified either in the description file or in the internal rules) to create a target file. Only one of those files (the current file) is used at any moment. If that current file is:

/home/tom/sample.c

then the make command gives the following values for the macros:

$(*D)  =  /home/tom
$(*F)  =  sample
$*     =  /home/tom/sample

The make command replaces this symbol only when running commands from its internal rules (or from the .DEFAULT list), but not when running commands from a description file.

Archive library member

If the $% macro is in a description file, and the target file is an archive library member, the make command replaces the macro symbol with the name of the library member. For example, if the target file is:

lib(file.o)

then themake command replaces the $% macro with the member name file.o.