Directives in Makefiles

Using directives, you can construct description files similar to batch files. The Make Utility provides directives that:

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:



Makefiles
Make Utility Macros


Conditional Expressions in Makefiles
Make Utility Command Options