新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > Linux下C编程基础之:使用autotools

Linux下C编程基础之:使用autotools

作者: 时间:2013-09-13 来源:网络 收藏

本文引用地址:https://www.eepw.com.cn/article/257148.htm

下面对该脚本文件的对应项进行解释。

n 其中的AUTOMAKE_OPTIONS为设置automake的选项。GNU对自己发布的软件有严格的规范,比如必须附带许可证声明文件COPYING等,否则automake执行时会报错。automake提供了3种软件等级:foreign、gnu和gnits,让用户选择采用,默认等级为gnu。在本示例中采用foreign等级,它只检测必须的文件。

n bin_PROGRAMS定义要产生的执行文件名。如果要产生多个执行文件,每个文件名用空格隔开。

n hello_SOURCES定义“hello”这个执行程序所需要的原始文件。如果“hello”这个程序是由多个原始文件所产生的,则必须把它所用到的所有原始文件都列出来,并用空格隔开。例如:若目标体“hello”需要“hello.c”、“david.c”、“hello.h”三个依赖文件,则定义hello_SOURCES=hello.cdavid.chello.h。要注意的是,如果要定义多个执行文件,则对每个执行程序都要定义相应的file_SOURCES。

接下来可以使用automake命令来生成“configure.in”文件,在这里使用选项“-a”(或者“—adding-missing”)可以让automake自动添加一些必需的脚本文件。如下所示:

[root@localhostautomake]#automake–a(或者automake--add-missing)

configure.in:installing'./install-sh'

configure.in:installing'./missing'

makefile.am:installing'depcomp'

[root@localhostautomake]#ls

aclocal.m4autoscan.logconfigure.inhello.cmakefile.ammissing

autom4te.cacheconfiguredepcompinstall-shmakefile.inconfig.h.in

可以看到,在automake之后就可以生成configure.in文件。

5.运行configure

在这一步中,通过运行自动配置设置文件configure,把makefile.in变成了最终的makefile。如下所示:

[root@localhostautomake]#./configure

checkingforaBSD-compatibleinstall.../usr/bin/install-c

checkingwhetherbuildenvironmentissane...yes

checkingforgawk...gawk

checkingwhethermakesets$(MAKE)...yes

checkingforgcc...gcc

checkingforCcompilerdefaultoutputfilename...a.out

checkingwhethertheCcompilerworks...yes

checkingwhetherwearecrosscompiling...no

checkingforsuffixofexecutables...

checkingforsuffixofobjectfiles...o

checkingwhetherweareusingtheGNUCcompiler...yes

checkingwhethergccaccepts-g...yes

checkingforgccoptiontoacceptANSIC...noneneeded

checkingforstyleofincludeusedbymake...GNU

checkingdependencystyleofgcc...gcc3

configure:creating./config.status

config.status:creatingmakefile

config.status:executingdepfilescommands

可以看到,在运行configure时收集了系统的信息,用户可以在configure命令中对其进行方便的配置。在./configure的自定义参数有两种,一种是开关式(--enable-XXX或--disable-XXX),另一种是开放式,即后面要填入一串字符(--with-XXX=yyyy)参数。读者可以自行尝试其使用方法。另外,读者可以查看同一目录下的“config.log”文件,以方便调试之用。

到此为止,makefile就可以自动生成了。回忆整个步骤,用户不再需要定制不同的规则,而只需要输入简单的文件及目录名即可,这样就大大方便了用户的使用。生成makefile的流程如图3.9所示。

图3.9生成makefile的流程图

linux操作系统文章专题:linux操作系统详解(linux不再难懂)


评论


相关推荐

技术专区

关闭