懒人学习automake, Makefile.am,configure.ac

本文详细介绍如何从已有的Makefile.am生成Makefile的过程。通过一系列命令如autoscan、autoconf及automake等,逐步构建出完整的Makefile文件。此外,还提供了一个具体的Makefile.am示例代码,帮助读者更好地理解整个流程。

已经存在Makefile.am,如何生成Makefile?


步骤:

[root@localhost hello]# autoscan .///在当前文件夹中搜索

[root@localhost hello]# cp configure.scan configure.ac //复制文件
[root@localhost hello]# vi configure.ac //编辑文件

    编辑configure.ac,加入下面一行:
    AM_INIT_AUTOMAKE(hello,1.0)      //automake所必备的宏,必须添加

[root@localhost hello]# aclocal     //执行aclocal生成aclocal.m4文件
[root@localhost hello]# autoconf   //执行autoconf生成configure文件
[root@localhost hello]# autoheader
[root@localhost hello]# automake --add-missing
[root@localhost hello]# touch NEWS; touch README; touch AUTHORS; touch ChangeLog    //创建NEWS等文件,如果没有自动生成,手工创建
[root@localhost hello]# automake --add-missing //再运行一次
[root@localhost hello]# ./configure    //配置,生成Makefile文件
[root@localhost hello]# make     //执行make命令


以上过程可能出现一些警告,请忽略。最后,给出一个Makefile.am的内容作为例子:

AM_LDFLAGS = -lpthread -lc -lm -lrt -ldl
CXXFLAGS = -D__STDC_LIMIT_MACROS -g -Wall -DORDER_SERIALIZE #-O2 -fno-strict-aliasing

bin_PROGRAMS = parser_main
parser_main_SOURCES = parser_main.cpp \
                Parser.cpp \
                Lexer.cpp \
    SelectStmt.cpp \
    InsertStmt.cpp \
    UpdateStmt.cpp \
    DeleteStmt.cpp \
    Stmt.cpp \
    Expr.cpp \
                Identifier.cpp
~                                



参考文献:

http://os.51cto.com/art/201006/207098.htm

http://os.51cto.com/art/201006/207099.htm

http://os.51cto.com/art/201006/207101.htm


如何写Makefile.am


<think>我们正在讨论的是autotools工具链中的两个关键文件:configure.acMakefile.am。 首先,用户要求简述这两个文件的作用、内容和使用场景。 根据autotools的工作流程: 1. configure.ac(以前叫configure.in)是autoconf工具的输入文件,用于生成configure脚本。 2. Makefile.amautomake工具的输入文件,用于生成Makefile.in(再由configure脚本生成最终的Makefile)。 下面我将分别简述这两个文件。 </think>### configure.acMakefile.am 的简述 #### 一、configure.ac 的作用与内容 **作用**: 作为 Autoconf 工具的核心输入文件,用于生成可移植的 `configure` 脚本。该脚本负责检测系统环境(如编译器、库依赖、平台特性等),最终生成适配当前系统的 `Makefile`。 **典型内容**: ```m4 AC_INIT([项目名], [版本号]) # 初始化项目信息 AM_INIT_AUTOMAKE # 初始化Automake AC_PROG_CC # 检测C编译器 AC_CHECK_HEADER([stdio.h]) # 检查头文件 AC_CHECK_LIB([m], [sin]) # 检查数学库 AC_CONFIG_FILES([Makefile]) # 指定输出文件 AC_OUTPUT # 结束配置 ``` **使用场景**: - 跨平台项目编译(如 Linux/macOS/BSD 兼容) - 动态处理依赖库(自动检测缺失库并报错) - 生成标准化的 `config.h` 头文件(保存系统配置宏) #### 二、Makefile.am 的作用与内容 **作用**: 作为 Automake 工具的输入文件,定义编译规则和文件结构,最终生成符合 GNU 标准的 `Makefile.in` 模板(供 `configure` 脚本使用)。 **典型内容**: ```makefile bin_PROGRAMS = myapp # 生成可执行文件 myapp myapp_SOURCES = main.c util.c # 源文件列表 include_HEADERS = utils.h # 安装头文件 dist_data_DATA = config.ini # 打包数据文件 ``` **使用场景**: - 自动化编译流程(自动推导依赖关系) - 生成安装/卸载规则(`make install` / `make uninstall`) - 打包发布(`make dist` 生成 .tar.gz 源码包) #### 三、协同工作流程 1. **生成工具链**: ```bash aclocal &amp;&amp; autoconf &amp;&amp; automake --add-missing ``` 2. **用户编译**: ```bash ./configure &amp;&amp; make &amp;&amp; make install ``` `configure.ac` 生成 `configure` 脚本 → `Makefile.am` 生成 `Makefile.in` → `configure` 结合两者生成最终 `Makefile`。 **核心价值**: 解决跨平台编译的复杂性,开发者无需手动编写和维护平台相关的编译规则[^1]。例如,通过 `AC_CHECK_LIB` 自动处理库依赖,避免硬编码路径[^2]。 --- ### 相关问题 1. 如何在 `configure.ac` 中检测 OpenSSL 库是否存在? 2. `Makefile.am` 中的 `_PROGRAMS` 和 `_LIBRARIES` 后缀有何区别? 3. Autotools 工具链包含哪些组件及其相互关系? 4. 如何通过 `make distcheck` 验证源码包的完整性?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值