Article ID: 71422 - View products that this article applies to.
This article was previously published under Q71422
NMAKE provides several features that ease the process of maintaining a library by incrementally updating only the modules that change. With the $? special macro and macro substitutions, the process involves only one call to LIB (the library maintenance utility). The text below presents makefiles that illustrate this procedure.
The sample makefiles below keep MYLIB.LIB up to date with respect to the four object files listed in the OBJS macro. These object files can be based on C or assembly language source files. You can extend the list of source-file types the makefile supports by adding the appropriate inference rules to the description file.
Sample makefile 1 includes the following line to maintain the library:
The $? macro expands to the list of all dependents that are out-of- date with respect to the target file. The "$(?: =-+)" part of the command-line is a macro substitution to be performed on the $? macro. This substitution instructs NMAKE expand $? to the list of out-of-date dependents, but then replace all spaces in the expanded list with the two-character pair "-+".
For example, assume that only MOD1.OBJ, MOD3.OBJ, and MOD4.OBJ are each out-of-date with respect to MYLIB.LIB. The $? macro expands to the following:
Therefore, $(?: =-+) actually causes the macro to be expanded with substitution as follows:
With the remainder of the command line included for reference, the NMAKE executes the following command line:
Note that the first time you add a module to the library with this command, LIB generates a "U4155: module not in library" warning to indicate that LIB is unable to replace a module because it is not found in the library. You can ignore the warning because LIB simply adds the module to the library.
This method works correctly as long as the OBJS macro does not contain too many modules. If the macro expansion causes the command line to exceed the MS-DOS or OS/2 command-line length limit (128 or 255 characters, respectively), the LIB call fails. If your library contains enough modules such that this may occur, then you should use the NMAKE in-line file capability to generate a response file.
Sample makefile 2 below demonstrates the response file method. The makefile creates a response file named MYLIB.LRF that contains the lines of the makefile between the double angle bracket (<<) tokens. The contents of the makefile reflect a macro substitution that is very similar to the method demonstrated above. The major difference is as follows: an input line in the response file is required for each LIB prompt. Therefore, the macro substitution must place newline characters into the file. The following command does this:
This command instructs NMAKE to expand the macro for out-of-date dependents by replacing each space with a space, and ampersand (&), a newline and a "-+" character pair. The caret (^) instructs NMAKE to interpret the next character literally, to place the newline character that follows the caret into the macro. (Because you type ENTER to place a newline character into the file, the end of the macro substitution must appear on the following line.)
Therefore, given the same scenario as above, if MOD1.OBJ, MOD3.OBJ, and MOD4.OBJ are out-of-date with respect to MYLIB.LIB, the $? macro expands to the following:
With this method, you can maintain any number of object files with one call to LIB.
Note: NMAKE version 1.1 (provided with Microsoft C versions 6.0 and 6.0a) does not expand the $? macro correctly unless the target- dependency line uses the multiple dependency operator, a double colon (::). To work around this problem, modify the makefile to specify a double colon instead of a single colon for the dependency that involves the library.
For more information on macro substitution or in-line files, please refer to the NMAKE documentation or online help provided with your compiler. For more information on response files, please refer to the LIB or LINK documentation or online help.
Sample NMAKE Makefile 1
Sample NMAKE Makefile 2
Article ID: 71422 - Last Review: October 23, 2003 - Revision: 2.0