Вы находитесь на странице: 1из 4

NMAKE Options

Visual Studio .NET 2003 NMAKE options are described in the following table. Options are preceded by either a slash (/) or a dash () and are not case sensitive. Use !CMDSWITCHES1 to change option settings in a makefile or in Tools.ini. Option /A /B /C /D Purpose Forces build of all evaluated targets, even if not out-of-date with respect to dependents. Does not force build of unrelated targets. Forces build even if timestamps are equal. Recommended only for very fast systems (resolution of two seconds or less). Suppresses default output, including nonfatal NMAKE errors or warnings, timestamps, and NMAKE copyright message. Suppresses warnings issued by /K. Displays timestamps of each evaluated target and dependent and a message when a target does not exist. Useful with /P for debugging a makefile. Use !CMDSWITCHES to set or clear /D for part of a makefile. Causes environment variables to override makefile macro definitions. Specifies filename as a makefile. Spaces or tabs can precede filename. Specify /F once for each makefile. To supply a makefile from standard input, specify a dash () for filename, and end keyboard input with either F6 or CTRL+Z. Displays a brief summary of NMAKE command-line syntax. Ignores exit codes from all commands. To set or clear /I for part of a makefile, use !CMDSWITCHES. To ignore exit codes for part of a makefile, use a dash () command modifier or .IGNORE2. Overrides /K if both are specified. Continues building unrelated dependencies, if a command returns an error. Also issues a warning and returns an exit code of 1. By default, NMAKE halts if any command returns a nonzero exit code. Warnings from /K are suppressed by /C; /I overrides /K if both are specified. Displays but does not execute commands; preprocessing commands are executed. Does not display commands in recursive NMAKE calls. Useful for debugging makefiles and checking timestamps. To set or clear /N for part of a makefile, use !CMDSWITCHES. Suppresses the NMAKE copyright message. Displays information (macro definitions, inference rules, targets, .SUFFIXES2 list) to standard output, and then runs the build. If no makefile or command-line target exists, it displays information only. Use with /D to debug a makefile. Checks timestamps of targets; does not run the build. Returns a zero exit code if all targets are up-to-date and a nonzero exit code if any target is not. Preprocessing commands are executed. Useful when running NMAKE from a batch file. Clears the .SUFFIXES list and ignores inference rules and macros that are defined in the Tools.ini file or that are predefined. Suppresses display of executed commands. To suppress display in part of a makefile, use the @ command modifier or .SILENT2. To set or clear /S for part of a makefile, use !CMDSWITCHES. Updates timestamps of command-line targets (or first makefile target) and executes preprocessing commands but does not run the build. Must be used in conjunction with /N. Dumps inline NMAKE files so that the /N output can be used as a batch file.

/E /F filename

/HELP, /? /I

/K

/N

/NOLOGO /P

/Q

/R /S

/T /U
1|Page

/X filename

/Y

Sends NMAKE error output to filename instead of standard error. Spaces or tabs can precede filename. To send error output to standard output, specify a dash () for filename. Does not affect output from commands to standard error. Disables batch-mode inference rules. When this option is selected, all batch-mode inference rules are treated as regular inference rules.

Running NMAKE
Visual Studio .NET 2003
NMAKE [option...] [macros...] [targets...] [@commandfile...]

NMAKE builds only specified targets or, if none is specified, the first target in the makefile. The first makefile target can be a pseudotarget1 that builds other targets. NMAKE uses makefiles specified with /F; if /F is not specified, it uses the Makefile file in the current directory. If no makefile is specified, it uses inference rules to build command-line targets. The commandfile text file (or response file) contains command-line input. Other input can precede or follow @commandfile. A path is permitted. In commandfile, line breaks are treated as spaces. Enclose macro definitions in quotation marks if they contain spaces.

2|Page

Nmake Makefile Tutorial and Example Aim The aim of this Nmake C++ tutorial is to give a quick introduction to nmake. We will look at the basics of an nmake makefile and go through the options of compiling and linking. Microsoft's C++ (Visual Studio) nmake is very similar to gnu's make with a few minor differences. Nmake has options very similar to gnu make and we will use some of them in this example. Leave any questions or problems as comments and I will endeavour to answer them. Assumptions This article assumes that you have a compatible version of Visual C++ installed. For this example we used Visual C++ 2008 Express Edition. However, there should not be any significant issues. As an example we will use a makefile that is used to compile one of the examples in this website - the common database pool template.

When you run nmake it looks for a file called makefile in the current directory. You can specify a file using the nmake -f myfile option. While it may look like cl.exe is doing all the work, cl.exe does the compiling and link.exe does the linking. For all the compile options you can use cl /? and for all the linker options you can use link /? You can run nmake without a target or you can specify a target such as nmane clean. Without a target nmake will look for the first available target in the makefile and build it.
1. MYSQL_HOME=D:\downloads\mysql-connector-c++-noinstall-1.0.5-win32 2. MYSQL_INCS=$(MYSQL_HOME)\include 3. MYSQL_LIBS=$(MYSQL_HOME)\lib 4. 5. mysqlbuild: mysqlpool.obj examplemysql.obj crosshelper.obj 6. cl /o hello.exe mysqlpool.obj examplemysql.obj crosshelper.obj /link /LIBPATH:$(MYSQL_LIBS) mysqlcppconn.lib 7. 8. 9. examplemysql.obj: ExampleMySQL.cpp 10. cl /c ExampleMySQL.cpp /D WINDOWSXX -I $(MYSQL_INCS) 11. 12. mysqlpool.obj: ..\mysql\MySQLPool.cpp 13. cl /c ..\mysql\MySQLPool.cpp /D WINDOWSXX -I $(MYSQL_INCS) 14. 15. crosshelper.obj: ..\CrossHelper.cpp 16. cl /c ..\CrossHelper.cpp /D WINDOWSXX 17. 18. oraclebuild: 19. echo "oracle build goes here" 20. 21. all:oraclebuild mysqlbuild 22. 23. clean: 24. del *.exe *.obj

Hide line numbers

lines 1,2 and 3 Defines variables that will be used in the compiling and the linking. Similar to environment variables. 3|Page

line 5 Defines a target called mysqlbuild that depends on other targets mysqlpool.obj, examplemysql.obj and crosshelper.obj. Before you goto line 6 to do the build nmake has to make sure that the dependencies are built. line 12,13 Here it finds the target mysqlpool.obj required at line 5. It depends on the CPP source file MySQLPool.cpp so now we go to the next line to compile the file. This is a compile only /c option. As you can see we are using the /D WINDOWSXX to define the WINDOWSXX macro and -I $(MYSQL_INCS) which is specifying the directory to search for include files. line 9,10 Build examplemysql.obj target required at line 5. line 15,16 Build corsshelper.obj target required at line 5. line 6 Once all the dependencies are built come back to line 6 and build the target. Here we are using /link to give the linker options which in this case is the LIBPATH to the mysqlcppconn.lib You can try nmake oraclebuild which will just display a message, and nmake all will try to build both the oraclebuild and mysqlbuild targets. Running nmake clean will delete all the *.obj and *.exe files so you can build them again.

4|Page

Вам также может понравиться