automake 框架_automake/autoconf的简单例子

项目一 helloworld

整个基础上仅有一个helloworld.c文件,功能也非常简单,只是向屏蔽输出一句hello。

新建一个helloworld目录,然后在里面新建一个文件helloworld.c,内容为:

#include

int main(int argc, char **agrv)

{

printf("Hello, Merlin\n");return 0;

}

执行命令autoscan生成一个架构configure.scan,将其重新命名为configure.ac(新版本使用ac后缀名,不再使用in后缀),此时目录中含有以下文件

merlin@tfAnalysis:~/t/hellworld$ lsautoscan.log configure.ac helloworld.c

原configure.scan的内容为:

# -*- Autoconf -*-# Process thisfilewith autoconf to produce a configure script.

AC_PREREQ([2.69])

AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])

AC_CONFIG_SRCDIR([helloworld.c])

AC_CONFIG_HEADERS([config.h])

# Checksforprograms.

AC_PROG_CC

# Checksforlibraries.

# Checksforheader files.

# Checksfortypedefs, structures, and compiler characteristics.

# Checksforlibrary functions.

AC_OUTPUT

将其修改为以下样子:

# -*- Autoconf -*-# Process thisfilewith autoconf to produce a configure script.

AC_PREREQ([2.69])

AC_INIT(helloworld,0.1, tfa2012@foxmail.com)

AC_CONFIG_SRCDIR(helloworld.c)

#AC_CONFIG_HEADERS([config.h])

AM_INIT_AUTOMAKE

# Checksforprograms.

AC_PROG_CC

# Checksforlibraries.

# Checksforheader files.

# Checksfortypedefs, structures, and compiler characteristics.

# Checksforlibrary functions.

AC_OUTPUT(Makefile)

AC_CONFIG_SRCDIR(helloworld.c)的功能是在./configure时检测文件helloworld.c是否存在,从而检测源码的正确性。

依次执行aclocal和autoconf两人个命令,此时文件夹中内容为:

merlin@tfAnalysis:~/t/hellworld$ lsaclocal.m4 autom4te.cache autoscan.log configure configure.ac helloworld.c

新建文件Makefile.am文件,并填写入以下内容:

AUTOMAKE_OPTIONS =foreign

bin_PROGRAMS=helloworld

helloworld_SOURCES= helloworld.c

执行automake --add-missing

merlin@tfAnalysis:~/t/hellworld$ automake --add-missing

configure.ac:11: installing './compile'configure.ac:8: installing './install-sh'configure.ac:8: installing './missing'Makefile.am: installing'./depcomp'

此时文件夹中内容为:

merlin@tfAnalysis:~/t/hellworld$ lsaclocal.m4 compile depcomp Makefile.am

autom4te.cache configure helloworld.c Makefile.inautoscan.log configure.acinstall-sh missing

这个时候就可以使用./configure来生成Makefile文件了

merlin@tfAnalysis:~/t/hellworld$ ./configure

checkingfor a BSD-compatible install... /usr/bin/install -c

checking whether build environment is sane... yes

checkingfor a thread-safe mkdir -p... /bin/mkdir -p

checkingfor gawk... gawkchecking whethermakesets $(MAKE)... yes

checking whethermakesupports nested variables... yes

checkingfor gcc... gccchecking whether the C compiler works... yes

checkingfor C compiler default output filename... a.out

checkingforsuffix of executables...

checking whether we are cross compiling... no

checkingfor suffix of objectfiles... o

checking whether we are using the GNU C compiler... yes

checking whethergcc accepts -g... yes

checkingfor gccoption to accept ISO C89... none needed

checking whethergcc understands -c and -o together... yes

checkingfor style of include used by make... GNU

checking dependency style ofgcc... gcc3

checking that generated files are newer than configure...doneconfigure: creating ./config.status

config.status: creating Makefile

config.status: executing depfiles commands

