简体   繁体   English

对配置脚本和 Makefile.in 感到困惑

[英]Confused about configure script and Makefile.in

I'm currently learning how to use the autoconf / automake toolchain.我目前正在学习如何使用autoconf / automake工具链。 I seem to have a general understanding of the workflow here - basically you have a configure.ac script which generates an executable configure file.我似乎对这里的工作流程有一个大致的了解 - 基本上你有一个configure.ac脚本,它生成一个可执行的configure文件。 The generated configure script is then executed by the end user to generate Makefile s, so the program can be built/installed.生成的configure脚本然后由最终用户执行以生成Makefile ,因此可以构建/安装程序。

So the installation for a typical end-user is basically:因此,典型最终用户的安装基本上是:

./configure
make
make install
make clean

Okay, now here's where I'm confused:好的,现在这是我感到困惑的地方:

As a developer, I've noticed that the auto-generated configure script sometimes won't run, and will error with:作为开发人员,我注意到自动生成的配置脚本有时无法运行,并且会出现以下错误:

config.status: error: cannot find input file: `somedir/Makefile.in' 

This confuses me, because I thought the configure script is supposed to generate the Makefile.in .这让我很困惑,因为我认为配置脚本应该生成Makefile.in So Googling around for some answers, I've discovered that this can be fixed with an autogen.sh script, which basically "resets" the state of the autoconf environment.因此,在谷歌上搜索一些答案,我发现这可以通过autogen.sh脚本来解决,该脚本基本上“重置”了autoconf环境的状态。 A typical autogen.sh script would be something like:典型的autogen.sh脚本类似于:

aclocal \
&& automake --add-missing \
&& autoconf

Okay fine.好的。 But as an end-user who's downloaded countless tarballs throughout my life, I've never had to use an autogen.sh script.但作为一个终生下载无数 tarball 的最终用户,我从未使用过autogen.sh脚本。 All I did was uncompress the tarball, and do the usual configure/make/make install/make clean routine.我所做的只是解压缩 tarball,然后执行通常的 configure/make/make install/make clean 例程。

But as a developer who's now using autoconf , it seems that configure doesn't actually run unless you run autogen.sh first.但是作为现在使用autoconf的开发人员,除非您先运行autogen.sh否则configure实际上不会运行。 So I find this very confusing, because I thought the end-user shouldn't have to run autogen.sh .所以我觉得这很令人困惑,因为我认为最终用户不应该运行autogen.sh

So why do I have to run autogen.sh first - in order for the configure script to find Makefile.in ?那么为什么我必须先运行autogen.sh - 为了让配置脚本找到Makefile.in Why doesn't the configure script simply generate it?为什么配置脚本不简单地生成它?

In order to really understand the autotools utilities you have to remember where they come from: they come from an open source world where there are (a) developers who are working from a source code repository (CVS, Git, etc.) and creating a tar file or similar containing source code and putting that tar file up on a download site, and (b) end-users who are getting the source code tar file, compiling that source code on their system and using the resulting binary.为了真正理解 autotools 实用程序,您必须记住它们来自哪里:它们来自一个开源世界,其中有 (a) 开发人员在源代码存储库(CVS、Git 等)中工作并创建一个tar 文件或包含源代码的类似文件并将该 tar 文件放在下载站点上,以及 (b) 获取源代码 tar 文件、在其系统上编译该源代码并使用生成的二进制文件的最终用户。 Obviously the folks in group (a) also compile the code and use the resulting binary, but the folks in group (b) don't have or need, often, all the tools for development that the folks in group (a) need.显然,(a) 组的人也编译代码并使用生成的二进制文件,但 (b) 组的人通常没有或不需要 (a) 组的人需要的所有开发工具。

So the use of the tools is geared towards this split, where the people in group (b) don't have access to autoconf, automake, etc.因此,工具的使用是针对这种分裂的,即组 (b) 中的人无法访问 autoconf、automake 等。

When using autoconf, people generally check in the configure.ac file (input to autoconf) into source control but do not check in the output of autoconf, the configure script (some projects do check in the configure script of course: it's up to you).使用autoconf时,人们通常将configure.ac文件(autoconf的输入)签入源代码管理,但不签入autoconf的输出, configure脚本(当然有些项目确实签入了configure脚本:这取决于你)。

When using automake, people generally check in the Makefile.am file (input to automake) but do not check in the output of automake: Makefile.in .使用 automake 时,人们通常检查Makefile.am文件(automake 的输入)但不检查 automake 的输出: Makefile.in

The configure script basically looks at your system for various optional elements that the package may or may not need, where they can be found, etc. Once it finds this information, it can use it to convert various XXX.in files (typically, but not solely, Makefile.in ) into XXX files (for example, Makefile ). configure脚本基本上会在您的系统中查看包可能需要或不需要的各种可选元素,可以在何处找到它们等。一旦找到此信息,它就可以使用它来转换各种XXX.in文件(通常,但不仅仅是Makefile.in ) 到XXX文件(例如Makefile )。

So the steps generally go like this: write configure.ac and Makefile.am and check them in. To build the project from source code control checkout, run autoconf to generate configure from configure.ac .所以步骤通常是这样的:写configure.acMakefile.am ,并检查他们要建立从源代码控制检出的项目,以使autoconf去生成。 configureconfigure.ac Run automake to generate Makefile.in from Makefile.am .运行Automake生成Makefile.inMakefile.am Run configure to generate Makefile from Makefile.in .运行configure生成MakefileMakefile.in Run make to build the product.运行 make 来构建产品。

When you want to release the source code (if you're developing an open source product that makes source code releases) you run autoconf and automake, then bundle up the source code with the configure and Makefile.in files, so that people building your source code release just need make and a compiler and don't need any autotools.当你想发布源代码时(如果你正在开发一个发布源代码的开源产品),你运行 autoconf 和 automake,然后将源代码与configureMakefile.in文件捆绑在一起,以便人们构建你的源代码发布只需要 make 和编译器,不需要任何自动工具。

Because the order of running autoconf and automake (and libtool if you use it) can be tricky there are scripts like autogen.sh and autoreconf, etc. which are checked into source control to be used by developers building from source control, but these are not needed/used by people building from the source code release tar file etc.因为运行 autoconf 和 automake(和 libtool,如果你使用它)的顺序可能很棘手,所以有像 autogen.sh 和 autoreconf 等脚本,它们被签入源代码管理,供开发人员从源代码​​管理中使用,但这些是从源代码发布 tar 文件等构建的人不需要/使用。

Autoconf and automake are often used together but you can use autoconf without automake, if you want to write your own Makefile.in . Autoconf 和 automake 通常一起使用,但如果您想编写自己的Makefile.in ,则可以使用 autoconf 而不使用 automake。

For this error:对于这个错误:

config.status: error: cannot find input file: `somedir/Makefile.in'

In the directory where the configure.ac is located in the Makefile.am add a line with the subdirectory somedir在Makefile.am中configure.ac所在目录添加一行,子目录somedir

SUBDIRS = somedir

Inside somedir put a Makefile.am with all the description.somedir里面放一个包含所有描述的Makefile.am then run automaker --add-missing然后运行automaker --add-missing

A better description can be found in 7.1 Recursing subdirectories automake manual.更好的描述可以在 7.1 Recursing subdirectories automake manual 中找到。 https://www.gnu.org/software/automake/manual/automake.html https://www.gnu.org/software/automake/manual/automake.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM