Chinaunix首页 | 论坛 | 博客
  • 博客访问: 82266
  • 博文数量: 15
  • 博客积分: 315
  • 博客等级: 二等列兵
  • 技术积分: 180
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-28 08:37
文章分类
文章存档

2012年(2)

2011年(13)

我的朋友

分类: LINUX

2011-12-12 15:46:16

  1. apt-get install checkinstall*
  2. 进入源码包
  3. 如果源码包没有打包的话,可以用一下命令进行源码打包:
  4. 示例:
  5. Autoconf/Automake工具用于自动创建功能完善的makefile文件。当前大多数软件包都是用这一工具生成makefile文件的。本节首先介绍Autoconf/Automake工具的功能以及makefile创建过程中所涉及的文件和命令。最后以一个实例介绍如何使用Autoconf/Automake工具自动创建makefile文件。
  6. Autoconf/Automake工具组简介
  7. Autoconf/Automake工具组主要包括autoconf、automake、perl语言环境和m4。其中FC4默认安装的autoconf和automake软件包信息如下:
  8. [root@localhost hello]# rpm -qa |grep autoconf //查看是否安装autoconf
  9. autoconf-2.59-5
  10. [root@localhost hello]# rpm -qa |grep automake //查看是否安装automake
  11. automake14-1.4p6-12
  12. automake-1.9.5-1
  13. automake17-1.7.9-6
  14. automake15-1.5-13
  15. automake16-1.6.3-5
  16. 默认安装的perl语言环境如下:
  17. [root@localhost ~]# rpm -qa |grep perl //
  18. 查看perl的安装情况,已经安装后才有以下信息
  19. perl-Filter-1.30-7
  20. perl-URI-1.35-2
  21. perl-HTML-Tagset-3.04-1
  22. perl-libwww-perl-5.803-2
  23. perl-XML-Encoding-1.01-27
  24. perl-XML-NamespaceSupport-1.08-7
  25. perl-Crypt-SSLeay-0.51-6
  26. perl-XML-Grove-0.46alpha-27
  27. perl-5.8.6-15
  28. perl-DateManip-5.42a-4
  29. perl-HTML-Parser-3.45-1
  30. perl-Compress-Zlib-1.34-2
  31. perl-XML-Parser-2.34-6
  32. perl-XML-Dumper-0.71-4
  33. perl-libxml-enno-1.02-31
  34. perl-Convert-ASN1-0.19-1
  35. perl-XML-SAX-0.12-7
  36. perl-LDAP-0.33-1
  37. perl-XML-LibXML-1.58-2
  38. perl-XML-Twig-3.17-1
  39. perl-Parse-Yapp-1.05-33
  40. perl-libxml-perl-0.08-1
  41. perl-XML-LibXML-Common-0.13-8
  42. 默认安装的m4软件包如下:
  43. [root@localhost ~]# rpm -qa |grep m4 //查看是否安装m4工具
  44. m4-1.4.3-1
  45. 如果读者没有获得以上任何一个软件包的完全安装,请直接插入FC4安装盘,使用"system-config-packages"命令更新,在开发工具中选中以上选项即可。
  46. 以下命令用来查看本节所使用的Autoconf/Automake命令所在位置:
  47. [root@localhost hello]# whereis aclocal //查看aclocal命令所在位置
  48. aclocal: /usr/bin/aclocal /usr/share/aclocal
  49. [root@localhost hello]# whereis autoscan //查看autoscan命令所在位置
  50. autoscan: /usr/bin/autoscan /usr/share/man/man1/autoscan.1.gz
  51. [root@localhost hello]# whereis autoconf //查看autoconf命令所在位置
  52. autoconf: /usr/bin/autoconf /usr/share/autoconf /usr/share/man/man1/autoconf.1.gz
  53. [root@localhost hello]# whereis autoheader //查看autoheader命令所在位置
  54. autoheader: /usr/bin/autoheader /usr/share/man/man1/autoheader.1.gz
  55. [root@localhost hello]# whereis automake //查看automake命令所在位置
  56. automake: /usr/bin/automake /usr/local/automake
  57. 使用Autoconf/Automake工具自动生成Makefile文件的流程图如图2-5所示。在此过程中使用的命令主要有aclocal、autoscan、autoconf、autoheader和automake。由图可知运行步骤如下:
  58. (1)创建源代码文件,使用"autoscan"生成configure.scan文件,将其重命名为configure.ac,并做适当修改,然后使用"aclocal"命令生成aclocal.m4文件,使用"autoconf"命令由configure.ac和aclocal.m4文件生成configure文件。
  59. (2)手工编辑Makefile.am文件,使用"automake"命令生成configure.in文件。
  60. (3)手工编辑或由系统给定acconfig.h文件,使用"autoheader"命令生成config.h.in文件。
  61. (4)使用"configure"命令由configure、configure.in和config.h.in文件生成Makefile文件。从而完成Makefile文件的创建过程。
  62. 下面以自动编译hello.c程序为例介绍如何使用这组工具生成makefile文件。
  63. 1.使用Vi编辑器编辑源程序
  64. 在Linux操作Shell提示符使用Vi编辑器下创建hello.c源程序。
  65. [root@localhost ch0206]# mkdir hello //创建文件夹
  66. [root@localhost ch0206]# cd hello //切换文件
  67. [root@localhost hello]# ls //已经创建的hello.c文件
  68. hello.c
  69. [root@localhost hello]# cat hello.c //C源程序代码
  70. int main(int argc,char** argv)
  71. {
  72. printf("hello!GNU\n");
  73. return 0;
  74. }
  75. 2.使用Autoscan工具生成configure.ac文件
  76. Autoscan工具用来扫描源代码以搜寻一般的可移植性问题,比如检查编译器、库和头文件等,并创建configure.scan文件,它会在给定目录及其子目录树中检查源文件,若没有给出目录,就在当前目录及其子目录树中进行检查。如下所示:
  77. [root@localhost hello]# autoscan .///在当前文件夹中搜索
  78. autom4te: configure.ac: no such file or directory
  79. autoscan: /usr/bin/autom4te failed with exit status: 1
  80. [root@localhost hello]# ls //生成configure.scan文件,它是configure.ac文件原型
  81. autoscan.log configure.scan hello.c
  82. [root@localhost hello]# cat configure.scan //configure.scan文件内容
  83. # -*- Autoconf -*-
  84. # Process this file with autoconf to produce a configure script.
  85. AC_PREREQ(2.59) //autoconf版本号
  86. AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS) //软件的名称和版本等信息
  87. AC_CONFIG_SRCDIR([hello.c]) //侦测源码文件
  88. AC_CONFIG_HEADER([config.h]) //用于生成config.h文件
  89. # Checks for programs.
  90. AC_PROG_CC //编译器
  91. # Checks for libraries.
  92. # Checks for header files.
  93. # Checks for typedefs, structures, and compiler characteristics.
  94. # Checks for library functions.
  95. AC_OUTPUT //输入文件名
  96. 下面给出本文件的简要说明(所有以"#"号开始的行为注释):
  97. (1)AC_PREREQ宏声明本文件要求的autoconf版本,本例使用的版本为2.59。
  98. (2)AC_INIT宏用来定义软件的名称和版本等信息,"FULL-PACKAGE-NAME"为软件包名称,"VERSION"为软件版本号,"BUG-REPORT-ADDRESS"为BUG报告地址(一般为软件作者邮件地址)。
  99. (3)AC_CONFIG_SRCDIR宏用来侦测所指定的源码文件是否存在,来确定源码目录的有效性。此处为当前目录下的hello.c。
  100. (4)AC_CONFIG_HEADER宏用于生成config.h文件,以便autoheader使用。
  101. (5)AC_PROG_CC用来指定编译器,如果不指定,选用默认gcc。
  102. (6)AC_OUTPUT用来设定 configure 所要产生的文件,如果是makefile,configure会把它检查出来的结果带入makefile.in文件产生合适的makefile。使用Automake时,还需要一些其他的参数,这些额外的宏用aclocal工具产生。
  103. 中间的注释可以分别添加用户测试程序、测试函数库和测试头文件等宏定义。
  104. 此文件只是下面要使用的configure.ac文件的原型,要使用此文件,还需要根据情况修改相关内容。
  105. [root@localhost hello]# cp configure.scan configure.ac //复制文件
  106. [root@localhost hello]# ls
  107. autoscan.log configure.ac configure.scan hello.c
  108. [root@localhost hello]# cat configure.ac
  109. # -*- Autoconf -*-
  110. # Process this file with autoconf to produce a configure script.
  111. AC_PREREQ(2.59)
  112. AC_INIT(hello,1.0,yangzongde@163.com) //在此行内容中设置当前软件包信息
  113. AM_INIT_AUTOMAKE(hello,1.0) //automake所必备的宏,必须添加
  114. AC_CONFIG_SRCDIR([hello.c]) //源文件名
  115. AC_CONFIG_HEADER([config.h]) //config文件
  116. # Checks for programs.
  117. AC_PROG_CC //编译器,可以不指定
  118. # Checks for libraries.
  119. # Checks for header files.
  120. # Checks for typedefs, structures, and compiler characteristics.
  121. # Checks for library functions.
  122. AC_OUTPUT(Makefile) //输出文件名为makefile
  123. 此文件的相关内容需要根据当前软件和系统环境进行配置,但是,AM_INIT_ AUTOMAKE宏需要自己添加,它是automake所必备的宏,同前面一样,PACKAGE是要产生的软件套件的名称,VERSION是版本编号。其他设置请参阅注释内容。
  124. 3.使用aclocal工具生成aclocal.m4
  125. aclocal工具用于扫描configure.ac文件生成aclocal.m4。此工具根据已经安装的宏、用户定义宏和acinclude.m4文件中的宏将configure.ac文件需要的宏集中定义到文件aclocal.m4中。
  126. [root@localhost hello]# aclocal //执行aclocal生成aclocal.m4文件
  127. [root@localhost hello]# ls
  128. aclocal.m4 autom4te.cache autoscan.log configure.ac configure.scan hello.c
  129. 4.使用autoconf工具生成configure文件
  130. 将configure.ac中的宏展开,生成configure脚本。这个过程可能要用到aclocal.m4中定义的宏。
  131. [root@localhost hello]# autoconf //执行autoconf生成configure文件
  132. [root@localhost hello]# ls
  133. aclocal.m4 autoscan.log configure.ac hello.c
  134. autom4te.cache configure configure.scan
  135. 5.使用autoheader工具生成config.h.in文件
  136. autoheader工具负责生成config.h.in文件。该工具会从"acconfig.h"文件中复制用户附加的符号定义。此步骤可以在第3或第4步之前完成。
  137. [root@localhost hello]# find / -name acconfig.h //系统acconfig.h文件位置
  138. /usr/src/kernels/2.6.11-1.1369_FC4-i686/include/acpi/acconfig.h
  139. [root@localhost hello]# autoheader
  140. [root@localhost hello]# ls //查看生成的config.h.in文件
  141. aclocal.m4 autoscan.log configure configure.scan
  142. autom4te.cache config.h.in configure.ac hello.c
  143. 6.创建Makefile.am文件
  144. Automake工具会根据configure.in中的参量把Makefile.am转换成Makefile.in文件。在使用Automake工具前,读者需要手工创建脚本配置文件Makefile.am。本例中,作者创建的文件如下所示:
  145. [root@localhost hello]# ls Makefile.am
  146. Makefile.am
  147. [root@localhost hello]# cat Makefile.am // Makefile.am范例
  148. AUTOMAKE_OPTIONS = foreign //软件等级
  149. bin_PROGRAMS = hello //可执行文件名
  150. hello_SOURCES = hello.c //源文件名
  151. 其中:
  152. (1)AUTOMAKE_OPTIONS为设置Automake的选项。由于GNU对自己发布的软件有严格的规范,比如必须附带许可证声明文件COPYING等,否则Automake执行时会报错。Automake提供了3种软件等级:foreign、gnu和gnits,供用户选择,默认等级为gnu。本例使需用foreign等级,它只检测必须的文件。
  153. (2)bin_PROGRAMS定义要产生的执行文件名。如果要产生多个执行文件,每个文件名用空格隔开。
  154. (3)hello_SOURCES定义"hello"这个执行程序所需要的原始文件。如果"hello"这个程序是由多个原始文件所产生的,则必须把它所用到的所有原始文件都列出来,并用空格隔开。例如:若目标体"hello"需要"hello.c"、"hello.h"两个依赖文件,则定义hello_SOURCES=hello.c hello.h。
  155. 7.使用Automake生成Makefile.in文件
  156. 下面使用Automake生成"Makefile.in"文件,使用选项"--add-missing"可以让Automake自动添加一些必需的脚本文件。如下所示:
  157. [root@localhost hello]# automake --add-missing
  158. configure.ac: installing './install-sh' //创建install-sh文件
  159. configure.ac: installing './missing'
  160. Makefile.am: installing './INSTALL'
  161. Makefile.am: required file './NEWS' not found
  162. Makefile.am: required file './README' not found
  163. Makefile.am: required file './AUTHORS' not found
  164. Makefile.am: required file './ChangeLog' not found
  165. Makefile.am: installing './COPYING'
  166. Makefile.am: installing './depcomp'
  167. [root@localhost hello]# automake --add-missing //再运行一次,可以辅助生成几个必要的文件
  168. Makefile.am: required file './NEWS' not found //没有找到NEWS文件
  169. Makefile.am: required file './README' not found
  170. Makefile.am: required file './AUTHORS' not found
  171. Makefile.am: required file './ChangeLog' not found
  172. [root@localhost hello]# touch NEWS //创建NEWS文件,如果没有自动生成,手工创建
  173. [root@localhost hello]# touch README //创建README文件
  174. [root@localhost hello]# touch AUTHORS //创建AUTHORS文件
  175. [root@localhost hello]# touch ChangeLog //创建ChangeLog文件
  176. [root@localhost hello]# automake --add-missing //再运行一次
  177. [root@localhost hello]# ls //生成必要的文件
  178. aclocal.m4 ChangeLog configure.scan INSTALL missing
  179. AUTHORS config.h.in COPYING install-sh NEWS
  180. autom4te.cache configure depcomp Makefile.am README
  181. autoscan.log configure.ac hello.c Makefile.in
  182. [root@localhost hello]# ls configure.in -l
  183. -rw-r--r-- 1 root root 536 Dec 27 04:29 configure.in
  184. 8.配置
  185. 运行自动配置设置文件configure,把Makefile.in变成最终的Makefile。
  186. [root@localhost hello]# ./configure //配置,生成Makefile文件
  187. ……
  188. config.status: creating Makefile
  189. config.status: executing depfiles commands
  190. [root@localhost hello]# ls
  191. aclocal.m4 ChangeLog config.status COPYING install-sh missing
  192. AUTHORS config.h configure depcomp Makefile NEWS
  193. autom4te.cache config.h.in configure.ac hello.c Makefile.am README
  194. autoscan.log config.log configure.scan INSTALL Makefile.in stamp-h1
  195. [root@localhost hello]# ls -l Makefile*
  196. -rw-r--r-- 1 root root 16876 Dec 27 04:51 Makefile
  197. -rw-r--r-- 1 root root 68 Dec 27 04:46 Makefile.am
  198. -rw-r--r-- 1 root root 17180 Dec 27 04:50 Makefile.in
  199. 9.测试
  200. 运行make命令进行编译,下面的示例中Make的主要编译命令为"gcc -g -O2 -o hello hello.o",此句对应本节前面介绍的手工编辑的Makefile文件内容。
  201. [root@localhost hello]# cd ../hello
  202. [root@localhost hello]# make //执行make命令
  203. make all-am
  204. ……
  205. gcc -g -O2 -o hello hello.o //编译指令
  206. ……
  207. 编译成功后,将在当前目录下生成并运行可执行程序hello。测试源代码是否正确:
  208. [root@localhost hello_2]# ./hello
  209. hello!GNU
  210. 此方法生成的makefile文件很全面。使用"make install"命令把目标文件安装在系统中。
  211. [root@localhost hello]# make install //安装
  212. make[1]: Entering directory '/root/book/ch02/ch0206/hello'
  213. test -z "/usr/local/bin" || mkdir -p -- "/usr/local/bin"
  214. /usr/bin/install -c 'hello' '/usr/local/bin/hello' //安装目标文件
  215. make[1]: Nothing to be done for 'install-data-am'.
  216. make[1]: Leaving directory '/root/book/ch02/ch0206/hello'
  217. 使用"make uninstall"命令把目标文件从系统中卸载。
  218. [root@localhost hello]# make uninstall //卸载命令
  219. rm -f '/usr/local/bin/hello' //从系统中卸载
  220. 使用"make clean"命令清除编译时的obj文件。
  221. [root@localhost hello]# make clean
  222. test -z "hello" || rm -f hello
  223. rm -f *.o //删除obj文件
  224. 使用"make dist"命令将程序和相关的文档打包为一个压缩文档以供发布。
  225. [root@localhost hello]# make dist
  226. ……
  227. [root@localhost hello]# ls //查看生成的文件
  228. aclocal.m4 config.h.in configure.scan install-sh README
  229. AUTHORS config.h.in~ COPYING Makefile stamp-h1
  230. autom4te.cache config.log depcomp Makefile.am
  231. Changelog config.status hello-1.0.tar.gz Makefile.in
  232. ChangeLog configure hello.c missing
  233. config.h configure.ac INSTALL NEWS
  234. [root@localhost hello]# ls hello-1.0.tar.gz -l //打包文件
  235. -rw-r--r-- 1 root root 67699 Dec 27 06:33 hello-1.0.tar.gz
  236. 源码包做好了以后,用以下命令进行deb包的制作!
  237. checkinstall -D --fstrans=yes --inspect --review-spec --review-control
  238. 如果打包不成功的话,在这样
  239. checkinstall -D 安装!
  240. 中间有些选项,需要手动设置,如版本,用途等等!
阅读(1701) | 评论(1) | 转发(3) |
给主人留下些什么吧!~~

78922422011-12-13 01:02:50

好长的教程啊,软件的细节处理过程