Makefile Batch Processing

Source: Internet
Author: User
Tags win32

This article mainly describes how to use batch processing to carry out the project batch compilation. This does not have to go to a single application to all other engineering libraries to open the compilation, to facilitate development. You can also use Makefile to view the dependencies between projects.

In fact, we compile, either directly using the IDE for compiling, or using the. bat batch.

The following is mainly introduced VS2008 IDE vcbuild.exe to achieve the implementation of Engineering batch compilation, as for the vc6.0,vs2010 under the corresponding IDE batch implementation, are similar (The IDE of the VC6.0 is the msdev.exe,vs2010 IDE is MSBuild.exe).

1. We will use the. mak file in our batch compilation, so we need to write a. mak file, such as Capiluademo.mak, which is basically all the projects you need to compile (it is recommended that all projects have been implemented in accordance with the specification configuration path). For some of the macro syntax in. Mak, you can check NMAKE's related syntax in MSDN.

definition of NMAKE macro

Macroname=string

use of NMAKE macro

$ (macroname)

Put the code below

#-----------------------------------------------------------------------------# Path Definition #---------------- -------------------------------------------------------------#--------Here suggest the IDE for the corresponding development environment, see the name of righteousness DEVENV = "E:\ Microsoft Visual Studio 9.0\vc\vcpackages\vcbuild.exe "POSTFIX = vcproj!" IF ' $ (CFG) ' = ' release ' proj_cfg = release Lib_postfix =! ELSE proj_cfg = Debug Lib_postfix = _d! ENDIF Make_flag =/out/build.log Build_flag =/$ (FLAG) #============================================================ ====================== #================================================================================== SRC_ Lualib_lib_path = \users\taoping\documents\visual Studio 2008\projects\capiluademo\src\libproject\lualib SRC_

Capilua_exe_path = \users\taoping\documents\visual Studio 2008\projects\capiluademo\src\exeproject\capiluademo buildall:del/q Build.log #------------Lualib Lib----------------------------------------------------------------- --------------------------
#======= = = Lualib_static ====================================================== $ (DEVENV) "$ (Src_lualib_lib_path) \LuaLib . $ (POSTFIX) "$ (Build_flag)" $ (proj_cfg) |	Win32 "$ (make_flag) #========== lualib_static ====================================================== #------------ Capiluademo Exe-------------------------------------------------------------------------------------------#==== = = = = = Capiluademo ====================================================== $ (DEVENV) "$ (Src_capilua_exe_path) \ capiluademo.$ (POSTFIX) "$ (Build_flag)" $ (proj_cfg) | Win32 "$ (make_flag) #========== G+massproductiontool ======================================================



Note:

In the write. Mak file, such as

$ (DEVENV) "$ (Src_lualib_lib_path) \lualib.$ (POSTFIX)" $ (Build_flag) "$ (proj_cfg) | Win32 "$ (make_flag)

#========== lualib_static ======================================================

It's best to have a line between the two, otherwise it's easy to have problems.

There are special characters like "$ (Src_lualib_lib_path) \lualib.$" (POSTFIX), such as spaces, underscores, etc., so that we need to enclose them in double quotes, or we will give an error.

Some assignment statements, such as Postfix, are all just definitions of macro variables, so $ (macroname) is used for this macro variable. If you are unfamiliar with makfefile syntax, you can go to the MSDN Direct Lookup makefile to understand its related syntax.

2. Open the VS2008 project, establish a makefile project, the project name is Capiluademomakefile, in the pop-up window, may finish the creation window directly, also may in the Creation window or the project attribute to set up, or close the project to open the capiluademomakefile.vcproj file directly in the text, adding the appropriate item to it. At this time we directly close the Makefile project, in the work directory of the project has been. vcproj project file capiluademomakefile.vcproj.

