1. if you already haveVc6Nmake script file (. Mak) can be exported directly)
"Project-export makefile ..."
Nmake-F nmaketest. Mak CFG = "nmaketest-Win32 debug"
Nmake-F nmaketest. Mak CFG = "nmaketest-Win32 debug" All
Nmake-F nmaketest. Mak CFG = "nmaketest-Win32 release" clean
Note: If the/F option is not specified, use the makefile in the current directory.
【Nmake /?] For more help! Vc6: [D: \ Program Files \ Microsoft Visual Studio \ vc98 \ bin]
Vs2008: [D: \ Program Files \ Microsoft Visual Studio 9.0 \ Vc \ bin]
2. The C ++ project of vs does not provide the nmake script file export function. We only need to use tools or manually compile the nmake script file.
++ ++
3.Rc.exe[Convert. RC resource text to. Res binary file]
/L 0x804 // default language ID (in hexadecimal notation) 0x804: Simplified Chinese 0x409: More in the United States...
/FO "nmaketest. Res" // specify the res name output by the RC file
For example, rc.exe/L 0x804/FO "nmaketest. Res"/D "_ debug"/D "_ afxdll" "nmaketest. RC"
4.Cl.exeCommon options [compile. C,. cpp,. cxx into an OBJ file]
/I "../include" // Add the header file search path
/D Win32 // pre-compiled macro definition
/W3 // set level 3 warning level
/FP "nmaketest. PCH" // specify the precompiled file name
/YU "stdafx. H" // use the pre-compiled header file during generation
/C // compile but not link
/Femytest // compile and output the mytest.exe Executable File
/LD // create a dynamic link library
/LDD // create a dynamic link library for debugging
/Ml // use libc. lib to create a single-thread Executable File
/MLD // use libcd. lib to create a single-thread executable file for debugging
/MT // use libcmt. lib to create multi-thread executable files
/MTD // use libcmtd. lib to create and debug multi-thread executable files
/MD // use msvcrt. lib/msvcrt. DLL to create multi-thread executable files
/MDD // use msvcrtd. lib/msvcrtd. DLL to create and debug multi-thread executable files
/Z7 // generate debugging information compatible with c7.0
/ZD // generate the row number
/Zi // generate complete debugging information
/Link // pass the/Linklater-specified token to link.exe
// When the cl.execompilation is complete, link.exe will be automatically called for connection,
// After cl.exe is used directly to compile. C or. cpp with the main function, the OBJ and exe files are generated.
For example, CL/C test1.cpp test2.cpp // compile test1.cpp and test2.cpp.
For example, Cl *. CPP/MD/C/I "G: \ VISUAL C ++ \ vc98 \ platformsdk \ include"
5.Link.exeCommon options [link obj, Lib, res to DLL, EXE, and other executable files]
/DLL // output the DLL file
-Lib // generate lib static library file example: Link-lib *. OBJ/out: Test. Lib
/Libpath: ".. \ publicsdk \ Lib" // specify the external lib search path
/Subsystem: Windows [console] // specify a subsystem
/Machine specify the target platform {am33 | arm | EBC | IA64 | m32r | MIPS | SH3 | sh3dsp | sh4 | sh5 | thumb | x86 | x64}, etc.
/Debug // generate debugging information
/PDB: "nmaketest. PDB" // rename the generated PDB File
/Map: "nmaketest. Map" // rename the generated map file
/Out: "nmaketest.exe" // rename the generated EXE file
/Implib: "test. lib" // generate a export database named test. Lib.
/Entry: _ dllmaincrtstartup @ 12 // specify the start address of the _ dllmaincrtstartup function DLL.
Example: link gdiplus. lib/subsystem: Windows/out: test.exe file1.obj file2.lib file3.res // generate a Windows executable program named test.exe
Example: link gdiplus. lib/subsystem: console/out: test.exe *. OBJ file2.lib file3.res // generate a console executable program named test.exe
Example: link gdiplus. LIB/subsytem: Windows/dll/out: test. dll/implib: test. LIB/DEF: test. def *. OBJ file2.lib file3.res // generate the name test. DLL dynamic library
Example: link *. obj rc. res/libpath: "G: \ visual c ++ \ Lib"/subsystem: Windows/machine: x86 kernel32.lib user32.lib gdi32.lib winspool. lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib UUID. lib odbc32.lib odbccp32.lib opengl32.lib
6.NmakeInstructions
(1) symbol description
# // Annotator
^ # ABC // # ABC string
\\// Connector used to merge two rows into one row. In a macro, when writing multiple rows, you must use "\" to connect.
% // File description
@ // Command modifier; prevents the result of the modified command from being printed.
$ // Macro quote
: // Dependency symbol
? [*] // Supports wildcard characters
(2) long file names are enclosed in double quotation marks.
For example, all: nmaketest. dll // the file name is short, and quotation marks are not required.
For example, all: "$ (outdir) \ nmaketest.exe" // when the file name is long, especially when spaces exist in the path, you must use quotation marks.
(3) include the sub-MAKEFILE file
Include "./dll/makefile"
(4) condition judgment-01
! If "$ (CFG)" = ""
CFG = nmaketest-Win32 debug
! Message no configuration specified. Defaulting to nmaketest-Win32 debug.
! Else
! Message be specified.
! Endif
(5) condition judgment-02 【! Ifndef! Ifdef]
! Ifndef private_runtimemode_debug
Runtimemode_debug =/MDD
! Else
Runtimemode_debug = $ (private_runtimemode_debug)
! Endif
(6) Output Message logs
! Message invalid configuration "$ (CFG)" specified.
(7) description block-the core of makefile. [Note: there cannot be blank lines between dependencies (or rules) and command blocks. commands is a Tab character before]
Targets...: dependences...
Commands...
(8) All/clean
Outdir =. \ release
Intdir =. \ release
ALL: "$ (outdir) \ nmaketest.exe"
Clean:
-@ Erase "$ (intdir) \ nmaketest. OBJ"
-@ Erase "$ (intdir) \ nmaketest. PCH"
-@ Erase "$ (intdir) \ nmaketest. Res"
-@ Erase "$ (intdir) \ nmaketestdlg. OBJ"
-@ Erase "$ (intdir) \ stdafx. OBJ"
-@ Erase "$ (intdir) \ vc60.idb"
-@ Erase "$ (outdir) \ nmaketest.exe"
-@ Erase "$ (outdir) \ nmaketest. Map"
"$ (Outdir )":
If not exist "$ (outdir)/$ (null)" mkdir "$ (outdir )"
(9) Compile
Cpp1_cl.exe
Cpp_proj =/nologo/MD/W3/GX/O2/D "Win32"/D "ndebug"/D "_ WINDOWS"/D "_ afxdll"/D "_ MBCS" /FP "$ (intdir) \ nmaketest. PCH "/YU" stdafx. H "/FO" $ (intdir) \ "/FD" $ (intdir) \ "/FD/C
. C {$ (intdir)}. OBJ ::
$ (CPP) @ <
$ (Cpp_proj) $ <
<
. Cpp {$ (intdir)}. OBJ ::
$ (CPP) @ <
$ (Cpp_proj) $ <
<
. Cxx {$ (intdir)}. OBJ ::
$ (CPP) @ <
$ (Cpp_proj) $ <
<
(10) Links
Link321_link.exe
Link32_flags =/nologo/subsystem: Windows/Incremental: No/PDB: "$ (outdir) \ nmaketest. PDB "/map:" $ (intdir) \ nmaketest. map "/machine: i386/out:" $ (outdir) \ nmaketest.exe"
Link32_objs = \
"$ (Intdir) \ nmaketest. OBJ "\
"$ (Intdir) \ nmaketestdlg. OBJ "\
"$ (Intdir) \ stdafx. OBJ "\
"$ (Intdir) \ nmaketest. Res"
"$ (Outdir) \ nmaketest.exe": "$ (outdir)" $ (def_file) $ (link32_objs)
$ (Link32) @ <
$ (Link32_flags) $ (link32_objs)
<
(11) file dependency
Source =. \ nmaketest. cpp
"$ (Intdir) \ nmaketest. OBJ": $ (source) "$ (intdir)" "$ (intdir) \ nmaketest. PCH"
Source =. \ nmaketest. RC
"$ (Intdir) \ nmaketest. Res": $ (source) "$ (intdir )"
$ (RSC) $ (rsc_proj) $ (source)
(12) pre-compiled files
Source =. \ stdafx. cpp
! If "$ (CFG)" = "nmaketest-Win32 release"
Cpp_switches =/nologo/MD/W3/GX/O2/D "Win32"/D "ndebug"/D "_ WINDOWS"/D "_ afxdll"/D "_ MBCS" /FP "$ (intdir) \ nmaketest. PCH "/YC" stdafx. H "/FO" $ (intdir) \ "/FD" $ (intdir) \ "/FD/C
"$ (Intdir) \ stdafx. OBJ" "$ (intdir) \ nmaketest. PCH": $ (source) "$ (intdir )"
$ (CPP) @ <
$ (Cpp_switches) $ (source)
<
! Elseif "$ (CFG)" = "nmaketest-Win32 debug"
Cpp_switches =/nologo/MDD/W3/GM/GX/Zi/OD/D "Win32"/D "_ debug"/D "_ WINDOWS"/D "_ afxdll "/ d "_ MBCS"/FP "$ (intdir) \ nmaketest. PCH "/YC" stdafx. H "/FO" $ (intdir) \ "/FD" $ (intdir) \ "/FD/GZ/C
"$ (Intdir) \ stdafx. OBJ" "$ (intdir) \ nmaketest. PCH": $ (source) "$ (intdir )"
$ (CPP) @ <
$ (Cpp_switches) $ (source)
<
! Endif
# Reference
1. http://msdn.microsoft.com/zh-cn/library/dd9y37ha (V = vs.80). aspx
2. http://c2.com/cgi/wiki? Usingnmake
3. http://zh.wikipedia.org/wiki/Make
4. Explanation of cl.exe link.exe usage
5. http://blog.codingnow.com/2008/09/replacement_of_ide_1.html
6. http://blog.codingnow.com/2008/09/replacement_of_ide_2
7. http://blog.codingnow.com/2008/09/replacement_of_ide_3
Http://blog.codingnow.com/2008/09/replacement_of_ide_4