什么是Makefile.am和Makefile.in?

本文翻译自:What are Makefile.am and Makefile.in?

These two files are mostly seen in open source projects. 这两个文件主要出现在开源项目中。

What are they for, and how do they work? 它们是什么,它们是如何工作的?


#1楼

参考:https://stackoom.com/question/Acdv/什么是Makefile-am和Makefile-in


#2楼

Makefile.am is a programmer-defined file and is used by automake to generate the Makefile.in file (the .am stands for a uto m ake). Makefile.am是一个程序员定义的文件,由automake用来生成Makefile.in文件( .am代表一个 uto m ake)。 The configure script typically seen in source tarballs will use the Makefile.in to generate a Makefile . 通常在源tarball中看到的configure脚本将使用Makefile.in生成Makefile

The configure script itself is generated from a programmer-defined file named either configure.ac or configure.in (deprecated). configure脚本本身是从名为configure.acconfigure.in (不建议使用)的程序员定义的文件生成的。 I prefer .ac (for a uto c onf) since it differentiates it from the generated Makefile.in files and that way I can have rules such as make dist-clean which runs rm -f *.in . 我喜欢.ac对于反对派çONF),因为它从产生区别它Makefile.in文件,这样我可以有规则,如make dist-clean它运行rm -f *.in Since it is a generated file, it is not typically stored in a revision system such as Git, SVN, Mercurial or CVS, rather the .ac file would be. 由于它是生成的文件,因此通常不会存储在诸如Git,SVN,Mercurial或CVS之类的修订系统中,而是存储在.ac文件中。

Read more on GNU Autotools . 阅读更多GNU Autotools 。 Read about make and Makefile first, then learn about automake , autoconf , libtool , etc. 首先阅读makeMakefile ,然后了解automakeautoconflibtool等。


#3楼

Simple example 简单的例子

Shamelessly adapted from: http://www.gnu.org/software/automake/manual/html_node/Creating-amhello.html and tested on Ubuntu 14.04 Automake 1.14.1. 无耻地改编自: http : //www.gnu.org/software/automake/manual/html_node/Creating-amhello.html并在Ubuntu 14.04 Automake 1.14.1上进行了测试。

Makefile.am Makefile.am

SUBDIRS = src
dist_doc_DATA = README.md

README.md README.md

Some doc.

configure.ac configure.ac

AC_INIT([automake_hello_world], [1.0], [[email protected]])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
 Makefile
 src/Makefile
])
AC_OUTPUT

src/Makefile.am SRC / Makefile.am

bin_PROGRAMS = autotools_hello_world
autotools_hello_world_SOURCES = main.c

src/main.c SRC / main.c中

#include 
#include 

int main (void) {
  puts ("Hello world from " PACKAGE_STRING);
  return 0;
}

Usage 用法

autoreconf --install
mkdir build
cd build
../configure
make
sudo make install
autoconf_hello_world
sudo make uninstall

This outputs: 这输出:

Hello world from automake_hello_world 1.0

Notes 笔记

  • autoreconf --install generates several template files which should be tracked by Git, including Makefile.in . autoreconf --install生成几个模板文件,应由Git跟踪,包括Makefile.in It only needs to be run the first time. 它只需要第一次运行。

  • make install installs: make install安装:

    • the binary to /usr/local/bin 二进制文件到/usr/local/bin
    • README.md to /usr/local/share/doc/automake_hello_world README.md/usr/local/share/doc/automake_hello_world

On GitHub for you to try it out. 在GitHub上你可以尝试一下。


#4楼

reference : 参考 :

Makefile.am -- a user input file to automake Makefile.am - 要自动化的用户输入文件

configure.in -- a user input file to autoconf configure.in - autoconf的用户输入文件


autoconf generates configure from configure.in autoconf从configure.in生成configure

automake gererates Makefile.in from Makefile.am automake从Makefile.am创建Makefile.in

configure generates Makefile from Makefile.in configure从Makefile.in生成Makefile

For ex: 例如:

$]
configure.in Makefile.in
$] sudo autoconf
configure configure.in Makefile.in ... 
$] sudo ./configure
Makefile Makefile.in

#5楼

DEVELOPER runs these: 开发者运行这些:

1) autoconf -- creates shippable configure script (which the installer will run to make the Makefile ) 1) autoconf - 创建可发送的配置脚本(安装程序将运行生成Makefile
2) automake - creates shippable Makefile.in (which configure will later read to make the Makefile ) 2) automake - 创建可发送的Makefile.in配置将在以后读取生成Makefile

INSTALLER runs these: INSTALLER运行这些:

./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

INPUTS -> PROGRAMS -> OUTPUTS: INPUTS - > PROGRAMS - > OUTPUTS:

DEVELOPER runs these: 开发者运行这些:

configure.in --> autoconf -> configure (script) --- (configure. in is depreciated. Now use configure.ac) configure.in - > autoconf的 - > 配置 (脚本)---(。 配置折旧现在使用configure.ac)
configure.ac -> autoconf -> configure (script) --- (*. ac = a uto c onf) configure.ac - > autoconf - > configure (script)---(*。 ac = a uto c onf)

Makefile.am -> automake -> Makefile.in ----------- (*. am = a uto m ake) Makefile.am - > automake - > Makefile.in -----------(*。 am = a uto m ake)

INSTALLER runs these: INSTALLER运行这些:

Makefile.in -> configure -> Makefile (*. in = in put file) Makefile.in - > 配置 - > 生成文件 (*。 放文件=)

Makefile -> make -> (the new software in your downloads or temporary directory) Makefile - > make - >(下载或临时目录中的新软件)
Makefile -> make install -> (puts new software in system directory) Makefile - > make install - >(将新软件放入系统目录)


" Autoconf is an extensible package of M4 macros that produce shell scripts to automatically configure software source code packages. These scripts can adapt the packages to many kinds of UNIX-like systems without manual user intervention. Autoconf creates a configuration script for a package from a template file that lists the operating system features that the package can use, in the form of M4 macro calls." Autoconf是一个可扩展的M4宏包,可以生成shell脚本来自动配置软件源代码包。这些脚本可以使软件包适应多种类UNIX系统而无需用户手动干预.Autoconf为一个软件包创建一个配置脚本模板文件,以M4宏调用的形式列出软件包可以使用的操作系统功能。“

" Automake is a tool for automatically generating Makefile.in files compliant with the GNU Coding Standards. Automake requires the use of Autoconf." Automake是一个自动生成符合GNU编码标准的Makefile.in文件的工具.Automake需要使用Autoconf。”

Manuals: 手册:

  • m4 (used by autoconf) m4 (由autoconf使用)
  • autoconf autoconf的
  • automake automake的

Interesting facts: 有趣的事实:
The main configure.ac used to build LibreOffice is over 12k lines of code, (but there are also 57 other configure.ac files in subfolders.) 用于构建LibreOffice的主要configure.ac是超过12k行代码,(但子文件夹中还有57个其他configure.ac文件。)
From this my generated configure is over 41k lines of code. 由此我生成的配置超过41k行代码。
While the Makefile.in and Makefile are both only 493 lines of code. Makefile.inMakefile都只有493行代码。 (But, there are also 768 more Makefile.in's in subfolders.) (但是,子文件夹中还有768个Makefile.in。)

你可能感兴趣的:(makefile,autotools,automake)