Customizing a Build Process

Home Page (Projects)OverviewsHow Do I... TopicsNMAKE Reference

You can specify custom build rules for use with any project or with any individual files that do not already have a rule associated with them. These rules then process the files at the appropriate point in the build if the output file is out of date with respect to the input file.

For example, you can add an .l file to your project, specify a lexical analyzer to process the file and produce a .y output file, and then specify a parser generator to process that file to create a source-code file. You could also select the output file for a configuration, to copy it to a specific directory for testing. Microsoft Visual C++ provides a number of macros for use in these commands.

Note   By default, a number of file types have tools associated with them, such as .c or .cpp files in Visual C++. To specify a custom rule for these files, you must select the Always use custom build step check box on the General tab of the Project Settings dialog box.

The custom rules run only on files in builds of the configurations in which you selected the files. That is, if your file set includes an .l file, and you select it only in one configuration, the rules that you specify run only in that configuration.

For example, assume that you want to include in your project a file named MYLEXINF.L. You first want a lexical analyzer to process MYLEXINF.L to produce a .C file with the same base name (MYLEXINF.C). First, you add MYLEXINF.L and MYLEXINF.C to your project using the Files into Project command on the Insert menu. (If you have not already created a version of MYLEXINF.C, Microsoft Visual C++ recognizes that and asks if you want to add a reference to the file anyway.) You then click the Settings command on the Project menu, and select MYLEXINF.L in the appropriate configuration. Next, select the Custom Build tab, and type commands similar to the following in the Build Command(s) list:

lexer $(InputPath) $(ProjDir)\$(InputName).c

This puts the lexical analyzer source MYLEXINF.C, in the project directory.

In the Output File(s) list, type $(ProjDir)\$(InputName).C. When you build this project, the build system checks the date of MYLEXINF.C. If its date is earlier than MYLEXINF.L, the build system runs these custom commands to rebuild MYLEXINF.C.

What do you want to know more about?

When custom build rules run

Macros for custom build commands

What do you want to do?

Specify custom build rules

Select the directories for the output files

Specify input dependencies

Specify build rules that run before the link process

Specify build rules that run after the build process