automake/autoconf的简单例子
参考文章1:http://loftor.com/archives/automake.html
参考文章2:http://www.blogjava.net/huyi2006/articles/187908.html
项目一 helloworld
整个基础上仅有一个helloworld.c文件,功能也非常简单,只是向屏蔽输出一句hello。
新建一个helloworld目录,然后在里面新建一个文件helloworld.c,内容为:
#include <stdio.h> int main(int argc, char **agrv)
{
printf("Hello, Merlin\n"); return ;
}
执行命令autoscan生成一个架构configure.scan,将其重新命名为configure.ac(新版本使用ac后缀名,不再使用in后缀),此时目录中含有以下文件
merlin@tfAnalysis:~/t/hellworld$ ls
autoscan.log configure.ac helloworld.c
原configure.scan的内容为:
# -*- Autoconf -*-
# Process this file with 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]) # 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_OUTPUT
将其修改为以下样子:
# -*- Autoconf -*-
# Process this file with 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 # 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_OUTPUT(Makefile)
AC_CONFIG_SRCDIR(helloworld.c)的功能是在./configure时检测文件helloworld.c是否存在,从而检测源码的正确性。
依次执行aclocal和autoconf两人个命令,此时文件夹中内容为:
merlin@tfAnalysis:~/t/hellworld$ ls
aclocal.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:: installing './compile'
configure.ac:: installing './install-sh'
configure.ac:: installing './missing'
Makefile.am: installing './depcomp'
此时文件夹中内容为:
merlin@tfAnalysis:~/t/hellworld$ ls
aclocal.m4 compile depcomp Makefile.am
autom4te.cache configure helloworld.c Makefile.in
autoscan.log configure.ac install-sh missing
这个时候就可以使用./configure来生成Makefile文件了
merlin@tfAnalysis:~/t/hellworld$ ./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... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
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 gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking that generated files are newer than configure... done
configure: 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.Po
gcc -g -O2 -o helloworld helloworld.o
merlin@tfAnalysis:~/t/hellworld$ ls
aclocal.m4 config.log depcomp install-sh missing
autom4te.cache config.status helloworld Makefile
autoscan.log configure helloworld.c Makefile.am
compile configure.ac helloworld.o Makefile.in
merlin@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 this file with 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 # Checks for programs.
AC_PROG_CC # Checks for libraries. # Checks for header files.
AC_CHECK_HEADERS([netinet/in.h stdlib.h string.h]) # Checks for typedefs, structures, and compiler characteristics. # Checks for library 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 静态库生成与动态库生成方法
automake/autoconf的简单例子的更多相关文章
- 大型项目使用Automake/Autoconf完成编译配置
http://www.cnblogs.com/xf-linux-arm-java-android/p/3590770.htmlhttp://blog.csdn.net/zengraoli/articl ...
- Hibernate4.2.4入门(一)——环境搭建和简单例子
一.前言 发下牢骚,这段时间要做项目,又要学框架,搞得都没时间写笔记,但是觉得这知识学过还是要记录下.进入主题了 1.1.Hibernate简介 什么是Hibernate?Hibernate有什么用? ...
- AgileEAS.NET SOA 中间件平台.Net Socket通信框架-简单例子-实现简单的服务端客户端消息应答
一.AgileEAS.NET SOA中间件Socket/Tcp框架介绍 在文章AgileEAS.NET SOA 中间件平台Socket/Tcp通信框架介绍一文之中我们对AgileEAS.NET SOA ...
- spring mvc(注解)上传文件的简单例子
spring mvc(注解)上传文件的简单例子,这有几个需要注意的地方1.form的enctype=”multipart/form-data” 这个是上传文件必须的2.applicationConte ...
- ko 简单例子
Knockout是在下面三个核心功能是建立起来的: 监控属性(Observables)和依赖跟踪(Dependency tracking) 声明式绑定(Declarative bindings) 模板 ...
- mysql定时任务简单例子
mysql定时任务简单例子 ? 1 2 3 4 5 6 7 8 9 如果要每30秒执行以下语句: [sql] update userinfo set endtime = now() WHE ...
- java socket编程开发简单例子 与 nio非阻塞通道
基本socket编程 1.以下只是简单例子,没有用多线程处理,只能一发一收(由于scan.nextLine()线程会进入等待状态),使用时可以根据具体项目功能进行优化处理 2.以下代码使用了1.8新特 ...
- 一个简单例子:贫血模型or领域模型
转:一个简单例子:贫血模型or领域模型 贫血模型 我们首先用贫血模型来实现.所谓贫血模型就是模型对象之间存在完整的关联(可能存在多余的关联),但是对象除了get和set方外外几乎就没有其它的方法,整个 ...
- [转] 3个学习Socket编程的简单例子:TCP Server/Client, Select
以前都是采用ACE的编写网络应用,最近由于工作需要,需要直接只用socket接口编写CS的代码,重新学习这方面的知识,给出自己所用到的3个简单例子,都是拷贝别人的程序.如果你能完全理解这3个例子,估计 ...
随机推荐
- mapxtreme演示V1.3
mapxtreme演示V1.3 mapxtreme地图相关基本功能的演示其中包括 鹰眼地图,图层控制,发达,缩小,平移地图,地图模糊查询,中点工具,距离测量工具,面积测量工具,图元信息查看工具,各 ...
- Youtube最佳Red5 官方视频下载指南,字幕【亲测成功】
前言 最近在研究Red5 流媒体服务框架,官网上的信息足以让一个新手入门 有官方參考手冊 -- 高速了解red5的相关信息 有Red5 on Stackoverflow -- 在上面能够提问或者回答 ...
- LInq 与lambda表达式
LInq 与lambda表达式 LinQ是我们常用的技术之一.因为我们绕不开的要对数据进行一系列的调整,如 排序. 条件筛选.求和.分组.多表联接 等等. lambda则是我们常用的语法糖,配合lin ...
- S3C2416裸机开发系列19_Fatfs播放录像wav音频文件
S3C2416裸机开发系列19 Fatfs播放录像wav音频文件 国际象棋男孩 1048272975 多媒体资源,一般都是以文件的形式存储在固化存储器中.Fatfs所支持的fat32为windo ...
- twitter接口开发
前一阵子研究了下twitter接口,发现网上的资料不是很多.遂花了些心血,终于有所收获~ 现在有时间赶紧整理出来便于自己以后查阅,也想帮助有困难的同学们.废话不多说,现在就以最简洁的方式开始了.注意: ...
- 使 IIS 6.0 可以在 64 位 Windows 上运行 32 位应用程序 试图加载格式不正确的程序。
原文 使 IIS 6.0 可以在 64 位 Windows 上运行 32 位应用程序 试图加载格式不正确的程序. win7 64位操作系统上边运行IIS网站应用的时候,提示错误"试图加载格式 ...
- 自己的包poi操作Excel工具
在前面的文章<使用poi读写Excel>中分享了一下poi操作Excel的简单演示样例.这次要分享一下我封装的一个Excel操作的工具类. 该工具类主要完毕的功能是:读取Excel.汇总E ...
- C#将image中的显示的图片转换成二进制
原文:C#将image中的显示的图片转换成二进制 1.将Image图像文件存入到数据库中 我们知道数据库里的Image类型的数据是"二进制数据",因此必须将图像文件转换成字节数组才 ...
- 终于会用c#中的delegate(委托)和event(事件)了
一.开篇忏悔 对自己最拿手的编程语言C#,我想对你说声对不起,因为我到现在为止才明白c#中的delegate和event是怎么用的,惭愧那.好了,那今天就趁月黑风高的夜晚简单来谈谈delegate和e ...
- IEnumerable,IQueryable的区别
IEnumerable,IQueryable之前世今生 IEnumerable<T>在.Net2.0中我们已经很熟悉了.你想要利用Foreach迭代吗?实现IEnumerable<T ...