Makefile自动生成工具-----autotools的使用(详细)
相信每个学习Linux的人都知道Makefile,这是一个很有用的东西,但是编写它是比较复杂,今天介绍一个它的自动生成工具,autotools的使用。很多GNULinux的的软件都是用它生成Makefile的,包括我们非常熟悉的Linux内核源代码。
1、准备:
需要工具
autoscan
aclocal
autoheader
automake
autoconf
auto make
在终端敲入命令,哪个没有安装哪个,一般是第一个autoscan没有,其它的我用的Ubuntu10.04下全部都有
2、测试程序编写:
建立目录:mkdir include src
编写程序:include/str.h
- #include <stdio.h>
- int str(char *string);
编写程序:src/str.c
- #include "str.h"
- //print string
- int str(char *string){
- printf("\n----PRINT STRING----\n\"%s\"\n",string);
- return 0;
- }
- //interface of this program
- int main(int argc , char **argv){
- char str_read[1024];
- printf("Please INPUT something end by [ENTER]\n");
- scanf("%s",str_read);
- return str(str_read );
- }
3、生成configure.ac
configure.ac是automake的输入文件,所以必须先生成该文件。
执行命令:
- [root@localhost str]# ls
- include src
- [root@localhost str]# autoscan
- autom4te: configure.ac: no such file or directory
- autoscan: /usr/bin/autom4te failed with exit status: 1
- [root@localhost str]# ls
- autoscan.log configure.scan include src
- [root@localhost str]# cp configure.scan configure.ac
修改 configure.ac
- # -*- Autoconf -*-
- # Process this file with autoconf to produce a configure script.
- AC_PREREQ(2.59)
- AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
- AC_CONFIG_SRCDIR([include/str.h])
- AC_CONFIG_HEADER([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
修改
- AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
改为:
- AC_INIT(str,0.0.1, [bug@sounos.org])
其中:FULL-PACKAGE-NAME 为程序名称,VERSION为当前版本, BUG-REPORT-ADDRESS为bug汇报地址
然后添加两句话:
AM_INIT_AUTOMAKE
AC_CONFIG_FILES([Makefile])
结果如下:(两句话不是在一起的)
- # -*- Autoconf -*-
- # Process this file with autoconf to produce a configure script.
- AC_PREREQ(2.59)
- #AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
- AC_INIT(str, 0.0.1, [bug@sounos.org])
- AM_INIT_AUTOMAKE
- AC_CONFIG_SRCDIR([include/str.h])
- AC_CONFIG_HEADER([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_CONFIG_FILES([Makefile])
- AC_OUTPUT
4、执行aclocal
- [root@localhost str]# aclocal
- /usr/share/aclocal/libfame.m4:6: warning: underquoted definition of AM_PATH_LIBFAME
- run info '(automake)Extending aclocal'
- or see http://sources.redhat.com/automake/automake.html#Extending-aclocal
5、制作Makefile.am
- [root@localhost str]# vi Makefile.am
- #Makefile.am
- bin_PROGRAMS = str
- str_SOURCES = include/str.h src/str.c
- str_CPPFLAGS = -I include/
automake 这个命令需要用到这个配置文件。各个选项意思比较直观,不多说。
6、autoheader
- [root@localhost str]# autoheader
7、automake必须文件:
- * install-sh
- * missing
- * INSTALL
- * NEWS
- * README
- * AUTHORS
- * ChangeLog
- * COPYING
- * depcomp
其中,以下文件在执行automake -a的时候会自动生成
- * install-sh
- * missing
- * INSTALL
- * COPYING
- * depcomp
所以,接下来手动生成剩下的文件
- [root@localhost str]# touch NEWS README AUTHORS ChangeLog
8、执行automake -a
- [root@localhost str]# automake -a
- configure.ac: installing `./install-sh'
- configure.ac: installing `./missing'
- Makefile.am: installing `./INSTALL'
- Makefile.am: installing `./COPYING'
- Makefile.am: installing `./compile'
- Makefile.am: installing `./depcomp'
9、autoconf
- [root@localhost str]# autoconf
- [root@localhost str]# ls
- aclocal.m4 autoscan.log config.h.in configure.scan include Makefile.am NEWS
- AUTHORS ChangeLog configure COPYING INSTALL Makefile.in README
- autom4te.cache compile configure.ac depcomp install-sh missing src
10、执行测试:
执行./configure
- [root@localhost str]# ./configure --prefix=/u
- checking for a BSD-compatible install... /usr/bin/install -c
- checking whether build environment is sane... yes
- checking for gawk... gawk
- checking whether make sets $(MAKE)... yes
- checking for gcc... gcc
- checking for C compiler default output file name... a.out
- checking whether the C compiler works... yes
- checking whether we are cross compiling... no
- checking for suffix of executables...
- 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 ANSI C... none needed
- checking for style of include used by make... GNU
- checking dependency style of gcc... gcc3
- configure: creating ./config.status
- config.status: creating Makefile
- config.status: creating config.h
- config.status: config.h is unchanged
- config.status: executing depfiles commands
执行 make
- [root@localhost str]# make
- make all-am
- make[1]: Entering directory `/data/devel/c/str'
- if gcc -DHAVE_CONFIG_H -I. -I. -I. -I include/ -g -O2 -MT str-str.o -MD -MP -MF ".deps/str-str.Tpo" -c -o str-str.o `test -f 'src/str.c' || echo './'`src/str.c; \
- then mv -f ".deps/str-str.Tpo" ".deps/str-str.Po"; else rm -f ".deps/str-str.Tpo"; exit 1; fi
- gcc -g -O2 -o str str-str.o
- make[1]: Leaving directory `/data/devel/c/str'
此时已经生成了 str(可执行文件名字在前面设置Makefile.am的参数时候去顶)这个,可以通过./str直接看到运行结果
- [root@localhost str]# ./str
- Please INPUT something end by [ENTER]
- abcksdhfklsdklfdjlkfd
- ----PRINT STRING----
- "abcksdhfklsdklfdjlkfd"
不过这里我们都做一步,把它安装到系统里面,这样我们只要在终端输入str就可以运行程序了。
执行 make install:
- [root@localhost str]# make install
- make[1]: Entering directory `/data/devel/c/str'
- test -z "/u/bin" || mkdir -p -- "/u/bin"
- /usr/bin/install -c 'str' '/u/bin/str'
- make[1]: Nothing to be done for `install-data-am'.
- make[1]: Leaving directory `/data/devel/c/str'
接下来你可以make clean 清除安装的那些.o 文件了。
这样生成了一个自动的Makefile。
Makefile自动生成工具-----autotools的使用(详细)的更多相关文章
- C/C++ makefile自动生成工具(comake2,autotools,linux),希望能为开源做点微薄的贡献!
序 在linux下C或C++项目开发,Makefile是必备的力气,但是发现手写很麻烦. 在百度有个comake2工具,用于自动生成Makefile工具,而在外边本想找一个同类工具,但发现 ...
- Makefile自动生成头文件依赖
前言 Makefile自动生成头文件依赖是很常用的功能,本文的目的是想尽量详细说明其中的原理和过程. Makefile模板 首先给出一个本人在小项目中常用的Makefile模板,支持自动生成头文件依赖 ...
- h5自动生成工具
一.前言 写了很多h5之后,对于写手写html和css已经麻木的我决定动手写个工具自动生成h5结构和样式.其实这个想法由来已久,但总是觉得自己技术不够,所以一直没实行.直到某天我真的写够了,我决定动手 ...
- 代码自动生成工具MyGeneration之一(程序员必备工具)
代码自动生成工具MyGeneration之一(程序员必备工具) 转 分类: C#2008-08-06 18:12 16064人阅读 评论(12) 收藏 举报 工具数据库相关数据库stringbrows ...
- Linux Makefile自动生成--config.h
Linux Makefile自动生成--config.h http://blog.csdn.net/spch2008/article/details/12510805
- Asp.net mvc 5 CRUD代码自动生成工具- vs.net 2013 Saffolding功能扩展
Asp.net mvc 5 CRUD代码自动生成工具 -Visual Studio.net2013 Saffolding功能扩展 上次做过一个<Asp.net webform scaffoldi ...
- springboot成神之——swagger文档自动生成工具
本文讲解如何在spring-boot中使用swagger文档自动生成工具 目录结构 说明 依赖 SwaggerConfig 开启api界面 JSR 303注释信息 Swagger核心注释 User T ...
- 基于数据库的代码自动生成工具,生成JavaBean、生成数据库文档、生成前后端代码等(v6.0.0版)
TableGo v6.0.0 版震撼发布,此次版本更新如下: 1.UI界面大改版,组件大调整,提升界面功能的可扩展性. 2.新增BeautyEye主题,界面更加清新美观,也可以通过配置切换到原生Jav ...
- C# 代码自动生成工具
开源:C# 代码自动生成工具,支持站点前后台 前言 写这个项目有很长一段时间了,期间也修修改改,写到最后,自己也没咋用(研究方向变化了). 正文 具体项目开源了:https://github.co ...
随机推荐
- C与C++ 无参函数的区别
在<C++ 编程思想>:“关于无参函数声明,C与C++有很大的差别.在C语言中,声明int fun1(),意味着一个可以有任意数目和类型的函数:而在C++中,指的却是一个没有参数的函数”. ...
- vim插件配置(一)
vim代码自动显示提示代码插件:AutoComplPop: 代码(普通变量函数) c/c++代码(类的 . , ->, :: 操作符)的自动补全插件: OmniCppComplete
- ThinkPHP - I 函数
ThinkPHP函数详解:I方法 浏览:144722 发布日期:2013/06/01 分类:文档教程 关键字: 函数 ThinkPHP的I方法是3.1.3版本新增的,如果你是之前的3.*版本的话, ...
- 翻页采用jaxa
<!-- 翻页采用jaxa --><script type="text/javascript">//class="page"下面的a被点 ...
- Ural 1297 Palindrome 【最长回文子串】
最长回文子串 相关资料: 1.暴力法 2.动态规划 3.中心扩展 4.Manacher法 http://blog.csdn.net/ywhorizen/article/details/6629268 ...
- 为什么使用LUT比GAL 节省资源
为什么使用LUT比GAL 节省资源 A[1:0] B[1:0] 实现一个比较器,如果A=B输出1 否则输出0 传统的GAL 需要 24= 16个存储单元(ROM)来存储结果数据,实现方法 ...
- 飞翔(LIS变形)
飞翔 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 鹰最骄傲的就是翱翔,但是鹰们互相都很嫉妒别的鹰比自己飞的快,更嫉妒其他的鹰比自己飞行的有技巧.于是,他们决定举办一场 ...
- Technology_Roadmap
2016年1月23日 前端技术: - HTML CSS JavaScript JQuery 操作系统: - Linux (CentOS) 数据库: - SQLServer MySQL 开源前端框架: ...
- 嵌入式MCU开发群资源
STM32CubeMX是一款图形化软件设置工具,允许使用图形化向导来生成C初始化代码.它是未来开发stm32系列产品的主流软件,是ST公司的主动原创,可以减轻开发工作,时间和费用.STM32Cube ...
- 数据库基础学习3-T-SQL语句
一.语句操作的基本方法 1.选中执行. 2.注释的方法‘--’. 二.数据类型 整数:int,bigint,smallint 小数:float,decimal(长度,精度) 字符:char(n),va ...