




已阅读5页,还剩24页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
文章分类:C+编程 1.autoscan (autoconf): 扫描源代码以搜寻普通的可移植性问题,比如检查编译器,库,头文件等,生成文件configure.scan,它是configure.ac的一个雏形。 your source files - autoscan* - configure.scan - configure.ac2.aclocal (automake):根据已经安装的宏,用户定义宏和acinclude.m4文件中的宏将configure.ac文件所需要的宏集中定义到文件 aclocal.m4中。aclocal是一个perl 脚本程序,它的定义是:“aclocal - create aclocal.m4 by scanning configure.ac” user input files optional input process output files= = = = acinclude.m4 - - - - -. V .-,configure.ac -|aclocal| user macro files -| |- aclocal.m4 -3.autoheader(autoconf): 根据configure.ac中的某些宏,比如cpp宏定义,运行m4,声称config.h.inuser input files optional input process output files= = = = aclocal.m4 - - - - - - - . | V .-,configure.ac -|autoheader|- autoconfig.h.in -4.automake: automake将Makefile.am中定义的结构建立Makefile.in,然后configure脚本将生成的Makefile.in文件转换 为Makefile。如果在configure.ac中定义了一些特殊的宏,比如AC_PROG_LIBTOOL,它会调用libtoolize,否则它 会自己产生config.guess和config.subuser input files optional input processes output files= = = = .-, | | - - - COPYING | | - - - INSTALL | |- install-sh | |- missing |automake|- mkinstalldirsconfigure.ac -| |Makefile.am -| |- Makefile.in | |- stamp-h.in .-+ | - - - config.guess | | | - - - config.sub | -+- | | - - - - config.guess |libtoolize| - - - - config.sub | |- ltmain.sh | |- ltconfig -5.autoconf:将configure.ac中的宏展开,生成configure脚本。这个过程可能要用到aclocal.m4中定义的宏。user input files optional input processes output files= = = =aclocal.m4 ,autoconfig.h.in - - - - - - -. V .-,configure.ac -|autoconf|- configure 6. ./configure的过程 .- config.cache configure* -+- config.log | config.h.in -. v .- autoconfig.h +- config.status* -+ Makefile.in - - Makefile 7. make过程 autoconfig.h -. +- make* - 程序 Makefile - .-, config.site - - -| | config.cache - - -|configure| - - - config.cache | +-, -+- | | |- config.status config.h.in -|config- |- config.h Makefile.in -| .status|- Makefile | |- stamp-h | +-, .-+ | | | -+- | ltmain.sh -|ltconfig|- libtool | | | -+- | |config.guess| | config.sub | -.-, Makefile -| | config.h -| make |project sources -| |- project targets .-+ +-, | - | | libtool | | missing | | install-sh | |mkinstalldirs| -实例:在/hello/目录下创建一个hello.c文件,并编译运行它: #cd /hello/(1) 编写源文件hello.c:#includeint main(int argc, char* argv)printf(Hello, GNU!n);return 0;litaovm0000131 hello$ lltotal 4-rw-rw-r- 1 litao litao 68 Aug 12 12:02 hello.c一、autoscanlitaovm0000131 hello$ autoscanautom4te: configure.ac: no such file or directoryautoscan: /usr/bin/autom4te failed with exit status: 1litaovm0000131 hello$ lltotal 8-rw-rw-r- 1 litao litao 0 Aug 12 12:03 autoscan.log-rw-rw-r- 1 litao litao 457 Aug 12 12:03 configure.scan-rw-rw-r- 1 litao litao 68 Aug 12 12:02 hello.c已经生成了configure.scan,autoscan.log文件将configure.scan 修改为configure.in,最后修改的内容如下:litaovm0000131 hello$ mv configure.scan configure.inlitaovm0000131 hello$ vim configure.in# -*- Autoconf -*-# Process this file with autoconf to produce a configure script.AC_PREREQ(2.59)AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)AC_CONFIG_SRCDIR(hello.c)#AC_CONFIG_HEADER(config.h)AM_INIT_AUTOMAKE(hello, 1.0)# Checks for programs.AC_PROG_CC# Checks for libraries.# Checks for header files.# Checks for typedefs, structures, and compiler characteristics.# Checks for library functions.AC_OUTPUT(Makefile)二、acloacllitaovm0000131 hello$ aclocal生成 aclocal.m4 和 autom4te.cache (生成aclocal.m4的过程中涉及到configure.in)litaovm0000131 hello$ lltotal 44-rw-rw-r- 1 litao litao 31120 Aug 12 12:08 aclocal.m4drwxr-xr-x 2 litao litao 4096 Aug 12 12:08 autom4te.cache-rw-rw-r- 1 litao litao 0 Aug 12 12:03 autoscan.log-rw-rw-r- 1 litao litao 496 Aug 12 12:08 configure.in-rw-rw-r- 1 litao litao 68 Aug 12 12:02 hello.c三、antoconflitaovm0000131 hello$ autoconf生成configure(根据configure.in, 和 aclocal.m4)litaovm0000131 hello$ lltotal 168-rw-rw-r- 1 litao litao 31120 Aug 12 12:08 aclocal.m4drwxr-xr-x 2 litao litao 4096 Aug 12 12:11 autom4te.cache-rw-rw-r- 1 litao litao 0 Aug 12 12:03 autoscan.log-rwxrwxr-x 1 litao litao 122297 Aug 12 12:11 configure-rw-rw-r- 1 litao litao 496 Aug 12 12:08 configure.in-rw-rw-r- 1 litao litao 68 Aug 12 12:02 hello.c四、编写Makefile.am: AUTOMAKE_OPTIONS= foreignbin_PROGRAMS= hellohello_SOURCES= hello.c五、automake 生成 Makefile.in, depcomp, install-sh, 和 missing (根据 Makefile.am, 和 aclocal.m4)litaovm0000131 hello$ automakeconfigure.in: required file ./install-sh not foundconfigure.in: required file ./missing not foundMakefile.am: required file ./depcomp not foundlitaovm0000131 hello$ automake -add-missingconfigure.in: installing ./install-shconfigure.in: installing ./missingMakefile.am: installing ./depcomplitaovm0000131 hello$ lltotal 192-rw-rw-r- 1 litao litao 31120 Aug 12 12:08 aclocal.m4drwxr-xr-x 2 litao litao 4096 Aug 12 12:14 autom4te.cache-rw-rw-r- 1 litao litao 0 Aug 12 12:03 autoscan.log-rwxrwxr-x 1 litao litao 122297 Aug 12 12:11 configure-rw-rw-r- 1 litao litao 496 Aug 12 12:08 configure.inlrwxrwxrwx 1 litao litao 31 Aug 12 12:16 depcomp - /usr/share/automake-1.9/depcomp-rw-rw-r- 1 litao litao 68 Aug 12 12:02 hello.clrwxrwxrwx 1 litao litao 34 Aug 12 12:16 install-sh - /usr/share/automake-1.9/install-sh-rw-rw-r- 1 litao litao 69 Aug 12 12:15 Makefile.am-rw-rw-r- 1 litao litao 16561 Aug 12 12:16 Makefile.inlrwxrwxrwx 1 litao litao 31 Aug 12 12:16 missing - /usr/share/automake-1.9/missing六、configure生成 Makefile, config.log, 和 config.statusautotools系列工具-自动生成Makefile在较大项目中, 如果手动维护Makefile, 那将是一件复杂并痛苦的事情. 那么, 有没有一种轻松的手段生成Makefile呢? autotools系列工具正是在这样的呼声中诞生的. 它只需用户输入简单的目标文件, 依赖文件, 文件目录等就可以轻松地生成Makefile了. 另外, 这些工具还可以完成系统配置信息的收集, 从而可以方便地处理各种移植性问题.autotools是系列工具, 它含有: aclocal autoscan autoconf autoheader automakeautotools 使用流程下面用一个简单的hello.c程序, 演示autotools的使用流程. hello.c如下:wangshengpc01:/work/train/make/automake$ lshello.cwangshengpc01:/work/train/make/automake$ cat hello.c#includeint main() printf(Hello, autotools!n); return 0;(1) 使用autoscan命令自动生成configure.scan文件它会在给定目录及其子目录树中检查源文件, 若没有给出目录, 就在当前目录及其子目录树中进行检查.它会搜索源文件以寻找一般的移植性问题并创建一个文件”configure.scan”, 该文件就是接下来autoconf要用到的”configure.in”原型.wangshengpc01:/work/train/make/automake$ autoscanwangshengpc01:/work/train/make/automake$ lsautoscan.log configure.scan hello.c(2)将configure.scan重命名为configure.in, 并做适当修改configure.scan的内容:wangshengpc01:/work/train/make/automake$ cat configure.scan# -*- Autoconf -*-# Process this file with autoconf to produce a configure script.AC_PREREQ(2.65)AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)AC_CONFIG_SRCDIR(hello.c)AC_CONFIG_HEADERS(config.h)# Checks for programs.AC_PROG_CC# Checks for libraries.# Checks for header files.# Checks for typedefs, structures, and compiler characteristics.# Checks for library functions.AC_OUTPUT将configure.scan重命名为configure.inwangshengpc01:/work/train/make/automake$ mv configure.scan configure.in根据具体情况, 适当修改, 以下加粗部分是修改的内容:wangshengpc01:/work/train/make/automake$ cat configure.in# -*- Autoconf -*-# Process this file with autoconf to produce a configure script.AC_PREREQ(2.65)#AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)AC_INIT(hello,1.0)AM_INIT_AUTOMAKE(hello,1.0)AC_CONFIG_SRCDIR(hello.c)AC_CONFIG_HEADERS(config.h)# Checks for programs.AC_PROG_CC# Checks for libraries.# Checks for header files.# Checks for typedefs, structures, and compiler characteristics.# Checks for library functions.AC_CONFIG_FILES(Makefile)AC_OUTPUT说明: 以”#”号开始的行为注释 AC_PREREQ宏声明本文要求的autoconf版本, 如本例中的版本 2.65 AC_INIT宏用来定义软件的名称和版本等信息, 在本例中省略了BUG-REPROT-ADDRESS, 一般为作者的E-mail AM_INIT_AUTOMAKE是手动添加的, 它是automake所必备的宏, 也同前面一样, PACKAGE是所要产生软件套件的名称,VERSION是版本编号. AC_CONFIG_SCRDIR宏用来侦测所指定的源码文件是否存在, 来确定源码目录的有效性. 在此处指当前目录下hello.c AC_CONFIG_FILES宏用于生成相应的Makefile文件.(3) 运行aclocal命令,生成”aclocal.m4文件, 该文件主要处理本地的宏定义wangshengpc01:/work/train/make/automake$ aclocalwangshengpc01:/work/train/make/automake$ lsaclocal.m4 autom4te.cache autoscan.log configure.in hello.c(4) 运行autoconf命令生成configure可执行文件wangshengpc01:/work/train/make/automake$ autoconfwangshengpc01:/work/train/make/automake$ lsaclocal.m4 autom4te.cache autoscan.log configure configure.in hello.c(5) 运行autoheader命令, 生成config.h.in文件.该工具通常会从”acconfig.h”文件中复制用户附加的符号定义. 本例中没有附加的符号定义, 所以不需要创建”acconfig.h”文件.wangshengpc01:/work/train/make/automake$ autoheaderwangshengpc01:/work/train/make/automake$ lsaclocal.m4 autom4te.cache autoscan.log config.h.in configure configure.in hello.c(6) 运行automake命令, 生成Makefile.in文件这一步是创建Makefile很重要的一步, automake要用的脚本配置文件是Makefile.am, 用户需要自己创建相应的文件. 之后, automake工具将自动转换成Makefile.in 本例中, 创建的文件为Makefile.am, 内容如下:wangshengpc01:/work/train/make/automake$ cat Makefile.amAUTOMAKE_OPTIONS=foreignbin_PROGRAMS=hellohello_SOURCES=hello.c说明: 其中的AUTOMAKE_OPTIONS为设置automake的选项. 由于GNU对自己发布的软件有严格的规范, 比如必须附带许可证声明文件COPYING等, 否则automake执行时会报错. automake提供了3中软件等级:foreign, gnu和gnits, 供用户选择. 默认级别是gnu. 在本例中, 使用了foreign等级, 它只检测必须的文件. bin_PROGRAMS定义要产生的执行文件名. 如果要产生多个执行文件, 每个文件名用空格隔开 hello_SOURCES 定义”hello”这个可执行程序所需的原始文件. 如果”hello”这个程序是由多个源文件所产生的, 则必须把它所用到的所有源文件都列出来, 并用空格隔开. 如果要定义多个可执行程序, 那么需要对每个可执行程序建立对应的file_SOURCES.在这里使用”add-missiing”选项可以让automake自动添加一些必须的脚本文件.wangshengpc01:/work/train/make/automake$ automake -add-missingconfigure.in:7: installing ./install-shconfigure.in:7: installing ./missingMakefile.am: installing ./depcompwangshengpc01:/work/train/make/automake$ lsaclocal.m4 autoscan.log configure depcomp install-sh Makefile.inautom4te.cache config.h.in configure.in hello.c Makefile.am missing(7)运行configure, 生成Makfefile文件wangshengpc01:/work/train/make/automake$ ./configurechecking for a BSD-compatible install. /usr/bin/install -cchecking whether build environment is sane. yeschecking for a thread-safe mkdir -p. /bin/mkdir -pchecking for gawk. gawkchecking whether make sets $(MAKE). yeschecking for gcc. gccchecking whether the C compiler works. yeschecking for C compiler default output file name. a.outchecking for suffix of executables.checking whether we are cross compiling. nochecking for suffix of object files. ochecking whether we are using the GNU C compiler. yeschecking whether gcc accepts -g. yeschecking for gcc option to accept ISO C89. none neededchecking for style of include used by make. GNUchecking dependency style of gcc. gcc3configure: creating ./config.statusconfig.status: creating Makefileconfig.status: creating config.hconfig.status: executing depfiles commandswangshengpc01:/work/train/make/automake$ lsaclocal.m4 config.h config.status depcomp Makefile missingautom4te.cache config.h.in configure hello.c Makefile.am stamp-h1autoscan.log config.log configure.in install-sh Makefile.inautotools生成Makefile流程图如下:使用由autotools生成的Makefileautotools生成的Makefile具有以下主要功能:(1) make编译源程序, 键入make, 默认执行”make all”命令wangshengpc01:/work/train/make/automake$ makemake all-ammake1: Entering directory /home/wangsheng/work/train/make/automakegcc -DHAVE_CONFIG_H -I. -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.cmv -f .deps/hello.Tpo .deps/hello.Pogcc -g -O2 -o hello hello.omake1: Leaving directory /home/wangsheng/work/train/make/automake此时在本目录下就生成了可执行文件”hello”, 运行”./hello”就能看到程序的执行结果:wangshengpc01:/work/train/make/automake$ ./helloHello, autotools!(2) make install执行该命令, 可以把程序安装到系统目录中wangshengpc01:/work/train/make/automake$ sudo make install此时, 直接在console输入hello, 就可以看到程序的运行结果(3) make clean清除之前所编译的可执行文件及目标文件wangshengpc01:/work/train/make/automake$ make cleantest -z hello | rm -f hellorm -f *.o(4) make dist将程序和相关的文档打包为一个压缩文档以供发布wangshengpc01:/work/train/make/automake$ make distwangshengpc01:/work/train/make/automake$ ls -l hello-1.0.tar.gzhello-1.0.tar.gz可见该命令生成了一个hello-1.0.tar.gz的压缩文档.4.2 编辑 Makefile.am 档 接下来我们要编辑 Makefile.am 档,Automake 会根据 configure.in 中 的巨集把Makefile.am 转成 Makefile.in 档。Makefile.am 档定义我们所 要产的目标: AUTOMAKE_OPTIONS 设定 automake 的选项。Automake 主要是帮助开发 GNU 软体的人员 维护软体套件,所以在执行 automake 时,会检查目录下是否存在标 准 GNU 软体套件中应具备的文件档案,例如 NEWS、AUTHOR、 ChangeLog 等文件档。设成 foreign 时,automake 会改用一般软 体套件的标准来检查。 bin_PROGRAMS 定义我们所要产生的执行档档名。如果要产生多个执行档,每个档名 用空白字元隔开。 hello_SOURCES 定义 hello 这个执行档所需要的原始档。如果 hello 这个程序 是由多个原始档所产生,必须把它所用到的原始档都列出来,以空白 字元隔开。假设 hello 这个程序需要 hello.c、main.c、 hello.h 三个档案的话,则定义 hello_SOURCES= hello.c main.c hello.h 如果我们定义多个执行档,则对每个执行档都要定义相对的 filename_SOURCES。 编辑好 Makefile.am 档,就可以用 automake -add-missing 来产生 Makefile.in。加上 -add-missing 选项是告诉 automake 顺便帮我们加 入包装一个软体套件所必备的档案。Automake 产生出来的 Makefile.in 档是完全符合 GNU Makefile 的惯例,我们只要执行 configure 这个 shell script 便可以产生合适的 Makefile 档了。configure.inMakefile.am解析(2010-04-07 13:25:01) 引用自:/u/22878/showart_421774.html用前面所介绍的基本概念,已经可以编译全功能的Gtk+/Gnome应用程序了。但是还有一个大问题:如何配置编译选项?一些实用工具如automake、autoconf、libtool等,可以用来简化这一过程。为了方便维护,同时,也是为了便于使用这些实用工具,应该在编写代码时遵从一些约定。如果要将程序发布为自由软件,最好能使程序源代码的目录结构遵从“GNU项目编码标准”。即使应用程序是私有的商用程序,不想公开源代码,从技术上来说,这么做也是一个非常好的选择,因为这些标准都是经过实践检验,能够让你节省大量的时间和精力。另外还应该在程序代码中包含INSTALL、README的文件。2.11.1生成源代码树差不多所有的Gnome应用程序都使用同样的基于GNU工具automake、autoconf和libtool的编译系统。Gtk+和 Gnome提供了一套autoconf宏,用于生成可移植的、符合标准的编译设置。我们用一个称GnomeHello的应用程序来演示Gnome的特性。Gnome应用程序遵从一系列的约定来生成源代码树和发布的tar文件,大多数约定被自由软件社区广泛使用。这些约定的许多方面已经在“GNU项目编码标准”(GNUProjectsCodingStandards/prep/standards_toc.html)和Linux文件系统层次标准 (LinuxFilesystemHierarchyStandard:/fhs/)中正式化了。GNU 工具集,包括automake和autoconf使遵从这些标准变得很容易。然而,有时候你可能不想使用GNU工具集,例如,你也许需要一个统一的在 Windows和MacOS平台上都能工作的编译工具(一些工具确实能在Windows平台上工作,它们使用Cygnus的“Cygwin”环境,参看 /cygwin)。如果使用了autoconf和automake,除了编译应用程序,用户并不需要有这些工具。使用这些工具的目的是创建能在用户环境使用的、可移植的shell脚本和Makefile文件。Autoconf实际上是一个工具集,其中包含aclocal、autoheader和autoconf等可执行文件。这些工具生成一个可移植的shell脚本configure,configure和软件包一起发布给用户。它探查编译系统,生成 Makefile文件和一个特殊的头文件config.h。由configure生成的文件能适应用户系统的特定环境。configure脚本从一个称为 Makefile.in的模板文件生成每个Makefile文件。automake由一个手写的Makefile.am生成Makefile.in文件。Makefile.in文件随软件一同发布,当用户运行 configure时会自动生成Makefile。
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高压电工考试题库:2025年高压试验技术操作典型题库
- 2025年大学国内安全保卫专业题库- 安全保卫专业学生的专业素质要求分析
- 2025年大学人文教育专业题库- 大学人文教育对学生的影响
- 2025年大学劳动教育专业题库- 劳动教育在大学生综合能力培养中的应用
- 2025年消防员职业技能考试:消防安全隐患识别与排除试题型
- 2025年大学劳动教育专业题库- 劳动教育与学生创新能力培养
- 2025年大学体育教育专业题库- 体育教学的理论研究与实践应用
- 2025年床边护理技能实操综合考核测试题答案及解析
- 2025年监理工程师职业能力测试卷:建筑工程施工监理进度控制标准试题
- 2025年大学武术与民族传统体育专业题库- 大学武术比赛的技战术与表演技能
- 【高二 拓展阅读-科技】Wind Energy
- 新版出口报关单模板
- 员工工资条模板
- 新教科版科学六年级上册知识点
- 初中历史小论文现状分析与写作探讨
- 新疆地方史课件
- 一粒种子旅行
- GB/T 9124-2010钢制管法兰技术条件
- GB 4287-1992纺织染整工业水污染物排放标准
- 腰椎间盘突出症课件
- 桂阳县中小幼教师资格定期注册工作指南专家讲座
评论
0/150
提交评论