0xAA55 发表于 2015-12-26 17:54:27

【搬运】【翻译】什么是Makefile.am和Makefile.in?

原网址:http://stackoverflow.com/questions/2531827/what-are-makefile-am-and-makefile-in

提问:
这两个文件经常在各种开源项目里能见到。它们有什么用?怎么用?

回答:
Makefile.am是程序员写的文件,用于让automake来产生Makefile.in文件(.am指的是automake)。通常可以在各种用tar压缩的源码项目里看到配置脚本用Makefile.in来生成Makefile。

配置脚本自身也是被程序员写的configure.ac(以前是configure.in)生成的。我更喜欢用.ac的后缀(.c指的是autoconf)因为它后缀和生成的Makefile.in不一样,这样我就可以用rm -f *.in来删除所有的自动生成的.in文件而不会删除自己写的configure.ac。因为.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

一个例子:
Makefile.am:SUBDIRS = src
dist_doc_DATA = README.mdREADME.md:一些文档configure.ac:AC_INIT(, , )
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_CONFIG_HEADERS()
AC_CONFIG_FILES([
Makefile
src/Makefile
])
AC_OUTPUTsrc/Makefile.am:bin_PROGRAMS = autotools_hello_world
autotools_hello_world_SOURCES = main.csrc/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
autoconf_hello_world
sudo make uninstall输出:Hello world from automake_hello_world 1.0注意:Notes
[*]autoreconf --install生成的一些临时文件应该被Git存起来,包括Makefile.in。这语句只需要运行一次。
[*]make install安装了以下的文件:[*]可执行文件,在/usr/local/bin
[*]README.md文档,在/usr/local/share/doc/automake_hello_world例子在GitHub有一份,你可以拿来试试。
https://github.com/cirosantilli/linux-cheat/tree/63278c7ac22721f7fa089cba32e93adf87724e3c/autotools/hello-world
页: [1]
查看完整版本: 【搬运】【翻译】什么是Makefile.am和Makefile.in?