⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cvs, automake与autoconf简介.htm

📁 Makefile编程及相关资料的介绍与入门。很适合初学者的学习与借鉴
💻 HTM
📖 第 1 页 / 共 5 页
字号:
                              CVSROOT=":ext:joe@www.minigui.org:/home/minigui" 
                              <BR><BR>$ cvs co miniguiexec03 <BR><A 
                              href="mailto:joe@192.9.200.75">joe@192.9.200.75</A>'s 
                              password: <BR><BR>输入密码,就可以得到一份miniguiexec03的拷贝了。 
                              <BR><BR><BR>总结 
                              <BR>以上只是一个简介,cvs还有很多高级功能,如果您需要更详细的信息,请看cvs 
                              的info或者到gnu上下载html版本的manual。 <BR><BR>第二部分 
                              使用Automake,Autoconf生成Makefile <BR>在Unix上写过程序的人尤其是用 
                              C 来开发程序的人一般都遇到过 Makefile,用 make 
                              来开发和编译程序的确很方便,可是要写出一个Makefile就不那么简单了。GNU Make 
                              那份几百页的文件,让许多人害怕。当然,现在关于make的文档比较多,不过写一个Makefile总是一件很烦人的事情,GNU 
                              Autoconf 及 Automake 这两个软件就是帮助程序开发者轻松产生Makefile 
                              文件的。现在的GNU软件如Apache, MySQL 
                              Minigui等都是利用Autoconf,Automake实现自动编译的。用户只要使用 
                              “./configure”, “make”, “make install” 
                              就可以把程序安裝到系统中。 <BR><BR>简介 <BR>Makefile 
                              基本上就是『目标』(target), 『关联』(dependencies) 
                              和『动作』三者所组成的一系列规则。而 make 就是根据 Makefile 的规则决定如何编译 
                              (compile) 和连接 (link) 程序或者其它动作。当然,make 
                              可做的不只是编译和连接程序,例如 FreeBSD 的 port collection 
                              中,Makefile还可以做到自动下载远程程序,解压缩 (extract) , 打补丁 
                              (patch),设定,然后编译,安装到系统中。 <BR><BR>Makefile 
                              基本结构虽然很简单,但是妥善运用这些规则就可以变换出许多不同的花样。却也因为这样,许多人刚开始学写Makefile 
                              时会觉得没有规范可以遵循,每个人写出来的Makefile都不大一样,不知道从哪里下手,而且常常会受到开发环境的限制,只要环境参数不同或者路径更改,可能 
                              Makefile 就得跟着修改。虽然有GNU Makefile Conventions (GNU 
                              Makefile惯例)制订出一些在进行 GNU 程序设计时写 Makefile 
                              的一些标准和规范,但是其内容很长而且很复杂,并且经常作一些调整,为了减轻程序开发人员维护Makefile 
                              的负担,就出现了Automake。 
                              <BR><BR>利用Automake,编程者只需要写一些预先定义好的宏 
                              (macro),提交给Automake处理,就会产生一个可以供 Autoconf 使用的 
                              Makefile.in文件。再配合使用 Autoconf产生的自动配置文件 configure 
                              即可产生一份符合 GNU Makefile 惯例的 Makeifle 了。 
                              <BR><BR><BR>  <BR><BR>需要的软件 <BR>在开始使用 Automake 
                              之前,首先确认你的系统安装有如下软件: <BR><BR>1. GNU Automake <BR>2. 
                              GNU Autoconf <BR>3. GNU m4 <BR>4. perl <BR>5. GNU 
                              Libtool (如果你需要产生 shared library) <BR><BR>最好也使用 GNU 
                              C/C++ 编译器 、GNU Make 以及其它 GNU 
                              的工具程序来作为开发的环境,这些工具都是属于 Open Source Software 
                              不但免费而且功能强大。如果你是使用 Red Hat Linux 可以找到所有上述软件的 rpm 
                              文件。  <BR><BR>一个简单的例子 <BR>Automake 所产生的 Makefile 
                              除了可以做到程序的编译和连接,也可以用来生成文档(如 manual page, info 
                              文件等),还可以有把源码文件包装起来以供发布,所以程序源代码所存放的目录结构最好符合GNU 
                              的标准惯例,接下来就用一个hello.c 來做为例子。 
                              <BR><BR>在工作目录下建立一个新的子目录devel,再在 devel 
                              下建立一个"hello"' 的子目录,这个目录将 <BR>作为存放 
                              hello这个程序及其相关文件的地方: <BR><BR>% mkdir devel;cd 
                              devel;mkdir hello;cd hello 
                              <BR><BR>用编辑器写一个hello.c文件, <BR><BR>#include 
                              &lt;stdio.h&gt; <BR>int main(int argc, char** 
                              argv) <BR>{ <BR>printf(“Hello, GNU!n”); <BR>return 
                              0; <BR>} <BR><BR>接下来就要用 Autoconf 及 Automake 來产生 
                              Makefile 文件了, <BR><BR>1. 用 autoscan 产生一个 
                              configure.in 的原型,执行autoscan 后会产生一个configure.scan 
                              的文件,可以用它作为 configure.in文件的蓝本。 <BR>  <BR>% autoscan 
                              <BR>% ls <BR>configure.scan hello.c <BR><BR>2. 编辑 
                              configure.scan文件,如下所示,並且改名为configure.in 
                              <BR><BR>dnl Process this file with Autoconf to 
                              produce a configure script. <BR>AC_INIT(hello.c) 
                              <BR>AM_INIT_AUTOMAKE(hello, 1.0) <BR>dnl Checks 
                              for programs. <BR>AC_PROG_CC <BR>dnl Checks for 
                              libraries. <BR>dnl Checks for header files. 
                              <BR>dnl Checks for typedefs, structures, and 
                              compiler characteristics. <BR>dnl Checks for 
                              library functions. <BR>AC_OUTPUT(Makefile) 
                              <BR><BR>3. 执行 aclocal 和 Autoconf ,分別会产生 aclocal.m4 
                              及 configure 两个文件 <BR><BR>% aclocal <BR>% Autoconf 
                              <BR>% ls <BR>aclocal.m4 configure configure.in 
                              hello.c <BR><BR>4. 编辑 Makefile.am 文件,內容如下 
                              <BR><BR>AUTOMAKE_OPTIONS= foreign 
                              <BR>bin_PROGRAMS= hello <BR>hello_SOURCES= hello.c 
                              <BR><BR>5. 执行 Automake --add-missing ,Automake 
                              会根据Makefile.am 文件产生一些文件,包含最重要的Makefile.in 
                              <BR><BR>% Automake --add-missing <BR>Automake: 
                              configure.in: installing `./install-sh' 
                              <BR>Automake: configure.in: installing 
                              `./mkinstalldirs' <BR>Automake: configure.in: 
                              installing `./missing' <BR><BR>6. 最后执行 
                              ./configure: <BR><BR>% ./configure <BR>creating 
                              cache ./config.cache <BR>checking for a BSD 
                              compatible install... /usr/bin/install -c 
                              <BR>checking whether build environment is sane... 
                              yes <BR>checking whether make sets ${MAKE}... yes 
                              <BR>checking for working aclocal... found 
                              <BR>checking for working Autoconf... found 
                              <BR>checking for working Automake... found 
                              <BR>checking for working autoheader... found 
                              <BR>checking for working makeinfo... found 
                              <BR>checking for gcc... gcc <BR>checking whether 
                              the C compiler (gcc ) works... yes <BR>checking 
                              whether the C compiler (gcc ) is a 
                              cross-compiler... no <BR>checking whether we are 
                              using GNU C... yes <BR>checking whether gcc 
                              accepts -g... yes <BR>updating cache 
                              ./config.cache <BR>creating ./config.status 
                              <BR>creating Makefile <BR><BR>$ ls <BR>Makefile 
                              aclocal.m4 config.status hello.c mkinstalldirs 
                              <BR>Makefile.am config.cache configure install-sh 
                              <BR>Makefile.in config.log configure.in missing 
                              <BR><BR>現在你的目录下已经产生了一个 Makefile 文件,输入make指令就可以编译 
                              hello.c 了! <BR><BR>% make <BR>gcc 
                              -DPACKAGE="hello" -DVERSION="1.0" -I. -I. -g -O2 
                              -c hello.c <BR>gcc -g -O2 -o hello hello.o 
                              <BR><BR>你还可以试试 “make clean“,”make install“,”make 
                              dist“: <BR>[root@localhost hello]# make clean 
                              <BR>test -z "hello " || rm -f hello <BR>rm -f *.o 
                              core *.core <BR>[root@localhost hello]# make 
                              install <BR>gcc -DPACKAGE="hello" -DVERSION="1.0" 
                              -I. -I. -g -O2 -c hello.c <BR>gcc -g -O2 -o hello 
                              hello.o <BR>make[1]: Entering directory 
                              `/home/joe/devel/hello' <BR>/bin/sh 
                              ./mkinstalldirs /usr/local/bin 
                              <BR>/usr/bin/install -c hello /usr/local/bin/hello 
                              <BR>make[1]: Nothing to be done for 
                              `install-data-am'. <BR>make[1]: Leaving directory 
                              `/home/joe/devel/hello' <BR>[root@localhost 
                              hello]# make dist <BR>rm -rf hello-1.0 <BR>mkdir 
                              hello-1.0 <BR>chmod 777 hello-1.0 <BR>here=`cd . 
                              &amp;&amp; pwd`; <BR>top_distdir=`cd hello-1.0 
                              &amp;&amp; pwd`; <BR>distdir=`cd hello-1.0 
                              &amp;&amp; pwd`; <BR>cd . <BR>&amp;&amp; Automake 
                              --include-deps --build-dir=$here --srcdir-name=. 
                              --output-dir=$top_distdir --foreign Makefile 
                              <BR>chmod -R a+r hello-1.0 <BR>GZIP=--best gtar 
                              chozf hello-1.0.tar.gz hello-1.0 <BR>rm -rf 
                              hello-1.0 <BR>一切工作得很好! 当然,在make 
                              install时由于需要向系统目录拷贝文件,您需要有root权限。 <BR><BR>更进一步 
                              <BR>上述产生Makefile 的过程和以往自行编写的方式非常不一样,使用 Automake 
                              只需用到一些已经定义好的宏就可以了。我们把宏及目标 (target)写在Makefile.am 
                              文件内,Automake 读入 Makefile.am 
                              文件后会把这一串已经定义好的宏展开并产生相对应的 <BR>Makefile.in 
                              文件,然后再由configure这个 shell script 根据 Makefile.in 
                              产生合适的Makefile。 <BR>具体流程如下所示: <BR>代码 --&gt; 
                              [autoscan*] --&gt; [configure.scan] --&gt; 
                              configure.in <BR>configure.in --. .------&gt; 
                              Autoconf* -----&gt; configure <BR>+---+ 
                              <BR>[aclocal.m4] --+ `---. <BR>[acsite.m4] ---' | 
                              <BR>+--&gt; [autoheader*] -&gt; [config.h.in] 
                              <BR>[acconfig.h] ----. | <BR>+-----' 
                              <BR>[config.h.top] --+ <BR>[config.h.bot] --' 
                              <BR><BR>Makefile.am --&amp;#61664; [Autoconf*] 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -