[英]What are Makefile.am and Makefile.in?
这两个文件多见于开源项目。
它们是做什么用的,它们是如何工作的?
Makefile.am
是一个程序员定义的文件,并且用于通过automake
以生成Makefile.in
文件( .am
代表一个UTO米AKE)。 通常在源 tarball 中看到的configure
脚本将使用Makefile.in
生成Makefile
。
configure
脚本本身是从名为configure.ac
或configure.in
(已弃用)的程序员定义的文件生成的。 我喜欢.ac
(对于反对派çONF),因为它从产生区别它Makefile.in
文件,这样我可以有规则,如make dist-clean
它运行rm -f *.in
。 由于它是生成的文件,因此通常不会存储在 Git、SVN、Mercurial 或 CVS 等修订系统中,而是.ac
文件。
阅读更多关于GNU Autotools 的信息。 首先阅读make
和Makefile
,然后了解automake
、 autoconf
、 libtool
等。
简单的例子
无耻地改编自: http : //www.gnu.org/software/automake/manual/html_node/Creating-amhello.html并在 Ubuntu 14.04 Automake 1.14.1 上测试。
生成文件
SUBDIRS = src
dist_doc_DATA = README.md
自述文件
Some doc.
配置文件
AC_INIT([automake_hello_world], [1.0], [bug-automake@gnu.org])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
Makefile
src/Makefile
])
AC_OUTPUT
源代码/Makefile.am
bin_PROGRAMS = autotools_hello_world
autotools_hello_world_SOURCES = main.c
src/main.c
#include <config.h>
#include <stdio.h>
int main (void) {
puts ("Hello world from " PACKAGE_STRING);
return 0;
}
用法
autoreconf --install
mkdir build
cd build
../configure
make
sudo make install
autotools_hello_world
sudo make uninstall
这输出:
Hello world from automake_hello_world 1.0
笔记
autoreconf --install
生成几个应该由 Git 跟踪的模板文件,包括Makefile.in
。 它只需要第一次运行。
make install
安装:
/usr/local/bin
README.md
到/usr/local/share/doc/automake_hello_world
在 GitHub 上供您试用。
autoconf
和automake
:configure
, make
和sudo make install
:./configure # Creates Makefile (from Makefile.in).
make # Creates the application (from the Makefile just created).
sudo make install # Installs the application
# Often, by default its files are installed into /usr/local
下面的符号大致是:输入 --> 程序 --> 输出
开发人员运行这些:
configure.ac - >的autoconf - >配置(脚本)---(* AC =一个UTOÇONF。)
configure.in --> autoconf -> configure (script) --- ( configure.in
depreciated. Use configure.ac)
Makefile.am - >的automake - > Makefile.in -----------(。*是= A UTO米AKE)
安装程序运行这些:
Makefile.in - >配置- (。*在放文件=)>的Makefile
Makefile -> make ---------->(将新软件放在您的下载或临时目录中)
Makefile -> make install ->(将新软件放入系统目录)
" autoconf是一个可扩展的 M4 宏包,它生成 shell 脚本来自动配置软件源代码包。这些脚本可以使包适应多种类 UNIX 系统,而无需用户手动干预。Autoconf 从一个包创建配置脚本。以 M4 宏调用的形式列出软件包可以使用的操作系统功能的模板文件。”
“ automake是一种自动生成符合 GNU 编码标准的 Makefile.in 文件的工具。Automake 需要使用 Autoconf。”
手册:
GNU AutoTools (这方面的权威手册)
m4 (由 autoconf 使用)
免费在线教程:
用于构建 LibreOffice 的主要configure.ac代码超过 12k 行,(但在子文件夹中还有 57 个其他 configure.ac 文件。)
由此我生成的配置超过 41k 行代码。
而Makefile.in和Makefile都只有 493 行代码。 (但是,子文件夹中还有 768 个 Makefile.in。)
参考:
Makefile.am -- automake 的用户输入文件
configure.in -- 自动配置的用户输入文件
autoconf 从 configure.in 生成配置
automake 从 Makefile.am 生成 Makefile.in
configure 从 Makefile.in 生成 Makefile
例如:
$]
configure.in Makefile.in
$] sudo autoconf
configure configure.in Makefile.in ...
$] sudo ./configure
Makefile Makefile.in
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.