Directives in Makefiles
Using directives, you can construct description
files similar to batch files. The Make Utility provides
directives that:
- conditionally execute commands
- display error messages
- include the contents of other files
- turn some Make Utility options on or off
Each directive begins with an exclamation point
(!) in the first column of the description file. Spaces can be
placed between the exclamation point and the directive keyword.
- !IF expression
- Executes the statements between the !IF
keyword and the next !ELSE or !ENDIF directive if expression evaluates to a nonzero value.
- !ELSE
- Executes the statements between the !ELSE
and !ENDIF directives if the statements preceding the
!ELSE directive were not executed.
- !ENDIF
- Marks the end of the !IF, !IFDEF, or
!IFNDEF block of statements.
- !IFDEF macroname
- Executes the statements between the !IFDEF
keyword and the next !ELSE or !ENDIF directive if macroname is defined in the description file. If a macro
has been defined as null, it is still considered to be
defined.
- !IFNDEF macroname
- Executes the statements between the
!IFNDEF keyword and the next !ELSE or !ENDIF directive if
macroname is not defined in the description file.
- !UNDEF macroname
- Undefines a previously defined macro.
- !ERROR text
- Prints the text and then stops execution.
- !INCLUDE filename
- Reads and evaluates the file filename before continuing with the current description
file. If filename is enclosed by angle brackets (< >), the
Make utility searches for the file in the directories
specified by the INCLUDE macro; otherwise, it looks only
in the current directory. The INCLUDE macro is initially
set to the value of the INCLUDE environment variable.
- !CMDSWITCHES {+|-} opt
- Turns on or off one of four Make options:
/d, /i, /n, and /s. If no options are specified, the
options are reset to the values they had when the Make
utility was started. To turn an option on, precede it
with a plus sign (+); to turn it off, precede it with a
minus sign (-). This directive updates the MAKEFLAGS
macro.
-
Example of Directives in a Makefile
!INCLUDE <INFRULES.TXT>
!CMDSWITCHES +D
WINNER.EXE:WINNER.OBJ
!IFDEF DEBUG
! IF "$(DEBUG)"=="Y"
LINK /CO WINNER.OBJ;
! ELSE
LINK WINNER.OBJ;
! ENDIF
!ELSE
! ERROR Macro named DEBUG is not defined.
!ENDIF
The directives in this example do the
following:
- The !INCLUDE directive causes the file
infrules.txt to be read and evaluated as if it were part
of the description file.
- The !CMDSWITCHES directive turns on the /d
option, which displays the dates of the files as they
were checked.
- If winner.exe is out-of-date with respect
to winner.obj, the !IFDEF directive checks to see whether
the macro debug is defined. If it is defined, the !IF
directive checks to see whether it is set to y. If it is,
the linker is invoked with the /CO option; otherwise, it
is invoked without the /CO. If the DEBUG macro is not
defined, the !ERROR directive prints the message and the
Make utility stops executing.

Makefiles
Make
Utility Macros

Conditional
Expressions in Makefiles
Make Utility
Command Options