autotools工具使用说明

来源:互联网 发布:阿里巴巴农村淘宝加盟 编辑:程序博客网 时间:2024/05/22 15:15

操作代码如下:

root@NanoPi2:~/Test/hello# autoscanroot@NanoPi2:~/Test/hello# lsautoscan.log  configure.scan  hello.croot@NanoPi2:~/Test/hello# vi configure.scan root@NanoPi2:~/Test/hello# mv configure.scan configure.acroot@NanoPi2:~/Test/hello# lsautoscan.log  configure.ac  hello.croot@NanoPi2:~/Test/hello# aclocalroot@NanoPi2:~/Test/hello# lsaclocal.m4  autom4te.cache  autoscan.log  configure.ac  hello.croot@NanoPi2:~/Test/hello# autoconfroot@NanoPi2:~/Test/hello# lsaclocal.m4  autom4te.cache  autoscan.log  configure  configure.ac  hello.croot@NanoPi2:~/Test/hello# autoheaderroot@NanoPi2:~/Test/hello# lsaclocal.m4  autom4te.cache  autoscan.log  config.h.in  configure  configure.ac  hello.croot@NanoPi2:~/Test/hello# vi Makefile.amroot@NanoPi2:~/Test/hello# automake --add-missingconfigure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocationconfigure.ac:11: installing './compile'configure.ac:6: installing './install-sh'configure.ac:6: installing './missing'Makefile.am: installing './depcomp'root@NanoPi2:~/Test/hello# lsaclocal.m4  autoscan.log  config.h.in  configure.ac  hello.c     Makefile.am  missingautom4te.cache  compile       configure    depcomp   install-sh  Makefile.inroot@NanoPi2:~/Test/hello# ./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... nochecking for mawk... mawkchecking whether make sets $(MAKE)... yeschecking whether make supports nested variables... 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 whether gcc understands -c and -o together... yeschecking for style of include used by make... GNUchecking dependency style of gcc... gcc3checking that generated files are newer than configure... doneconfigure: creating ./config.statusconfig.status: creating Makefileconfig.status: creating config.hconfig.status: executing depfiles commandsroot@NanoPi2:~/Test/hello# lsaclocal.m4  autoscan.log  config.h     config.log     configure depcomp  install-sh  Makefile.am  missingautom4te.cache  compile       config.h.in  config.status  configure.ac  hello.c  Makefile    Makefile.in  stamp-h1root@NanoPi2:~/Test/hello# makemake  all-ammake[1]: Entering directory '/root/Test/hello'gcc -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.o  make[1]: Leaving directory '/root/Test/hello'root@NanoPi2:~/Test/hello# ./hello Hello! This is our embedded world!root@NanoPi2:~/Test/hello# 

其中configure.scan注释如下:

#                                               -*- Autoconf -*-# Process this file with autoconf to produce a configure script.AC_PREREQ([2.69])AC_INIT(hello, 1.0, lx2018fc@qq.com)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.69。
• AC_INIT宏用来定义软件的名称和版本等信息,在本例中省略了BUG-REPORT-ADDRESS,
一般为作者的 E-mail。
• AM_INIT_AUTOMAKE 是笔者另加的,它是 automake 所必备的宏,也同前面一样,
PACKAGE 是所要产生软件套件的名称,VERSION 是版本编号。
• AC_CONFIG_SRCDIR 宏用来侦测所指定的源码文件是否存在,来确定源码目录的有
效性。在此处为当前目录下的 hello.c。
• AC_CONFIG_HEADER 宏用于生成 config.h 文件,以便 autoheader 使用。
• AC_CONFIG_FILES 宏用于生成相应的 Makefile 文件。
• 中间的注释间可以添加分别用户测试程序、测试函数库、测试头文件等宏定义。
Makefile.am文件注释如下:

AUTOMAKE_OPTIONS=foreignbin_PROGRAMS=hellohello_SOURCES= hello.c

• 其中的 AUTOMAKE_OPTIONS 为设置 automake 的选项。由于 GNU(在第 1 章中已
经有所介绍)对自己发布的软件有严格的规范,比如必须附带许可证声明文件 COPYING 等,
否则 automake 执行时会报错。automake 提供了 3 种软件等级:foreign、gnu 和 gnits,让用户
选择采用,默认等级为 gnu。在本例使用 foreign 等级,它只检测必须的文件。
• bin_PROGRAMS 定义要产生的执行文件名。如果要产生多个执行文件,每个文件名
用空格隔开。
• hello_SOURCES 定义“hello”这个执行程序所需要的原始文件。如果“hello”这个
程序是由多个原始文件所产生的,则必须把它所用到的所有原始文件都列出来,并用空格隔
开。例如:若目标体“hello”需要“hello.c”、“sunq.c”、“hello.h”三个依赖文件,则定义
hello_SOURCES=hello.c sunq.c hello.h。要注意的是,如果要定义多个执行文件,则对每个执
行程序都要定义相应的 file_SOURCES。

0 0
原创粉丝点击