昨天把pmon推到了github上,然后,今天突然发现了一点点小异常。

突然这个名字被修改了 ,让我觉得眼前一亮啊。

原来pmon背后还有点意思。

因为这个提示在logo下面,这个就很容易找到了。(pmon/common/main.c)

869行打印了logo

884行的位置,对应有个Version:

1. 好家伙,这个字符串vers来自全局变量。

追查这个全局变量,来自vers.c文件,并且发现内容已经被修改好了。

 2. 那这个文件也是自动生成的。

这里我看看编译脚本

发现在编译vers.c之前,运行了一个shell脚本(newvers.h),感觉这个有戏。

 3. 找到这个文件newvers.h

#!/bin/sh -
#
# Copyright (c) 2001, 2002
#	Interactive People Unplugged AB.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#	This product includes software developed by Interactive People 
#	AB, Sweden and its contributors.
# 4. Neither the name of the IP Unplugged AB nor the names of its contributors
#    may be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

if [ ! -r version ]
then
	echo 0 > version
fi

touch version
v=`cat version` u=${USER-root} d=`pwd` h=`hostname` t=`env LANG=en_US.UTF-8 date`
id=`basename ${d}`
git=`git log -1|head -n 3|perl -e 'local $/;$a=<>;$a=~s/\n/ /g;print $a;'`
ost="PMON2000"
osr="3.3"

cat >vers.c <<eof
char ostype[] = "${ost}";
char osrelease[] = "${osr}";
char osversion[] = "${id}#${v}";
char sccs[8] = { ' ', ' ', ' ', ' ', '@', '(', '#', ')' };
char vers[] =
    "${ost} ${osr} (${id}) #${v}: ${t} ${git}";
eof

cat >vers.h <<eof
#define VERS "${ost} ${osr} (${id}) #${v}: ${t}\r\n"
eof

expr ${v} + 1 > version

这个文件就解释几句

3.1 if那里是去读取version文件,如果不存在,则创建一个,并且写入0.

3.2 v 变量的结果来自“cat version” ,后面u变量的结果来自shell变量${USER-root}的值

version文件中就一个数字:

 git 来自git命令的结果,git log -1 果然可以得到自己的git信息

 3.3 然后把内容写入到vers.c文件中

这里cat 写入,<< eof 就是把eof之前的字符写入到vers.c

就是我们前面看到的值了。

3.4 写入h文件

 3.5 把version中的数字加1,然后写到version中。而这个数字就是

 这个有点意思,每编译一次,就加1,这样就很方便自动控制版本了。

这个数字应该表示下一次编译的次数号了。

4. 再编译一下,并更新到开发板试试。

 果然已经更新了。

既然别人有这么优秀的版本控制办法,我们也可以多多借鉴借鉴一下。这样你要找到相同的版本就容易很多了。

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