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 ...
随机推荐
- Unity KillCount
using UnityEngine; using System.Collections; public class KillCountMult : MonoBehaviour { public GUI ...
- c/c++字符数组和字符串大揭秘
第一:写这篇文章源于我对'\0'和“\0”的探讨 当我对char a []="\0"; int size_a=sizeof(a); //结果为2 当时我很纳闷字符串不是以'\0'结 ...
- VMware Workstation9安装Mac OS X10.9系统
链接地址:http://jingyan.baidu.com/article/aa6a2c142cef740d4c19c426.html VMware Workstation9.0安装Mac OS X1 ...
- redis(三)redis+Keepalived主从热备秒级切换
一 简介 安装使用centos 5.10 Master 192.168.235.135 Slave 192.168.235.152 Vip 192.168.235.200 编译环境 yum -y in ...
- 设计模式(十二)职责链模式(Chain of Responsibility)(对象行为型)
设计模式(十二)职责链模式(Chain of Responsibility)(对象行为型) 1.概述 你去政府部门求人办事过吗?有时候你会遇到过官员踢球推责,你的问题在我这里能解决就解决,不能解决就 ...
- android学习--视图列表(ListView和ListActivity)
说明: 视图列表(ListView和ListActivity)与AutoComplete.Spinner类似,它们都须要一个供显示的列表项,能够须要借助于内容Adapter提供显示列表项 创建List ...
- BZOJ 1578: [Usaco2009 Feb]Stock Market 股票市场( 背包dp )
我们假设每天买完第二天就卖掉( 不卖出也可以看作是卖出后再买入 ), 这样就是变成了一个完全背包问题了, 股票价格为体积, 第二天的股票价格 - 今天股票价格为价值.... 然后就一天一天dp... ...
- 数据库神器:Navicat Premium
Navicat premium是一款数据库管理工具.将此工具连接数据库,你可以从中看到各种数据库的详细信息.包括报错,等等.当然,你也可以通过他,登陆数据库,进行各种操作.Navicat Premiu ...
- 《Python爬虫学习系列教程》学习笔记
http://cuiqingcai.com/1052.html 大家好哈,我呢最近在学习Python爬虫,感觉非常有意思,真的让生活可以方便很多.学习过程中我把一些学习的笔记总结下来,还记录了一些自己 ...
- 回归基础从新认识——HTML+CSS
前言 这段时间工作没那么繁杂,索性就想说来套系统的学习,之前去面试的时候,有被问及些基础的知识,居然回答不上来,也不能说是回答不上吧,回答的不全面.前端群上问了那个机构比较好,选择了慕课网.看了一段时 ...