1. Invoke NMAKE's basic syntax in the command line:
namke/f makefile/x StdErrFile [macrodefs] [targets]
Where makefile is the makefile file, the/x stderrfile is an optional parameter that stores NMAKE errors to the file StdErrFile.
2, the main grammar of makefile:
2.1 Notes
Makefile's comments begin with #, such as:
# Usage:nmake Clean (removes all intermediary files)
# Or:nmake Options (builds one library variant (see below))
2.2 Macros
An important part of Makefile is the macro. The macro in Makefile is similar to the macro in the C language, which is essentially a string substitution. Its syntax is simple, as follows:
Macro NAME = macro Value
Macro NAME = macro Value
VS pre-defined many macros, such as OutDir, you can redefine the macros in your makefile to overwrite the original values.
Macros can use environment variables, such as your system has a OPEN_SOURCE environment variable, and you can define macros like this:
Third_party = $ (Open_source)
The reference usage for a macro is $ (macro name).
2.3 Preprocessing Instructions
Makefile's preprocessing directives are similar to the C language preprocessing directives, and their common directives are as follows:
! Error string--Displays the wrong "string" and then stops execution with an error code of U1050
! Message string--Displays the string, which is typically used for information to display the C language of the #pragma message
! Include [<]filename[>]--contains makefile.
! If const--is established (not 0), then process! F and next! else or! The statement between endif
There are also such as! Ifdef macroname,! Ifndef macroname,! ELSE,! ELSEIF,! Elseifdef,! Elseifndef,! The meaning of the directives such as # endif and C language is consistent.
2.4 Description Block
Basic syntax:
Target: Dependencies
Command
3. Example
Create a new console program named Consoletest, create a new file named Consoletest.vc in the Consoletest directory, and enter it with Notepad:
| 1234567891011121314 |
all: ConsoleTest.exe# compilestdafx.obj: stdafx.cpp cl -c -D_X86=1 -DWIN32 -D_DEBUG -D_CONSOLE -Istdafx.h stdafx.cppConsoleTest.obj: ConsoleTest.cpp stdafx.obj cl -c -D_X86=1 -DWIN32 -D_DEBUG -D_CONSOLE -Istdafx.h ConsoleTest.cpp # linkConsoleTest.exe: ConsoleTest.obj link /INCREMENTAL:YES /NOLOGO /subsystem:console /out:ConsoleTest.exe ConsoleTest.obj kernel32.libclean: @-ifexist *.obj del *.obj |
CL and link Brief:
Some common options for CL:
-C: Compile but not link
-D: Defines the preprocessor, such as-d_x86=1: Specifies compiling on the x86 platform,-d_debug: Defining the preprocessor _DEBUG,
-I: Included header file
The last parameter of CL is the compiled file.
Some common options for link are:
/incremental: Whether to enable incremental link, yes is enabled, no is not enabled,
/NOLOGO: Suppress the start copyright flag
/SUBSYSTEM: Specifies a subsystem that is typically two options on a PC Desktop program: Console (console program) and Windows (non-console program).
/out: Specifies the output file.
The last parameter of link is the obj file and library file that need to be linked.
Clean the @-if instruction below can be written like this:-if, whose run result is the same, but has the echo of the command. Also directly written: If, can be executed.
(GO) NMAKE study notes