autotools生成Makefile

自己需编写,Makefile.am



通过搜索资料和自身体会总结autotools的一个简单使用方法。


大致包括如下命令:

autoscan

aclocal

autoconf

autoheader

automake


首先创建hello.c文件并编辑

  1. #include <stdio.h>  
  2.   
  3. int main()  
  4. {  
  5.     printf("hello\n");  
  6.     return 0;  
  7. }  

(1)autoscan

在源代码目录中执行 autoscan

生成configure.scan文件。

编辑configure.scan文件,通常添加如下两行

[plain]  view plain copy print ?
  1. AM_INIT_AUTOMAKE(hello, 1.0)  
  2. AC_CONFIG_FILES([Makefile])  

并另存为configure.ac(或configure.in),和autoscan.log。

(2)aclocal

执行aclocal,工具根据configure.ac(或configure.in)生成aclocal.m4文件和autom4te.cache文件夹。

(3)autoconf

执行autoconf,生成configure文件。

(4)autoheader

执行autoheader,生成config.h.in文件。

(5)automake

新建文件Makefile.am并编辑

[plain]  view plain copy print ?
  1. AUTOMAKE_OPTIONS=foreign  
  2. bin_PROGRAMS=hello  
  3. hello_SOURCES=hello.c  

执行automake,提示:
[plain]  view plain copy print ?
  1. configure.ac:8: error: required file './install-sh' not found  
  2. configure.ac:8:   'automake --add-missing' can install 'install-sh'  
  3. configure.ac:8: error: required file './missing' not found  
  4. configure.ac:8:   'automake --add-missing' can install 'missing'  
  5. Makefile.am: error: required file './depcomp' not found  
  6. Makefile.am:   'automake --add-missing' can install 'depcomp'  
  7.    

执行automake --add-missing

再执行automake

后面的过程即为熟知的

./configure

make

make install


补充:

autotools工具还提供 make dist 打包功能

执行 make dist

根据configure.ac中 

AC_INIT( [ hello ], [ 1.0 ] )

生成hello-1.0.tar.gz的源码包文件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值