Chinaunix首页 | 论坛 | 博客
  • 博客访问: 668292
  • 博文数量: 160
  • 博客积分: 2384
  • 博客等级: 大尉
  • 技术积分: 1366
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-01 11:35
文章分类
文章存档

2015年(45)

2014年(36)

2012年(28)

2011年(37)

2010年(2)

2009年(10)

2008年(2)

分类: LINUX

2011-05-24 11:41:38

  1. 一,将SVN版本信息添加到我们的程序版本中

  2. 1,使用sed命令修改源代码/Makefile中的版本号,添加SVN版本信息:

  3. #!/bin/sh
  4. #File Name: build-l200.sh

  5. #Get the SVN version number
  6. svn_ver=`svn up|grep revision|awk -F' ' '{ print $3 }'|awk -F'.' '{print $1}'`
  7. echo "SVN Version: $svn_ver"

  8. #Find the Version line
  9. line=`sed -n '/#define DROPBEAR_VERSION/=' options.h`

  10. #Instead the original version by mine
  11. sed -i -e ${line}s"/.*/#define DROPBEAR_VERSION \"0.51 Build ${svn_ver}\"/" options.h

  12. #compile the source code
  13. make

  14. 2, 将SVN版本信息放入version.h头文件中,在源代码中在包含该头文件并引用他们:
  15. a, makefile中定义版本信息并调用scripts/mkversion脚本:
  16. CROSS_COMPILE =
  17. ARCH= L200

  18. MAJOR=1
  19. MINOR=0
  20. REVER=0
  21. SVNUP=1

  22. all: entry version at
  23. version:
  24. @echo " ";
  25. @echo " =========================================";
  26. @echo " ** Create Software Version Head File **";
  27. @echo " =========================================";
  28. sh scripts/mkversion ${SVNUP} ${MAJOR} ${MINOR} ${REVER}

  29. b, scripts/mkversion脚本:

  30. #!/bin/sh

  31. GET_SVN=$1
  32. MAJOR=$2
  33. MINOR=$3
  34. REVER=$4

  35. if [ $GET_SVN -eq 0 ]
  36. then
  37. echo "============ Skip svn update ============"
  38. exit;
  39. else
  40. echo "============ SVN update and get svn version now ============"
  41. svn up
  42. svn_ver=`svn up|grep revision|awk -F' ' '{ print $3 }'|awk -F'.' '{print $1}'`

  43. echo "/* This is generate by makefile , don't Edit it by hand */" > version.h
  44. echo "#define MAJOR ${MAJOR}" >>version.h
  45. echo "#define MINOR ${MINOR}" >>version.h
  46. echo "#define REVER ${REVER}" >>version.h

  47. if [ ! -z $svn_ver ]
  48. then
  49. echo "#define SVNVER $svn_ver" >>version.h
  50. else
  51. echo "#define SVNVER 0000" >>version.h
  52. fi
  53. fi

  54. 3, 使用sed修改Makefile文件: 替换行/行前插入/行后插入

  55. 例一:
  56. FILE=src/pkcs11/Makefile

  57. #将文件中所有的$KEY替换成$INSTEAD
  58. KEY="-module -shared -avoid-version -no-undefined"
  59. INSTEAD="-module -static -avoid-version -no-undefined"
  60. sed -i -e "s/${KEY}/$INSTEAD/g" $FILE

  61. #找到某一行,并在其后插入一些行;
  62. FILE=src/libopensc/Makefile
  63. line=`sed -n '/all: all-am/=' $FILE`
  64. #替换该行内容
  65. sed -i -e ${line}s"/.*/all: all-am L200_rebuildLib/" $FILE
  66. #在该行后插入一些新的行
  67. sed -i -e `expr $line + 1`a"L200_rebuildLib:" $FILE
  68. sed -i -e `expr $line + 2`a"\\\tcp \`dirname \${abs_top_srcdir}\`/pcsc-lite-1.5.5/src/.libs/libpcscl
  69. ite.a \${abs_srcdir}/.libs" $FILE
  70. sed -i -e `expr $line + 3`a"\\\tsh \${abs_srcdir}/L200_rebuildLib.sh \${abs_srcdir}\n" $FILE

  71. 找到某一行,在该行前插入一行:
  72. FILE=src/Makefile
  73. #找到要修改的行号
  74. line=`sed -n '/CFLAGS = -Wall -fno-common/=' $FILE`
  75. #替换该行的内容
  76. sed -i -e ${line}s"/.*/CFLAGS = -Wall -fno-common -O2 -Wl,-elf2flt='-s 262144'/" $FILE
  77. #在该行前插入一行注释
  78. sed -i -e ${line}i"# Set stack size as 256K" $FILE

  79. 找到某一行,删除该行第一个字符:
  80. KEY="#am__EXEEXT_1 = cryptoflex-tool"
  81. line=`sed -n "/$KEY/=" $FILE`

  82. if [ $line ] ; then #如果变量不为空,即找到该行
  83. sed -i -e "${line}s/.//1" $FILE #这里的1即为第一个字符,若修改第二个字符则改为2
  84. sed -i -e "`expr $line + 1`s/.//1" $FILE
  85. sed -i -e "`expr $line + 2`s/.//1" $FILE
  86. fi

  87. 例二:
  88. CROSS=/opt/buildroot_350/build_arm/staging_dir/bin/arm-linux-uclibc-
  89. # | -----------------------------
  90. # | Cross compile iproute2-2.6.34
  91. # | -----------------------------

  92. if [ ! -d iproute2-2.6.34 ] ; then
  93. tar -xjf iproute2-2.6.34.tar.bz2
  94. fi

  95. if [ -d iproute2-2.6.34 ]; then
  96. cd iproute2-2.6.34
  97. FILE=Makefile
  98. sed -i -e 38s"/.*/SUBDIRS=lib tc/" $FILE

  99. line=`sed -n '/^CC = gcc$/=' $FILE`
  100. if [ $line ]; then
  101. sed -i -e ${line}s"@.*@CROSS=$CROSS@" $FILE //由于$CROSS中中包含sed默认分隔符"\",所以我们这里改用@作为分隔符
  102. sed -i -e `expr $line + 0`a"CC = \${CROSS}gcc" $FILE
  103. sed -i -e `expr $line + 1`a"AR=\${CROSS}ar" $FILE
  104. sed -i -e `expr $line + 2`a"AS=\${CROSS}as" $FILE
  105. sed -i -e `expr $line + 3`a"LD=\${CROSS}ld" $FILE
  106. sed -i -e `expr $line + 4`a"RANLIB=\${CROSS}ranlib" $FILE
  107. fi

  108. make && cd -
  109. fi

  110. # | -----------------------------
  111. # | Cross compile redir-2.2.1
  112. # | -----------------------------

  113. if [ ! -d redir-2.2.1 ] ; then
  114. tar -xzf redir-2.2.1.tar.gz
  115. fi

  116. if [ -d redir-2.2.1 ]; then
  117. cd redir-2.2.1
  118. FILE=Makefile
  119. sed -i -e s":^CC = gcc$:CC = ${CROSS}gcc:" $FILE //这里选用":"作为sed 分隔符
  120. make && cd -
  121. fi


  122. 二,一些常用的alias:

  123. alias vt100='export TERM=vt100'
  124. alias linux='export TERM=linux'
  125. alias maek='make'
  126. alias rmsvn='find -name .svn -exec rm -rf {} \;'
  127. alias rmgdb='find -iname "*.gdb" -exec rm -rf {} \;'
  128. alias rmdep='find -name .depend -exec rm -rf {} \;'
  129. alias myindent='indent -npro -kr -bl -nce -bli0 -i2 -ts2 -sob -l80 -nfc1 -ss -ncs'
  130. alias myctages='ctags --c-kinds=+defglmnstuvx --langmap=c:.c.h.ho.hem.het.hec.hev.him.hit.hic.hiv -R .'

  131. alias nocvim='mv ~/.vimrc ~/.vimrcb'
  132. alias cvim='mv ~/.vimrcb ~/.vimrc'
  133. alias mntwinxp='sudo mount -t cifs -o username="username",password="password" //Winxp_ipaddr/linux /home/username/winxp/'



  134. 用于在文件中查找的脚本:
  135. #!/bin/sh
  136. # Description: This shell script used to grep the "key" in all the files
  137. find -iname "*$suffix" | xargs grep "$key"
  138. find -iname "*$suffix" | xargs grep "\<$key\>"
  139. # in current folder.
  140. # Author: guowenxue(guowenxue@gmail.com)
  141. # Version: 1.0.0 (Release by guowenxue on 04th Feb. 2010)
  142. # ChangeLog: None
  143. #

  144. if [ $# -lt 1 ] ; then
  145. echo " Usage: $0 key [-g] [suffix]"
  146. echo "Example1: mygrep haha"
  147. echo "Example2: mygrep haha -g"
  148. echo "Example1: mygrep haha *.c"
  149. echo "Example1: mygrep haha -g *.c"
  150. exit;
  151. fi

  152. key=$1 #The grep key

  153. if [ $# = 1 ] ; then
  154. grep -n "$key" -r *
  155. elif [ $# = 2 ] ; then
  156. if [ $2 = "-g" ] ; then
  157. grep -n "\<$key\>" -r *
  158. else
  159. suffix=$2
  160. find -iname "$suffix" | xargs grep -n "$key"
  161. fi
  162. else # Arguments more than 3
  163. if [ $2 = "-g" ] ; then
  164. suffix=$3

  165. elif [ $3 = "-g" ]; then
  166. suffix=$2
  167. fi

  168. find -iname "$suffix" | xargs grep -n "\<$key\>"
  169. fi


  170. [guowenxue@localhost drivers]$ mygrep 15000400
  171. csps/lpc313x/include/lpc313x_chip.h:#define LCD_INTERFACE_BASE 0x15000400
  172. [guowenxue@localhost drivers]$ mygrep 15000400 .h
  173. ./csps/lpc313x/include/lpc313x_chip.h:#define LCD_INTERFACE_BASE 0x15000400
  174. [guowenxue@localhost drivers]$ mygrep 15000400 .h -g
  175. [guowenxue@localhost drivers]$ mygrep 15000400 -g .h

  176. Sed命令去掉补丁文件中首字符"+",获取C代码文件:
  177. [guowenxue@localhost spi]$ sed -i 's/^+//' tsc2046.h


  178. 清除所有ARP缓存表:
  179. for ip in `seq 1 6`; do arp -d 192.168.5.$ip; done
阅读(3528) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~