./configure 自动生成makefile

新建helloworld目录,里边有一个源码文件helloworld.c。

$ autoscan 
$ ls 
configure.scan helloworld.c 

新生成的文件configure.scan改名为configure.in,并编辑修改内容,去掉无关的语句: 

===================configure.in内容开始============= 
# -*- Autoconf -*- 
# Process this file with autoconf to produce a configure script. 

AC_INIT(helloworld.c) 
AM_INIT_AUTOMAKE(helloworld, 1.0) 

# 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) 
=====================configure.in内容结束================== 

$ aclocal 
$ls 
aclocal.m4 configure.in helloworld.c 
$ autoconf 
$ ls 
aclocal.m4 autom4te.cache configure configure.in helloworld.c 

新产生aclocal.m4及configure两个文件。

aclocal是一个perl 脚本程序,它的定义是:“aclocal - create aclocal.m4 by scanning configure.ac”。 aclocal根据configure.in文件的内容,自动生成aclocal.m4文件。

autoconf 是用来生成自动配置软件源代码脚本(configure)的工具。autoconf从configure.in这个列举编译软件时所需要各种参数的模板文件中创建configure。 autoconf需要GNU m4宏处理器来处理aclocal.m4,生成configure脚本。 

m4是一个宏处理器。

新建Makefile.am文件,内容如下: 
AUTOMAKE_OPTIONS=foreign 
bin_PROGRAMS=helloworld 
helloworld_SOURCES=helloworld.c 

automake会根据你写的Makefile.am来自动生成Makefile.in。 
Makefile.am中定义的宏和目标,会指导automake生成指定的代码。例如,宏bin_PROGRAMS将导致编译和连接的目标被生成。 

运行automake命令如下:将会生成configure文件
$ automake --add-missing 
configure.in: installing `./install-sh' 
configure.in: installing `./mkinstalldirs' 
configure.in: installing `./missing' 
Makefile.am: installing `./depcomp' 

automake会根据Makefile.am文件产生一些文件,包含最重要的Makefile.in。 

执行configure生成Makefile 

$ ./configure 

使用Makefile编译代码 
$ make 

运行helloworld 

$ ./helloworld 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

步基

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值