编译出来试试:

merlin@tfAnalysis:~/t/hellworld$ make

gcc -DPACKAGE_NAME=\"helloworld\" -DPACKAGE_TARNAME=\"helloworld\" -DPACKAGE_VERSION=\"0.1\" -DPACKAGE_STRING=\"helloworld\ 0.1\" -DPACKAGE_BUGREPORT=\"tfa2012@foxmail.com\" -DPACKAGE_URL=\"\" -DPACKAGE=\"helloworld\" -DVERSION=\"0.1\" -I. -g -O2 -MT helloworld.o -MD -MP -MF .deps/helloworld.Tpo -c -o helloworld.o helloworld.c

mv -f .deps/helloworld.Tpo .deps/helloworld.Pogcc -g -O2 -o helloworld helloworld.o

merlin@tfAnalysis:~/t/hellworld$ lsaclocal.m4 config.log depcompinstall-shmissing

autom4te.cache config.status helloworld Makefile

autoscan.log configure helloworld.c Makefile.am

compile configure.ac helloworld.o Makefile.inmerlin@tfAnalysis:~/t/hellworld$ ./helloworld

Hello, Merlin

项目二 tfadc

这个工程稍微复杂一些,具体的结构是这样子的:

tfadc/

scripts/

src/

cmdline.c

confile.c

main.c

network.c

db/

include/

tfadp/

tfadp.c

tfana/

tfana.c

在tfadc目录下面运行autoscan命令,此时获得的configure.scan需要修改成configure.ac,是以下样子:

# -*- Autoconf -*-# Process thisfilewith autoconf to produce a configure script.

AC_PREREQ([2.69])

AC_INIT([tfadc], [0.2], [tfa2012@foxmail.com])

AC_CONFIG_SRCDIR([config.h.in])

AC_CONFIG_HEADERS([config.h])

AM_INIT_AUTOMAKE

# Checksforprograms.

AC_PROG_CC

# Checksforlibraries.

# Checksforheader files.

AC_CHECK_HEADERS([netinet/in.h stdlib.h string.h])

# Checksfortypedefs, structures, and compiler characteristics.

# Checksforlibrary functions.

AC_CHECK_FUNCS([bzero socket strerror])

#AC_CONFIG_FILES([Makefile])

AC_OUTPUT(

Makefile

src/Makefile

)

在tfadc目录下面新建一个Makefile.am,这里指示还有子目录为src,表明子目录中有Makefile.am文件:

AUTOMAKE_OPTIONS =foreign

SUBDIRS=src

#EXTRA_DIST= doc/userguide

新建另外一个文件src/Makefile.am,这里没有指示其还有子目录的Makefile.am,而是让如tfadp下的源码使用tfadp/tfadp.c这样的形式引入到本Makefile.am中来,这个时候需要在AUTOMAKE_OPTIONS中加入subdir-objects参数:

AUTOMAKE_OPTIONS = foreign subdir-objects

bin_PROGRAMS=tfadc

tfadc_SOURCES= cmdline.c confile.c main.c network.c tfadp/tfadp.c tfana/tfana.c

#tfadc_LDADD= db/db.a tfana/tfana.a

如果想要把tfana中的文件编译成库文件的话,则需要在tfana中新建一个Makefile.am,那么上面的src/Makefile.am就需要添加一个SUBDIRS = tfana了,并且还需要修改src/Makefile.am加上tfadc_LDADD = tfana/tfana.a这一行。具体如何操作还需要看一看网上的例程(参数链接2)。

添加完两个Makefile.am之后就可以使用automake --add-missing生成configure文件了,后面的步骤就简单了./configure && make...

本文将持续完善,将在未来的实际项目时添加以下内容

1 配置安装路径等选项

2 添加配置选项(./configure --enable-xxx)

3 如果软件有配置文件则如何拷贝到实际环境中

4 静态库生成与动态库生成方法

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值