其實(shí),一直以來(lái),我們編譯KVM(Linux kernel)生成的RPM包中的kernel版本總是帶有一個(gè)“莫名其妙”的加號(hào)(+),其實(shí)我知道大概是因?yàn)槲覀冃薷牧薒inux.git(或kvm.git)中的一些文件。但是我們只是修改了一下Makefile,讓我們做RPM包是方便而已,一般我也沒有在編譯時(shí)修改其他的源代碼文件,所以我想把這個(gè)加號(hào)去掉,對(duì)其進(jìn)行了簡(jiǎn)單的研究,問(wèn)題已經(jīng)搞定了,記錄如下吧。
kernel版本出現(xiàn)一個(gè)加號(hào)(plug sign)的原因可能是如下兩點(diǎn),當(dāng)然前提是使用Linux的GIT repository,且CONFIG_LOCALVERSION_AUTO和LOCALVERSION都沒有設(shè)置。
(1)如果當(dāng)前repository的commit ID不是某一個(gè)tag,則默認(rèn)有一個(gè)加號(hào)。因?yàn)樵谧钌蠈拥腗akefile中只有該repository中最近一次tag的版本信息,需要用加號(hào)(+)來(lái)標(biāo)識(shí)它并非一個(gè)tag(如:3.5.0)。
(2)如果當(dāng)前repository的commit ID剛好是一個(gè)tag,且其中有GIT管理下的文件被改動(dòng),這默認(rèn)有一個(gè)加號(hào)(+)。
如果想避免這個(gè)煩人的加號(hào),可以將scripts/setlocalversion腳本中帶有’ echo “+” ‘和’ res=”$res${scm:++}” ‘的這兩行刪掉即可。
To avoid the additional plus sign in kernel release version, just remove ‘ echo “+” ‘ line and ‘ res=”$res${scm:++}” ‘ line in scripts/setlocalversion file.
首先,Linux的頂層的Makefile關(guān)于版本的信息,以及對(duì)”make kernelrelease”的定義如下:
1234567891011121314 | VERSION = 3PATCHLEVEL = 5SUBLEVEL = 0EXTRAVERSION =NAME = Saber-toothed Squirrel#.............. @echo ' kernelrelease - Output the release version string' @echo ' kernelversion - Output the version stored in Makefile'#..............kernelrelease: @echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))" kernelversion: @echo $(KERNELVERSION) |
然后,我們執(zhí)行“make kernelrelease”則會(huì)生成kernel發(fā)布的版本信息,如下:
12345 | [root@jay-linux linux.git]# make kernelrelease3.5.0[root@jay-linux linux.git]# vi mm/oom_kill.c[root@jay-linux linux.git]# make kernelrelease3.5.0+ |
注意,這個(gè)加號(hào)其實(shí)是作為本地的版本號(hào)加進(jìn)去的,詳見scripts/setlocalversion這個(gè)腳本,有如下的部分重要內(nèi)容。
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 | scm_version(){ local short short=false cd "$srctree" if test -e .scmversion; then cat .scmversion return fi if test "$1" = "--short"; then short=true fi # Check for git and a git repo. if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore # it, because this version is defined in the top level Makefile. if [ -z "`git describe --exact-match 2>/dev/null`" ]; then # If only the short version is requested, don't bother # running further git commands if $short; then echo "+" return fi # If we are past a tagged commit (like # "v2.6.30-rc5-302-g72357d5"), we pretty print it. if atag="`git describe 2>/dev/null`"; then echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),$(NF))}' # If we don't have a tag at all we print -g{commitish}. else printf '%s%s' -g $head fi fi if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then printf '%s' -dirty fi # All done with git return fi#................}#................# CONFIG_LOCALVERSION and LOCALVERSION (if set)res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}" # scm version string if not at a tagged commitif test "$CONFIG_LOCALVERSION_AUTO" = "y"; then # full scm version string res="$res$(scm_version)"else # append a plus sign if the repository is not in a clean # annotated or signed tagged state (as git describe only # looks at signed or annotated tags - git tag -a/-s) and # LOCALVERSION= is not specified if test "${LOCALVERSION+set}" != "set"; then scm=$(scm_version --short) res="$res${scm:++}" fifiecho "$res" |
如下的一些信息可以方便你理解上面的這段腳本。
123456789101112131415 | [root@jay-linux linux.git]# git rev-parse --verify --short HEAD28a33cb[root@jay-linux linux.git]# git describe --exact-match 2>/dev/nullv3.5[root@jay-linux linux.git]# git diff-index --name-only HEADmm/oom_kill.c[root@jay-linux linux.git]# man git #........... git-rev-parse(1) Pick out and massage parameters. git-describe(1) Show the most recent tag that is reachable from a commit. git-diff-index(1) Compares content and mode of blobs between the index and repository. #............ |
另外,對(duì)于setlocalversion中的一個(gè)語(yǔ)法解釋一下:
${var:-value1} 在變量var不為空時(shí),保持var原有的值不變;如果var變量未設(shè)置或者為空,這表達(dá)式結(jié)果為value1,但是變量var的值并不改變(未設(shè)置或?yàn)榭眨?br>${var:+value1} 在變量var不為空時(shí),表達(dá)式結(jié)果為value1;如果var變量未設(shè)置或者為空,這表達(dá)式結(jié)果為空。${var+value1}的效果一樣。
${var:=value1} 在變量var不為空時(shí),保持var原有的值不變;如果var變量未設(shè)置或者為空,這表達(dá)式結(jié)果為value1,變量var也被賦值為value1。
${var:?value1} 在變量var未設(shè)置或?yàn)榭諘r(shí),腳本會(huì)退出并拋出一個(gè)錯(cuò)誤信息(包含value1)。
另外,如下一篇博客也研究了這個(gè)問(wèn)題,供大家參考。
http://blog.csdn.net/adaptiver/article/details/7225980
聯(lián)系客服