一个简单的执行程序的GNU automake自动生成Makefile的方法及案例
一个简单的执行程序的GNU automake自动生成Makefile的方法及案例
在GNU的世界里,存在Automake这样的工具进行自动生成Makefile文件,automake是由Perl语言编写的,必须与GNU autoconf一并使用,具体的生成过程请参看GNU automake的wikipedia中的右下角的图,地址如下:http://en.wikipedia.org/wiki/Automake,由此图可看到使用自动生成Makefile的工具使用的流程,步骤主要如下:
- autoscan
- 修改生成的configure.scan为configure.in
- aclocal
- autoheader
- autoconf
- 创建Makefile.am并进行具体内容的写入
- automake
- automake
- ./configure生成Makefile
- make得到可执行程序
光空说太抽象了,那么来一个简单的例子吧,
0. 创建一个printf("Hello world!\n")
的小程序,创建目录hello后创建hello.c,
ufo@ufo:~/hello$ ls
hello.c
那么下一步即可开始automake的工作了,
1、使用autoscan生成configure.scan
ufo@ufo:~/hello$ autoscan
ufo@ufo:~/hello$ ls
autoscan.log configure.scan hello.c
ufo@ufo:~/hello$ aclocal
aclocal: `configure.ac' or `configure.in' is required
2、在上一步中直接执行aclocal时出现以上的提示,那么就要将生成的configure.scan修改为configure.ac或configure.in再进行aclocal的执行;
ufo@ufo:~/hello$ mv configure.scan configure.in
ufo@ufo:~/hello$ ls
autoscan.log configure.in hello.c
3、执行aclocal
ufo@ufo:~/hello$ aclocal
ufo@ufo:~/hello$ ls
autom4te.cache autoscan.log configure.in hello.c
4、执行autoheader
ufo@ufo:~/hello$ ls
autom4te.cache autoscan.log config.h.in configure.in hello.c
5、执行autoconf
ufo@ufo:~/hello$ autoconf
ufo@ufo:~/hello$ ls
autom4te.cache autoscan.log config.h.in configure configure.in hello.c
6、创建Makefile.am
ufo@ufo:~/hello$ vim Makefile.am
ufo@ufo:~/hello$ cat Makefile.am
bin_PROGRAMS=hello
hello_SOURCES=hello.c
关于Makefile.am中的具体内容的意思是说生成的可执行文件的名称为hello,对应的源代码为hello.c。
7、执行automake
ufo@ufo:~/hello$ automake
configure.in: no proper invocation of AM_INIT_AUTOMAKE was found.
configure.in: You should verify that configure.in invokes AM_INIT_AUTOMAKE,
configure.in: that aclocal.m4 is present in the top-level directory,
configure.in: and that aclocal.m4 was recently regenerated (using aclocal).
automake: no `Makefile.am' found for any configure output
automake: Did you forget AC_CONFIG_FILES([Makefile]) in configure.in?
这时出错了,是说configure.in文件中的AM_INIT_AUTOMAKE没有找到,只有修改configure.in
文件后再从第三步进行重新执行,configure.in中的AC_INIT行下添加
AM_INIT_AUTOMAKE(hello,1.0),格式为AM_INIT_AUTOMAKE(package,version),再修改AC_OUTPUT为AC_OUTPUT(Makefile);
修改完configure.in文件后,再次执行2~7;
8、执行automake
ufo@ufo:~/hello$ automake
configure.in:6: required file `./install-sh' not found
configure.in:6: `automake --add-missing' can install `install-sh'
configure.in:6: required file `./missing' not found
configure.in:6: `automake --add-missing' can install `missing'
Makefile.am: required file `./INSTALL' not found
Makefile.am: `automake --add-missing' can install `INSTALL'
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
Makefile.am: required file `./COPYING' not found
Makefile.am: `automake --add-missing' can install `COPYING'
Makefile.am: required file `./depcomp' not found
Makefile.am: `automake --add-missing' can install `depcomp'
按照提示创建缺少的文件,
ufo@ufo:~/hello$ touch NEWS README AUTHORS ChangeLog
再执行:
ufo@ufo:~/hello$ automake --add-missing
没有出错的情况下再次执行automake;
ufo@ufo:~/hello$ ls
aclocal.m4 ChangeLog configure.in INSTALL missing
AUTHORS config.h.in COPYING install-sh NEWS
autom4te.cache config.h.in~ depcomp Makefile.am README
autoscan.log configure hello.c Makefile.in
此时已经生成了生成Makefile文件的cinfigure脚本;
9、./configure生成Makefile
ufo@ufo:~/hello$ ls Makefile
Makefile
10、make得到可执行程序
ufo@ufo:~/hello$ make
make all-am
make[1]: 正在进入目录 `/home/ufo/hello'
gcc -DHAVE_CONFIG_H -I. -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.c
mv -f .deps/hello.Tpo .deps/hello.Po
gcc -g -O2 -o hello hello.o
make[1]:正在离开目录 `/home/ufo/hello'
ufo@ufo:~/hello$ ls
aclocal.m4 config.h configure hello.c Makefile.am stamp-h1
AUTHORS config.h.in configure.in hello.o Makefile.in
autom4te.cache config.h.in~ COPYING INSTALL missing
autoscan.log config.log depcomp install-sh NEWS
ChangeLog config.status hello Makefile README
ufo@ufo:~/hello$ ./hello
Hello World!
这就是牛X的automake的例子;关于其中的细节日后有空再表了
一个简单的执行程序的GNU automake自动生成Makefile的方法及案例的更多相关文章
- GNU autotools自动生成Makefile 介绍
一.目的 使用autotools工具来帮助我们自动地生成符合自由软件惯例的makefile(这样就可以像常见的GNU程序一样,只要使用"./configure", "ma ...
- 使用autoconf与automake自动生成MakeFile文件
automake主要通过编辑Makefile.am来控制它的行为,下面就常用的三个Makefile.am配置做出说明. 1.1. autotools的工作原理 autotools最终是为了生成Make ...
- 简单实例,说明自动生成Makefile的详细过程
为了编译一个简单的源文件main.c,需要自动生成一个makefile,以下是步骤: 第一步:----------在/root/project/main目录下创建一个文件main.c,其内容如下:-- ...
- linux下使用automake工具自动生成makefile文件
linux环境下,当项目工程很大的时候,编译的过程很复杂,所以需要使用make工具,自动进行编译安装,但是手写makefile文件比较复杂,所幸在GNU的计划中,设计出了一种叫做Autoconf/Au ...
- 使用automake等命令自动生成Makefile文件 (转载)
使用automake等命令自动生成Makefile文件 Linux下编程时,为了方便编译,往往使用Makefile文件自动完成编译,但是Makefile文件本身的书写十分复杂,规则很多.好在Lin ...
- 自动生成 Makefile (automake/autoconf 入门)
作为Linux 下的程序开发人员,大家一定都遇到过Makefile ,用make 命令来编译自己写的程序确实是很方便.一般情况下,大家都是手工写一个简单Makefile ,如果要想写出一个符合自由软件 ...
- 自动生成makefile
原文 http://www.laruence.com/2009/11/18/1154.html 作为Linux下的程序开发人员,大家一定都遇到过Makefile,用make命令来编译自己写的程序确实 ...
- 如何自动生成Makefile
作为Linux下的程序开发人员,大家一定都遇到过Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下,大家都是手工写一个简单Makefile,如果要想写出一个符合自由软件惯例的M ...
- 使用autotools自动生成Makefile并在此之上使用dh-make生成可发布的deb程序包(详解)
转自:http://blog.csdn.net/longerzone/article/details/12705507 一.前言 本文将介绍如何使用autotools生成一个Makefile文件,并在 ...
随机推荐
- gh-ost 号称是不需要触发器(Triggerless)支持的在线更改表结构的工具
https://segmentfault.com/a/1190000006158503?utm_source=tuicool&utm_medium=referral
- Android:隐藏ActionBar
在OnCreate函数中添加:getActionBar().hide();
- ubuntu 14.04升级PHP5.5.9 到5.6
升级的步骤:参考https://www.digitalocean.com/community/questions/how-to-upgrade-from-php-v-5-5-9-to-v-5-6 su ...
- CentOS出错You don't have permission to access on this server
检查http.conf发现没错之后.查找资料后发现时selinux的问题,所以须要关闭这个服务: 1 vi /etc/sysconfig/selinux 2 SELINUX=enforcing 改为 ...
- [java设计模式]之单例模式
-------------------此部分比較深入地解说了单例模式,原文链接已给出.兴许将涉及一些常见面试问题--------------------------- 原文地址:http://www. ...
- luogu1005 矩阵取数游戏
题目大意 一个矩阵,每次从每一行的行首或行尾取一个数,每一行的价值为 取的数*2^当前取数的次数,每一次的价值为每一行的价值的和.求得到的价值的最大值. 思路 #include <cstdio& ...
- poj1041 John's trip——字典序欧拉回路
题目:http://poj.org/problem?id=1041 求字典序欧拉回路: 首先,如果图是欧拉图,就一定存在欧拉回路,直接 dfs 即可,不用 return 判断什么的,否则TLE... ...
- How to build CppCMS 1.x.x
How to build CppCMS 1.x.x Requirements Mandatory Requirements Recommended Dependencies Suggested Dep ...
- PCB MongoDb安装与Windows服务安装
工程MI流程指示做成Web网页形式,采用MVC框架制作,数据传输用Web API方式, 最终此网页会挂到公司各系统中访问,为了提高访问并发量,并将工程数据统一结构化管理, 采用No SQL Mongo ...
- PCB 无需解压,直接读取Zip压缩包指定文件 实现方法
最近有一项需求,将电测试点数后台批量写入到工程系统流程指示中,而电测试文件存在压缩包中,压缩包存在公共网络盘 示例图: 一.采用原始方法(4步完成): 第1步:.网络盘ZIP拷到本地, 第2步:解压Z ...