(We use the NMAKE tool for batch compilation, and if you open the Capiluademomakefile.vcproj file in text, it's an XML-formatted document with a Vcnmaketool,vcnmaketool actually Microsoft tool Chain in a tool, interested in the VC can be established by the EXE or DLL library project. Vcproj project files are compared to makefile.vcproj project files when they are different, EXE or DLL is name= " VCMidlTool "As to what to fill in this XML document, unfamiliar friends can go to MSDN to find out about it. )

The document code is attached below . (There are some not filled in, there is a default value)

<?xml version= "1.0" encoding= "gb2312"?> <visualstudioproject projecttype= "Visual C + +" version= "9.00" Name= "
	Capiluademomakefile "projectguid=" {ac320f53-a504-41fe-8fa3-9bef7d40aa8d} "keyword=" MakeFileProj " targetframeworkversion= "196613" > <Platforms> <platform name= "Win32"/> </Platforms> <t oolfiles> </ToolFiles> <Configurations> <configuration name= "debug|
			Win32 "outputdirectory=" $ (configurationname) "intermediatedirectory=" $ (configurationname) "configurationtype=" 0 " > <tool name= "vcnmaketool" buildcommandline= "nmake/f capiluademo.mak flag=build cfg=debug" ReBuil Dcommandline= "nmake/f capiluademo.mak flag=rebuild cfg=debug" cleancommandline= "output=" "PreprocessorDefin" itions= "Win32;_debug" includesearchpath= "forcedincludes=" "assemblysearchpath=" "forcedusingassemblies=" "Compileasmanaged=" "/> </Configuration> <configuration
			Name= "release|
			Win32 "outputdirectory=" $ (configurationname) "intermediatedirectory=" $ (configurationname) "configurationtype=" 0 " > <tool name= "vcnmaketool" buildcommandline= "nmake/f capiluademo.mak flag=build cfg=release" ReBu Ildcommandline= "nmake/f capiluademo.mak flag=rebuild cfg=release" cleancommandline= "Output=" "PreprocessorD" Efinitions= "WIN32; Ndebug "includesearchpath=" "forcedincludes=" "assemblysearchpath=" "forcedusingassemblies=" "CompileA" Smanaged= ""/> </Configuration> </Configurations> <References> </References> <files > <filter name= "Source Files" filter= "Cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" uniqueidentifier= "{4FC73 7F1-C7A5-4376-A066-2A32D752A2FF} "> </Filter> <filter name=" Header Files "filter=" h;hpp;hxx;hm;in L;inc;xsd "uniqueidentifier=" {93995380-89BD-4B04-88EB-625FBE52EBFB} "> </Filter> <filter
			Name= "Resource Files" filter= "Rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" UniqueI
			Dentifier= "{67da6ab6-f800-4c08-8b7a-83bb121aad01}" > </Filter> <file relativepath= ". \readme.txt"
 > </File> </Files> <Globals> </Globals> </VisualStudioProject>


3. The last thing I need to do is to write a batch file. bat, such as Rebuild_debug.bat. The vsvars32.bat batch file in the directory represented by environment variable vs90comntools is mainly to set up environment variables, which can be opened by oneself.

Put Code on

@call "%vs90comntools%vsvars32.bat"

@SET delparam=/s/q *.ncb *.sbr *.obj *.pch *.pdb *.idb *.exp *.opt *.CLW-*.bbs *. APS *.PLG *.BSC *.lik *.lib


@call "%vs90comntools%vsvars32.bat"

@echo off
Echo ********** build Debug Capiluademo Project ************
echo ******************************************************
@echo

on CD  C:\Users\taoping\Documents\Visual Studio 2008\projects\capiluademo\makefile
@if exist "Debug" Del \debug \*.htm
cd  C:\Users\taoping\Documents\Visual Studio 2008\projects\capiluademo\makefile

vcbuild  /showenv capiluademomakefile.vcproj "Debug"/rebuild

Note:

If you want to release the compiler, just want to put this sentence vcbuild/showenv capiluademomakefile.vcproj "Debug"/rebuild, change to Vcbuild/showenv Capiluademomakefile.vcproj "Release"/rebuild

VCBuild's Grammar

In the batch rebuild_debug.bat above, some add @ To hide the current row in the window.
. bat to use variables, you can set variables, if not clear. bat batch file related syntax, you can go to understand, in fact. bat batch and. Mak's makefile files are written in some different grammatical formats.

cmd interpreter, mainly to explain. bat batch files and COM files;

NMAKE interpreter, mainly to explain the makefile file;

4. After writing rebuild_debug.bat, we only need to double-click to execute the file, we can implement batch compilation. His execution process is to use Vcbuild to invoke Nmake,vcbuild.exe----> VCNMakeTool.exe-----> NMAKE.exe.

Here, we should all be able to feel Microsoft as a commercial product, a bit good is, a lot of help documents, many you can not see the end, I mainly used to see the. Perhaps this is the difference between commercialization and open source.

==================================================================

The following is from the network: Click on the Open link

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.