Linux - 如何生成configure文件

Linux - 如何生成configure文件

简介

本文简单地介绍一下如何生成configure文件,主要目的是把握整体的流程,以后如果要用到再仔细阅读对应文档。

整体的过程

在Linux下面手动编译什么东西的时候,一般都是下面三步:

./configure
make
make install

其中configure的作用是根据Makefile.in生成Makefile,然后才能make。要生成configure文件,需要用到一套工具,叫做autotools。

autotools的简单工作流程如下:

                    +---------+
                    |         |
                    |         |
 Makefile.am +----> | automake| +-------> Makefile.in +-----+
                    |         |                             |
                    |         |                             |
                    |         |                             |
                    +---------+                             |
                                                            |
                    +---------+                             |
                    |         |                             |
                    |         |                             v
configure.ac +----> | autoconf| +-------> configure  +------+-----> Makefile
                    |         |
                    |         |
                    |         |
                    +---------+

autotools包括automake, autoconf 以及其他一些工具。automake用于生成Makefile 的模板Makefile.inautoconf用于生成configure文件。

示例

首先准备一下源文件:

#include <stdio.h>

int
main(int argc, char* argv[])
{
    printf("Hello world\n");
    return 0;
}

编写configure.ac文件:

AC_INIT([helloworld], [0.2], [me@google.com]) # 程序的名字,版本,开发者
AM_INIT_AUTOMAKE        # 初始化automake
AC_PROG_CC              # 使用C编译器
AC_CONFIG_FILES([Makefile]) # configure的输出文件
AC_OUTPUT               # 输出

然后编写Makefile.am文件:

AUTOMAKE_OPTIONS = foreign	#这是一个foreign项目,具体见参考中GNU automake文档List of Automake options
bin_PROGRAMS = helloworld	#输出的二进制
helloworld_SOURCES = main.c	#源文件列表

三个文件都准备好了之后,依次运行:

$ aclocal
$ autoconf
$ automake --fix-missing

然后就会发现Makefile.in以及configure都已经生成了。


参考:

  • https://thoughtbot.com/blog/the-magic-behind-configure-make-make-install
  • GNU automake
  • 4
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值