Inline Files

NMAKE can create “inline files” in the commands section of a description block or inference rule. An inline file is created on disk by NMAKE and contains text you specify in the makefile. The name of the inline file can be used in commands in the same way as any filename. NMAKE creates the inline file only when it executes the command in which the file is created.

One way to use an inline file is as a response file for another utility such as LINK or LIB. Response files avoid the operating system limit on the maximum length of a command line and automate the specification of input to a utility. Inline files eliminate the need to maintain a separate response file. They can also be used to pass a list of commands to the operating system.

Specifying an Inline File

The syntax for specifying an inline file in a command is:

<<[[filename]]

Specify the double angle brackets (<<) on the command line at the location where you want a filename to appear. Because command lines must be indented (see page 660), the angle brackets cannot appear at the beginning of a line. The angle bracket syntax must be specified literally; it cannot be represented by a macro expansion.

When NMAKE executes the description block, it replaces the inline file specification with the name of the inline file being created. The effect is the same as if a filename was literally specified in the commands section.

The filename supplies a name for the inline file. It must immediately follow the angle brackets; no space is permitted. You can specify a path with the filename. No extension is required or assumed. If a file by the same name already exists, NMAKE overwrites it; such a file is deleted if the inline file is temporary. (Temporary inline files are discussed in the next section.)

A name is optional; if you don't specify filename, NMAKE gives the inline file a unique name. If filename is specified, NMAKE places the file in the directory specified with the name or in the current directory if no path is specified. If filename is not specified, NMAKE places the inline file in the directory specified by the TMP environment variable or in the current directory if TMP is not defined. You can reuse a previous inline filename; NMAKE overwrites the previous file.

Creating an Inline File

The instructions for creating the inline file begin on the first line after the command. The syntax to create the inline file is:

inlinetext
.
.
.
<<[[KEEP | NOKEEP]]

The set of angle brackets marking the end of the inline file must appear at the beginning of a separate line in the makefile. All inlinetext before the delimiting angle brackets is placed in the inline file. The text can contain macro expansions and substitutions. Directives and comments are not permitted in an inline file; NMAKE treats them as literal text. Spaces, tabs, and newline characters are treated literally.

The inline file can be temporary or permanent. To retain the file after the end of the NMAKE session, specify KEEP immediately after the closing set of angle brackets. If you don't specify a preference, or if you specify NOKEEP (the default), the file is temporary. KEEP and NOKEEP are not case sensitive. The temporary file exists for the duration of the NMAKE session.

It is possible to specify KEEP for a file that you do not name; in this case, the NMAKE-generated filename appears in the appropriate directory after the NMAKE session.

Example

The following makefile uses a temporary inline file to clear the screen and then display the contents of the current directory:

COMMANDS = cls ^

dir

showdir :

<<showdir.bat

$(COMMANDS)

<<

In this example, the name of the inline file serves as the only command in the description block. This command has the same effect as running a batch file named SHOWDIR.BAT that contains the same commands as those listed in the macro definition.

Reusing an Inline File

After an inline file is created, you can use it more than once. To reuse an inline file in the command in which it is created, you must supply a filename for the file where it is defined and first used. You can then reuse the name later in the same command.

You can also reuse an inline file in subsequent commands in the same description block or elsewhere in the makefile. Be sure that the command that creates the inline file executes before all commands that use the file. Regardless of whether you specify KEEP or NOKEEP, NMAKE keeps the file for the duration of the NMAKE session.

Example

The following makefile creates a temporary LIB response file named LIB.LRF:

OBJECTS = add.obj sub.obj mul.obj div.obj

math.lib : $(OBJECTS)

LIB math.lib @<<lib.lrf

-+$(?: = &^

-+)

listing;

<<

copy lib.lrf \projinfo\lib.lrf

The resulting response file tells LIB which library to use, the commands to execute, and the name of the listing file to produce:

-+add.obj &

-+sub.obj &

-+mul.obj &

-+div.obj

listing;

The second command in the descripton block tells NMAKE to copy the response file to another directory.

Using Multiple Inline Files

Summary: The same command can use more than one inline file.

You can specify more than one inline file in a single command line. For each inline specification, specify one or more lines of inline text followed by a closing line containing the delimiter. Begin the second file's text on the line following the delimiting line for the first file.

Example

The following example creates two inline files:

target.abc : depend.xyz

copy <<file1 + <<file2 both.txt

I am the contents of file1.

<<

I am the contents of file2.

<<KEEP

This is equivalent to specifying

copy file1 + file2 both.txt

to concatenate two files, where FILE1 contains

I am the contents of file1.

and FILE2 contains

I am the contents of file2.

The KEEP keyword tells NMAKE not to delete FILE2. After the NMAKE session, the files FILE2 and BOTH.TXT exist in the current directory.