标签:
autotools是个系列工具,主要由autoconf、automake、perl语言环境和m4等组成,所包含的命令有5个:
下图是autotools使用的流程图:
autotools的安装:
apt-get install autoconf automake autotools-dev m4
autotools使用简单实例如下:
mkdir demo_conf vi hello.cpp内容如下:
#include <iostream> using namespace std; int main(){ cout << "hello\n"; }
$ autoscan $ ls autoscan.log configure.scan hello.cpp
$ mv configure.scan configure.ac vi configure.ac修改后的内容如下:
# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ([2.68]) AC_INIT(hello, 1.0, zhunian0322@163.com) AC_CONFIG_SRCDIR([hello.cpp]) AC_CONFIG_HEADERS([config.h]) AM_INIT_AUTOMAKE(hello,1.0) # Checks for programs. AC_PROG_CXX # Checks for libraries. # Checks for header files. # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. AC_CONFIG_FILES([Makefile]) AC_OUTPUTconfigure.ac文件说明:
AC_PREREQ 声明本文要求的autoconf版本.如本例中的版本2.68 AC_INIT 用来定义软件的名称、版本、作者E-mail等 AC_CONFIG_SRCDIR 用来侦测所制定的源码文件是否存在,确定源码目录的有效性。此处为当前目录下的hello.cpp AC_CONFIG_HEADERS 用于生成config.h文件,以便autoheader命令使用 AM_INIT_AUTOMAKE 是通过手动添加的,他是automake所必备的宏,用于指定软件名和软件版本号 AC_PROC_CXX 用来指定编译器。此处是g++ AC_PROC_CC是gcc AC_CONFIG_FILES 用于生成相应的Makefile文件 AC_OUTPUT 用来设定configure 所要产生的文件,如果是Makefile,configure 会把它检查出来的结果带入makefile.in文件产生何时的Makefile。使用automake时,还需要一些其他的参数,这些额外的宏用aclocal工具产生
$ aclocal $ ls aclocal.m4 autom4te.cache autoscan.log configure.ac hello.cpp
$ autoconf $ ls aclocal.m4 autom4te.cache autoscan.log configure configure.ac hello.cpp
$ autoheader $ ls aclocal.m4 autoscan.log configure hello.cpp autom4te.cache config.h.in configure.ac
$ vi Makefile.am增加一下内容:
AUTUMAKE_OPTIONS = foreign bin_PROGRAMS = hello hello_SOURCES = hello.cppMakefile.am文件内容说明
AUTOMAKE_OPTIONS 为设置automake 的选项.由于GNU对自己发布的软件有严格的规范,比如必须附带许可证声明文件COPYING等,否则automake执行时会报错.automake提供了3种软件等级:foreign、gnu、gnits,供用户选择。默认级别是gnu。 bin_PROGRAMS 定义要产生的执行文件名。如果要产生多个执行文件,每个文件名用空格隔开 hello_SOURCES 定义“hello”这个可以执行程序所需的原始文件。如果“hello”这个程序是由多个源文件所产生的,则必须把它所用到的所有源文件都列出来,并用空格隔开。如果要定义多个可执行程序,那么需要对每个可执行程序建立对应的file_SOURCES
$ automake --add-missing configure.ac:8: installing `./install-sh'; error while making link: Operation not supported configure.ac:8: installing `./missing'; error while making link: Operation not supported Makefile.am: installing `./INSTALL'; error while making link: Operation not supported <pre name="code" class="plain">Makefile.am: required file `./NEWS' not found Makefile.am: required file `./README' not found Makefile.am: required file `./AUTHORS' not found Makefile.am: required file `./ChangeLog' not foundMakefile.am: installing `./COPYING‘ using GNU General Public License v3 file; error while making link: Operation not supportedMakefile.am: Consider adding the COPYING file to the version control systemMakefile.am: for your code, to avoid questions about which license your project uses.Makefile.am: installing `./depcomp‘; error while making link: Operation not supported 说明:
configure.ac:8: installing `./install-sh'; error while making link: Operation not supported configure.ac:8: installing `./missing'; error while making link: Operation not supported Makefile.am: installing `./depcomp'; error while making link: Operation not supported ##因为把工程放在FAT32分区上,而它不支持link.需要挪到ext3上
Makefile.am: required file `./NEWS' not found Makefile.am: required file `./README' not found Makefile.am: required file `./AUTHORS' not found Makefile.am: required file `./ChangeLog' not found ##使用touch 命令创建这4个文件
$ cp -rvf ../demo_conf/ /home/gino/ $ cd /home/gino/demo_conf/ $ touch NEWS $ touch README $ touch AUTHORS $ touch ChangeLog $ automake --add-missing $ ls aclocal.m4 autoscan.log config.h.in configure hello install-sh Makefile.in README AUTHORS ChangeLog config.log configure.ac hello.cpp Makefile missing stamp-h1 autom4te.cache config.h config.status depcomp hello.o Makefile.am NEWS
$ ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... no checking for mawk... mawk checking whether make sets $(MAKE)... yes checking for g++... g++ checking whether the C++ compiler works... yes checking for C++ compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking for style of include used by make... GNU checking dependency style of g++... gcc3 configure: creating ./config.status config.status: creating Makefile config.status: creating config.h config.status: config.h is unchanged config.status: executing depfiles commands
标签:
原文地址:http://blog.csdn.net/u011641885/article/details/46316167