在nmake的Hello World中,蚂蚁简单示范了一个使用nmake构建程序的例子,在这个例子里,我们将给生成的可执行文件增加版本资源。
有所改变的文件如下
DEL *.obj
DEL *.res
DEL *.exe
#include <stdio.h>
void main()
{
printf("Spike Command Line Build v1.0.0.0.\n");
}
#
# File Name: makefile
# Summary:
# Simply demonstrate how to use nmake to build a exe file with version info.
#
#
# You must define link yourself, i'm trapped at this point for a while...:(
#
link=link.exe
#
# Spike excuted binary file name
#
EXE=SpikeCmdBuild.exe
#
# Spike source file & object file
#
APPSRC=SpikeCmdBuild.cpp
# Note how we replace the .cpp with .obj in a macro
APPOBJ=$(APPSRC:.cpp=.obj)
#
# Spike resource file
#
APPRC=SpikeCmdBuild.rc
# Also macro replacement as above
APPRES=$(APPRC:.rc=.res)
#
# nmake entry point
#
all: $(EXE)
#
# Note: We use some infered rules, such as
# .cpp.obj
# $(CPP) $(CPPFLAGS) /c $<
# .rc.res
# $(RC) $(RFLAGS) /r $*
# Please type commmand "nmake /P" to view the detail info.
#
$(EXE):$(APPOBJ) $(APPRES)
$(link) $(APPOBJ) $(APPRES)
新增加的文件
#include <windows.h>
#define P_VERSION 1,0,0,0
#define F_VERSION 1,0,0,0
#define P_VERSTR "1, 0, 0, 0\0"
#define F_VERSTR "1, 0, 0, 0\0"
VS_VERSION_INFO VERSIONINFO
FILEVERSION F_VERSION
PRODUCTVERSION P_VERSION
FILEFLAGSMASK 0x3fL
FILEFLAGS 0x0L
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
{
BLOCK "StringFileInfo" {
BLOCK "080004B0" {
VALUE "CompanyName", "Spike Inc.\0"
VALUE "FileDescription", "Spike exe for command build.\0"
VALUE "FileVersion", F_VERSTR
VALUE "InternalName", "Spike\0"
VALUE "LegalCopyright", "Leftright twinsant@sina.com\0"
VALUE "LegalTrademarks", "twinsant(tm)\0"
VALUE "OriginalFilename", "SpikeCmdBuild.exe\0"
VALUE "ProductName", "SpikeCmdBuild\0"
VALUE "ProductVersion", P_VERSTR
}
}
BLOCK "VarFileInfo" {
VALUE "Translation", 0x800, 1200
}
}