automake——automake简易教程
转载自:http://blog.csdn.net/earbao/article/details/38516327
【carolven原创begin】automake使用步骤,下图给出了清晰的流程(图片来自https://en.wikipedia.org/wiki/Automake)
【carolven原创end】
autoconf/automake主要用于创建Makefile,本文主要介绍一下automake的简单用法。
Ubuntu下安装automake:
sudo apt-get install automake
即可安装automake的相关工具。
使用automake主要会用到aclocal、autoscan、autoconf、autoheader和automake这几个命令。
autoheader主要用来生成 config.h.in 宏定义
首先简略的说一下用automake生成Makefile的步骤:
(1)创建源代码文件,使用”autoscan”生成configure.scan文件,将其重命名为configure.ac,并做适当修改,
然后使用”aclocal”命令生成aclocal.m4文件,使用”autoconf”命令由configure.ac和aclocal.m4文件生成configure文件。
(2)手工编辑Makefile.am文件,使用”automake”命令生成configure.in文件。
(3)手工编辑或由系统给定acconfig.h文件,使用”autoheader”命令生成config.h.in文件。
(4)使用”configure”命令由configure、configure.in和config.h.in文件生成Makefile文件。从而完成Makefile文件的创建过程。
下面用一个经典的hello world的例子说明automake的用法
1.编辑源文件
root@ubuntu:~# mkdir hello
root@ubuntu:~# cd hello
root@ubuntu:~/hello# vi hello.c
root@ubuntu:~/hello# cat hello.c
Source code |
![]() ![]() ![]() |
[cpp] view plaincopy
- <span class="co2" style="color:rgb(51,153,0)">#include <stdio.h></span>
- <span class="kw4" style="color:rgb(0,0,255)">int</span> main<span class="br0" style="color:rgb(0,128,0)">(</span><span class="br0" style="color:rgb(0,128,0)">)</span>
- <span class="br0" style="color:rgb(0,128,0)">{</span>
- <span class="kw3" style="color:rgb(0,0,221)">printf</span><span class="br0" style="color:rgb(0,128,0)">(</span><span class="st0" style="color:rgb(255,0,0)">"hello world<span class="es1" style="color:rgb(0,0,153); font-weight:bold">\n</span>"</span><span class="br0" style="color:rgb(0,128,0)">)</span><span class="sy4" style="color:rgb(0,128,128)">;</span>
- <span class="kw1" style="color:rgb(0,0,255)">return</span> <span class="nu0" style="color:rgb(0,0,221)">0</span><span class="sy4" style="color:rgb(0,128,128)">;</span>
- <span class="br0" style="color:rgb(0,128,0)">}</span>
2.使用Autoscan工具生成configure.ac文件
Autoscan工具用来扫描源代码以搜寻一般的可移植性问题,比如检查编译器、库和头文件等,并创建configure.scan文件,它会在给定目录及其子目录树中检查源文件,若没有给出目录,就在当前目录及其子目录树中进行检查。
root@ubuntu:~/hello# autoscan //扫描源文件,生成configure.scan
root@ubuntu:~/hello# ls
autoscan.log configure.scan hello.c
root@ubuntu:~/hello# cat configure.scan
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.AC_PREREQ([2.65])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
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_OUTPUT
下面给出本文件的简要说明(所有以”#”号开始的行为注释):
(1)AC_PREREQ宏声明本文件要求的autoconf版本,本例使用的版本为2.59。
(2)AC_INIT宏用来定义软件的名称和版本等信息,”FULL-PACKAGE-NAME”为软件包名称,”VERSION”为软件版本号,”BUG-REPORT-ADDRESS”为BUG报告地址(一般为软件作者邮件地址)。
(3)AC_CONFIG_SRCDIR宏用来侦测所指定的源码文件是否存在,来确定源码目录的有效性。此处为当前目录下的hello.c。
(4)AC_CONFIG_HEADER宏用于生成config.h文件,以便autoheader使用。
(5)AC_PROG_CC用来指定编译器,如果不指定,选用默认gcc。
(6)AC_OUTPUT用来设定 configure 所要产生的文件,如果是makefile,configure会把它检查出来的结果带入makefile.in文件产生合适的makefile。使用Automake时,还需要一些其他的参数,这些额外的宏用aclocal工具产生。
此文件只是下面要使用的configure.ac文件的原型,当然我们还要对其做一定的修改:
root@ubuntu:~/hello# cp configure.scan configure.ac
root@ubuntu:~/hello# vi configure.ac
root@ubuntu:~/hello# cat configure.ac
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.AC_PREREQ([2.65]) //automake版本
AC_INIT(hello, 1.0, kingplesk@gmail.com) //设置软件包信息
AM_INIT_AUTOMAKE(hello, 1.0) //这个需要手动添加,它是automake必备的宏
AC_CONFIG_SRCDIR([hello.c]) //源文件名
#AC_CONFIG_HEADERS([config.h]) //config.h 文件, 这个地方我们不需要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(Makefile) //要输出的文件名
3.使用aclocal工具生成aclocal.m4
aclocal根据configure.ac生成aclocal.m4
root@ubuntu:~/hello# aclocal
root@ubuntu:~/hello# ls
aclocal.m4 autom4te.cache autoscan.log configure.ac hello.c
4.使用autoconf工具生成configure文件
将configure.ac中的宏展开,生成configure脚本。这个过程可能要用到aclocal.m4中定义的宏。
root@ubuntu:~/hello# autoconf
root@ubuntu:~/hello# ls
aclocal.m4 autom4te.cache autoscan.log configure configure.ac hello.c
5.使用autoheader 工具生成 config.h config.h.in
root@ubuntu:~/hello# autoheader
root@ubuntu:~/hello# ls
5.创建Makefile.am文件
Automake工具会根据configure.in中的参量把Makefile.am转换成Makefile.in文件。所以在使用automake之前我们需要自己创建Makefile.am文件
root@ubuntu:~/hello# vi Makefile.am
root@ubuntu:~/hello# cat Makefile.am
AUTOMAKE_OPTIONS=foreign //软件等级
bin_PROGRAMS=hello //可执行文件名
hello_SOURCES=hello.c //源文件名
其中:
(1)AUTOMAKE_OPTIONS为设置Automake的选项。由于GNU对自己发布的软件有严格的规范,比如必须附带许可证声明文件COPYING等,否则Automake执行时会报错。Automake提供了3种软件等级:foreign、gnu和gnits,供用户选择,默认等级为gnu。本例使需用foreign等级,它只检测必须的文件。
(2)bin_PROGRAMS定义要产生的执行文件名。如果要产生多个执行文件,每个文件名用空格隔开。
(3)hello_SOURCES定义”hello”这个执行程序所需要的原始文件。如果”hello”这个程序是由多个原始文件所产生的,则必须把它所用到的所有原始文件都列出来,并用空格隔开。例如:若目标体”hello”需要”hello.c”、”hello.h”两个依赖文件,则定义hello_SOURCES=hello.c hello.h。
6.使用Automake生成Makefile.in文件
下面使用Automake生成”Makefile.in”文件,使用选项”–add-missing”可以让Automake自动添加一些必需的脚本文件。如下所示:
root@ubuntu:~/hello# automake --add-missing
configure.ac:6: installing `./install-sh'
configure.ac:6: installing `./missing'
Makefile.am: installing `./depcomp'
root@ubuntu:~/hello# ls
aclocal.m4 autoscan.log configure.ac hello.c Makefile.am missing
autom4te.cache configure depcomp install-sh Makefile.in
7.执行./configure 生成Makefile
8.测试
root@ubuntu:~/hello# ls
aclocal.m4 config.log configure.ac hello.c Makefile missing
autom4te.cache config.status depcomp hello.o Makefile.am
autoscan.log configure hello install-sh Makefile.in
root@ubuntu:~/hello# ./hello
hello world
使用”make dist”命令将程序和相关的文档打包为一个压缩文档以供发布。
root@ubuntu:~/hello# make dist
root@ubuntu:~/hello# ls
aclocal.m4 config.status hello install-sh missing
autom4te.cache configure hello-1.0.tar.gz Makefile
autoscan.log configure.ac hello.c Makefile.am
config.log depcomp hello.o Makefile.inhello-1.0.tar.gz为打包过后的文件
下面是另一种文档结构
|-- conf
| `-- test.conf
`-- src|-- test1.c|-- test2.c`-- test2.h
src为源文件目录,conf为配置文件的目录。创建Makefile的方式和上面有一点点不同
1.执行autoscan命令
root@ubuntu:~/test# autoscan
root@ubuntu:~/test# ls
autoscan.log conf configure.scan src
root@ubuntu:~/test# cat configure.scan
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.AC_PREREQ([2.65])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([src/test2.h])
AC_CONFIG_HEADERS([config.h])# Checks for programs.
AC_PROG_CC# Checks for libraries.# Checks for header files.
AC_CHECK_HEADERS([stdlib.h string.h])# Checks for typedefs, structures, and compiler characteristics.# Checks for library functions.AC_OUTPUT
修改configure.scan为configure.ac
root@ubuntu:~/test# mv configure.scan configure.ac
root@ubuntu:~/test# vim configure.ac
root@ubuntu:~/test# cat configure.ac
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.AC_PREREQ([2.65])
AC_INIT(test, 1.0)
AM_INIT_AUTOMAKE(test, 1.0)
AC_CONFIG_SRCDIR([src/test2.h])# Checks for programs.
AC_PROG_CC# Checks for libraries.
AC_CHECK_LIB(pthread, pthread_create) //pthread为链接库名字, pthread_create为库中的一个函数# Checks for header files.
AC_CHECK_HEADERS(stdlib.h string.h pthread.h) # Checks for typedefs, structures, and compiler characteristics.# Checks for library functions.AC_OUTPUT(Makefilesrc/Makefileconf/Makefile) //每一个目录需要输出一个Makefile文件
2.使用aclocal工具生成aclocal.m4
3.使用autoconf工具生成configure文件
4. 创建Makefile.am
在顶层目录创建的Makefile.am的内容如下
root@ubuntu:~/test# vi Makefile.am
root@ubuntu:~/test# cat Makefile.am
SUBDIRS= src conf
在src目录下创建的Makefile.am内容如下
root@ubuntu:~/test# cd src/
root@ubuntu:~/test/src# vi Makefile.am
root@ubuntu:~/test/src# cat Makefile.am
bin_PROGRAMS= test
test_SOURCES= test1.c test2.c
在conf目录下创建的Makefile.am内容如下
root@ubuntu:~/test/conf# vi Makefile.am
root@ubuntu:~/test/conf# cat Makefile.am
configdir = /etc //这个数据文件将要移动到的目录
config_DATA = test.conf //数据文件名,如果有多个文件则这样写config_DATA = test1.dat test2.dat
5.使用Automake生成Makefile.in文件
root@ubuntu:~/test# automake --add-missing
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
这里出现了一个问题,NEWS, README这几个文件不存在, 那么我们就手工创建他们
root@ubuntu:~/test# touch NEWS README AUTHORS ChangeLog
再次执行automake
root@ubuntu:~/test# automake
6.后面的步骤就和上面的例子一样了
automake——automake简易教程相关推荐
- qmake 简易教程
qmake 简易教程 qmake是Qt开发中默认的构建工具. posted on 2018-05-27 00:09 JichengTang 阅读(...) 评论(...) 编辑 收藏 转载于:http ...
- eslint不报错 vue_【简易教程】基于Vue-cli使用eslint指南
插件安装 首先在vscode插件中搜索eslint和prettier. 啥也不管,这俩必须得装. 插件简介 vscode插件库里的eslint是用来在你写代码的时候就直接给你报错.(vue-cli中的 ...
- Ocelot简易教程(一)之Ocelot是什么
Ocelot简易教程(一)之Ocelot是什么 原文:Ocelot简易教程(一)之Ocelot是什么 作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/955 ...
- 安装python程序后要进行什么设置-安装好Pycharm后如何配置Python解释器简易教程...
这两天有许多Python小白加入学习群,并且问了许多关于Pycharm基本使用的问题,今天小编就以配置Python解释器的问题给大家简单絮叨一下. 1.一般来说,当我们启动Pycharm,如果Pych ...
- ST单片机使用ST Visual Programmer软件烧录程序简易教程
文章原始地址: http://feotech.com/?p=100 ST单片机使用ST Visual Programmer软件烧录程序简易教程 ST Visual Programmer 是ST公司为自 ...
- mysql游标进阶_mysql进阶(三)游标简易教程
mysql游标简易教程 从mysql V5.5开始,进行了一次大的改变,就是将InnoDB作为默认的存储引擎.InnoDB支持事务,而且拥有相关的RDBMS特性:ACID事务支持,数据完整性(支持外键 ...
- Android开发简易教程
Android开发简易教程 Android 开发因为涉及到代码编辑.UI 布局.打包等工序,有一款好用的IDE非常重要.Google 最早提供了基于 Eclipse 的 ADT 作为开发工具,后来在2 ...
- 文件上传利器SWFUpload入门简易教程
凡做过网站开发的都应该知道表单file的确鸡肋. Ajax解决了不刷新页面提交表单,但是却没有解决文件上传不刷新页面,当然也有其它技术让不刷新页面而提交文件,该技术主要是利用隐藏的iFrame, 较A ...
- 【简易教程】基于Vue-cli使用eslint指南
[简易教程]基于Vue-cli使用eslint指南 插件安装 首先在vscode插件中搜索eslint和prettier. 啥也不管,这俩必须得装. 插件简介 vscode插件库里的eslint是用来 ...
- Ext DeskTop的使用方法简易教程及相关例子Demo(转)
Ext DeskTop的使用方法简易教程及相关例子Demo(转) ExtJS 2010-12-31 10:11:15 阅读196 评论0 字号:大中小 订阅 http://qwikioffice. ...
最新文章
- 【WPF】一个简单的ColorPicker控件
- python使用matplotlib可视化、使用locator_params函数自定义调整Y轴坐标轴的刻度的个数(customize number of ticks of y axis)
- Spark 1.0.0版本发布
- 火力发电厂与变电站设计防火规范_2019年《建筑设计防火规范》新版征求意见稿...
- 桌面快捷键和桌面livefolder
- Java中包装类型和基本类型的使用场景(阿里开发规范)
- mysql过滤器_MYSQL复制过滤器
- thinkpad bios联想logo_最强12吋ThinkPad,X201终极改造:8代酷睿+双内存+NVMe
- Spring IOC知识点一网打尽!
- 如何对xgboost模型进行优化
- 最长回文字串--动态规划
- 相机的成像原理: 针孔相机, 胶卷相机 和 数码相机
- 禁止计算机使用u盘启动,电脑禁用u盘的设置方法
- PyTorch搭建LSTM实现多变量时间序列预测(负荷预测)
- linux系统可以安装浩辰CAD,浩辰CAD2021
- IntelliJ IDEA 最新注册码(截止到2019年12月12日)
- Camera Surface 从应用到cameraserver的流转
- 清北学堂 2017-10-07
- C语言system()函数
- 从零开始——在Ubuntu22.04系统中部署KubeEdge架构
热门文章
- 关于石墨烯费米能与偏置电压、超材料吸收器的相关讨论
- 如何查看电脑是否设置了定时关机
- UG/NX二次开发 从文件导入表达式 UF_MODL_import_exp
- reduce()使用场景、用法总结
- Java统一返回类型R
- Codeforces-1697 C: awoo‘s Favorite Problem 【构造、双指针】
- 如何把firefox的默认播放器设置成realplayer!
- 安装FreeBSD 13.1系统及配置xfce桌面
- Excel不用打开工作簿就能直接在里面输入文字!
- 社交网络平台技术 考试卷