用Autotools工具编写Makefile文件
来源:互联网 发布:中国对东盟投资数据 编辑:程序博客网 时间:2024/05/16 09:50
之所以要用到Autotools, 是因为当工程比较大的时候, 手工编写Makefile文件是很麻烦的一件事情~此时就需要一款可以收集系统配置信息并自动生成Makefile文件的工具~
Autotools工具是由以下5个工具组成:
1)autoscan 扫描源代码目录
2)autocal 展开宏
3)autoconf 生成configure文件
4)autoheader生成header文件
5)automake 生成Makefile相关
先来看一下GNU官网的Autotools工具使用流程图:
[http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Making-configure-Scripts.html#Making-configure-Scripts]Files used in preparing a software package for distribution, when using just Autoconf:
your source files --> [autoscan*] --> [configure.scan] --> configure.ac configure.ac --. | .------> autoconf* -----> configure [aclocal.m4] --+---+ | `-----> [autoheader*] --> [config.h.in] [acsite.m4] ---' Makefile.in
Additionally, if you use Automake, the following additional productions come into play:
[acinclude.m4] --. | [local macros] --+--> aclocal* --> aclocal.m4 | configure.ac ----' configure.ac --. +--> automake* --> Makefile.in Makefile.am ---'
Files used in configuring a software package:
.-------------> [config.cache] configure* ------------+-------------> config.log | [config.h.in] -. v .-> [config.h] -. +--> config.status* -+ +--> make* Makefile.in ---' `-> Makefile ---'
下面这个可能更直观一些:
举个栗子:
先用vi写一个hello.c并保存;
#include<stdio.h>void main(){ printf("hello,tudou!");}
autoscan
功能: 扫描源代码目录并生成configure.scan文件
lmtd@lmtd-virtual-machine:~/demo$ autoscanlmtd@lmtd-virtual-machine:~/demo$ lsautoscan.logconfigure.scanhello.clmtd@lmtd-virtual-machine:~/demo$ mv configure.scan configure.aclmtd@lmtd-virtual-machine:~/demo$ lsautoscan.logconfigure.achello.c
编辑一下configure.ac文件:
1 # -*- Autoconf -*- 2 # Process this file with autoconf to produce a configure script. 3 4 AC_PREREQ([2.69]) 5 AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS]) 6 AC_CONFIG_SRCDIR([hello.c]) 7 AC_CONFIG_HEADERS([config.h]) 8 9 # Checks for programs. 10 AC_PROG_CC 11 12 # Checks for libraries. 13 14 # Checks for header files. 15 16 # Checks for typedefs, structures, and compiler characteristics. 17 18 # Checks for library functions. 19 20 AC_OUTPUT
将第5行,第20行的
5 AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
<pre name="code" class="cpp"> 20 AC_OUTPUT改为:
5 AC_INIT(hello,1.0,lmtd@sina.com) //分别对应三个参数([文件全称],[版本号],[错误报告地址])
20 AC_OUTPUT(hello,1.0)
aclocal
功能:perl脚本程序,自动生成aclocal.m4文件.
lmtd@lmtd-virtual-machine:~/demo$ aclocallmtd@lmtd-virtual-machine:~/demo$ lsaclocal.m4 autom4te.cache autoscan.log configure.ac hello.c之后我们会发现多了一个aclocal.m4宏展开文件和一个autom4te.cache缓存文件.
autoconf
功能:生成configure文件.
lmtd@lmtd-virtual-machine:~/demo$ autoconflmtd@lmtd-virtual-machine:~/demo$ lsaclocal.m4 autom4te.cache autoscan.log configure configure.ac hello.c虽然已经生成了configure文件,但是现在还不能进行配置,因为还缺少一些shell脚本文件,这些文件可以由automake生成.
automake
功能:产生Makefile.in文件.
具体用法:automake --add-missing
lmtd@lmtd-virtual-machine:~/demo$ automake --add-missingconfigure.ac:8: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:configure.ac:8: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocationconfigure.ac:11: installing './compile'configure.ac:8: installing './install-sh'configure.ac:8: installing './missing'automake: error: no 'Makefile.am' found for any configure outputlmtd@lmtd-virtual-machine:~/demo$ lsaclocal.m4 autoscan.log config.log configure.ac install-shautom4te.cache compile configure hello.c missing
configure.ac:11: error: required file './compile' not foundconfigure.ac:11: 'automake --add-missing' can install 'compile'configure.ac:8: error: required file './install-sh' not foundconfigure.ac:8: 'automake --add-missing' can install 'install-sh'configure.ac:8: error: required file './missing' not foundconfigure.ac:8: 'automake --add-missing' can install 'missing'就是说缺少install-sh等脚本文件.
GNU官网说它举个栗子:
Now it is time to write your Makefile.am for zardoz
. Since zardoz
is a user program, you want to install it where the rest of the user programs go: bindir
. Additionally, zardoz
has some Texinfo documentation. Your configure.ac script uses AC_REPLACE_FUNCS
, so you need to link against ‘$(LIBOBJS)’. So here’s what you’d write:
bin_PROGRAMS = zardoz //要命名的程序zardoz_SOURCES = main.c head.c float.c vortex9.c gun.c //源代码程序zardoz_LDADD = $(LIBOBJS) //引用类库的路径info_TEXINFOS = zardoz.texi
Now you can run ‘automake --add-missing’ to generate your Makefile.in and grab any auxiliary files you might need, and you’re done!
1 bin_PROGRAMS = hello 2 hello_SOURCES = hello.c
lmtd@lmtd-virtual-machine:~/demo$ lsaclocal.m4 compile configure install-shautom4te.cache config.log configure.ac Makefile.amautoscan.log config.status hello.c missing
lmtd@lmtd-virtual-machine:~/demo$ automakeconfigure.ac:8: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:configure.ac:8: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocationMakefile.am: installing './INSTALL'Makefile.am: error: required file './NEWS' not foundMakefile.am: error: required file './README' not foundMakefile.am: error: required file './AUTHORS' not foundMakefile.am: error: required file './ChangeLog' not foundMakefile.am: installing './COPYING' using GNU General Public License v3 fileMakefile.am: Consider adding the COPYING file to the version control systemMakefile.am: for your code, to avoid questions about which license your project usesconfigure.ac:7: error: required file 'config.h.in' not foundMakefile.am: installing './depcomp'
lmtd@lmtd-virtual-machine:~/demo$ touch NEWS README AUTHORS ChangeLog
lmtd@lmtd-virtual-machine:~/demo$ lsaclocal.m4 ChangeLog configure hello.c missingAUTHORS compile configure.ac INSTALL NEWSautom4te.cache config.log COPYING install-sh READMEautoscan.log config.status depcomp Makefile.amlmtd@lmtd-virtual-machine:~/demo$ automake --add-missingconfigure.ac:8: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:configure.ac:8: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocationconfigure.ac:7: error: required file 'config.h.in' not found
咦?这里说缺少"config.h.in"这是为什么呢?
autoheader
功能:自动生成config.h.in.
lmtd@lmtd-virtual-machine:~/demo$ autoheaderlmtd@lmtd-virtual-machine:~/demo$ lsaclocal.m4 ChangeLog config.status depcomp Makefile.amAUTHORS compile configure hello.c missingautom4te.cache config.h.in configure.ac INSTALL NEWSautoscan.log config.log COPYING install-sh README
- 用Autotools工具编写Makefile文件
- Makefile文件编写和autotools的使用
- 使用autotools工具自动生成makefile文件
- 用autotools制作Makefile 和configure文件。
- 用autotools制作Makefile 和configure文件。
- 用autotools制作Makefile 和configure文件
- 用autotools制作Makefile 和configure文件
- linux下编程用到的autotools工具 生成makefile文件
- autotools工具自动生成Makefile
- autotools生成makefile文件实例
- autotools生成makefile文件实例
- 自学编写Makefile之1 —— GNU Autotools工具介绍
- autotools系列工具—-自动生成Makefile
- autotools系列工具—-自动生成Makefile
- autotools系列工具—自动生成Makefile
- Makefile自动生成工具-----autotools的使用
- Makefile自动生成(autotools工具的使用)
- make工具与makefile文件编写实例
- FFMPEG采集摄像头数据并切片为iPhone的HTTP Stream流
- mysql show processlist命令 详解
- Android Studio 快捷键
- Android中Handler消息机制
- C-047.枚举
- 用Autotools工具编写Makefile文件
- 剑指offer系列之十三:链表中的倒数第k个节点
- 不用删除密码卸载Symantec
- java 程序的启动界面
- Android Studio——Dialogde 的主题报错
- Java多线程(三)、线程同步
- android.util.AndroidRuntimeException: requestFeature() must be called before adding content
- 设置 AlertDialog窗口的大小
- 解码未知结构的JSON数据