通过相同的Makefile生成Makefile的包含文件 [英] Generate include files for the Makefile by the same Makefile

查看:132
本文介绍了通过相同的Makefile生成Makefile的包含文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序中,我有一个比较复杂的构建过程.当前,在一个目录中,我将Makefile.am中的include与一个文件一起使用,该文件不存在,但必须自行构建.原因是此包含文件相当长.此外,在实际程序中,它不仅是一个文件,而且是几个文件,并且该文件的生成过程可能会不时发生变化.

In my program, I have a somewhat complicated build process. Currently, in one directory I use include in Makefile.am with a file, that does not exist but has to be build on its own. The reason is that this include file is quite long. Further in the real program it is not just only one file but several and the generation process for this file can change from time to time.

Makefile.am看起来像这样

noinst_LIBRARIES = libtest.a
nodist_libtest_a_SOURCES = file.c
CLEANFILES = file.c Make_file.mk 

$(builddir)/Make_test.mk: $(srcdir)/Perl/generate_mk_files.pl
      perl $(srcdir)/Perl/generate_mk_files.pl file

include $(builddir)/Make_file.mk

创建Make_file.mk后,它看起来像

$(builddir)/file.c: $(srcdir)/file.template $(srcdir)/Perl/generate_c.pl
      perl $(srcdir)/Perl/generate_c.pl $(srcdir)/file.template

Automake以及最终的构建过程同样有效. make的输出类似于(我已将其短一些):

Automake works and the final build process as well. The output to make is something like (I have shorted it somewhat):

Makefile:721: Make_file.mk: Datei oder Verzeichnis nicht gefunden (file not found)
perl ../../../../src/components/test/Perl/generate_mk_files.pl test
perl ../../../../src/components/test/Perl/generate_c.pl ../../../../src/components/test/file.template

因此,make首先抱怨找不到包含文件,然后创建它,然后还遵循包含文件的规则.

Therefore, make first complains that the include file is not found, then creates it and then also follows the rules of the included file.

尽管我很高兴它能奏效,但我想知道为什么.首先,我认为make加载了Makefile.在此步骤中,Make_file.mk不存在.因此,似乎Makefile已加载多次.

Although I am happy that it works I wonder why. First, I thought that make loads the Makefile. During this step, Make_file.mk does not exists. Therefore it seems the Makefile is loaded more than once.

此外,手册 include状态的自动制作的说明:

Further, the manual of Automake for include states:

请注意,这些片段是由automake而不是由automake读取和解释的 制造.

Note that these fragments are read and interpreted by automake, not by make.

这不是我所看到的,因为其中包含的片段在执行Automake的过程中不存在.

Which is not what I see, since the included fragment does not exist during the execution of Automake.

我的问题基本上是:

  • 它为什么起作用?
  • 这是执行此操作的正确方法还是应该使用其他方法,例如在Makefile中启动make的新实例.
  • Why does it work?
  • Is this the correct way to do this or should I use another approach, e.g. starting new instances of make within Makefile.

推荐答案

我不太了解Automake,但是从GNU make手册中可以找到:

I don't really know Automake, but, from the GNU make manual :

如果在以下任何目录中找不到包含的makefile,则{strong> a 警告消息已生成,但不是立即致命的 错误;继续对包含include的makefile进行处理. 完成读取makefile文件后,make将尝试重新制作任何文件 过期或不存在的.请参阅如何重新制作Makefile. 只有在尝试找到一种重新制作Makefile的方法并失败之后, 将诊断出丢失的Makefile为致命错误.

If an included makefile cannot be found in any of these directories {standard includes directories} , a warning message is generated, but it is not an immediately fatal error; processing of the makefile containing the include continues. Once it has finished reading makefiles, make will try to remake any that are out of date or don’t exist. See How Makefiles Are Remade. Only after it has tried to find a way to remake a makefile and failed, will make diagnose the missing makefile as a fatal error.

如果您想让make仅仅忽略一个不存在的makefile或 无法重制,没有错误消息,请使用-include指令 而不是包含,像这样:

If you want make to simply ignore a makefile which does not exist or cannot be remade, with no error message, use the -include directive instead of include, like this:

-include filenames…

这一切都类似于include,只是如果有任何文件名(或任何文件名)都没有错误(甚至没有警告) 任何文件名的先决条件)不存在或不能为 重新制作.

This acts like include in every way except that there is no error (not even a warning) if any of the filenames (or any prerequisites of any of the filenames) do not exist or cannot be remade.

因此,基本上,make在完成对主Makefile的解析之前,无法执行用于重新生成包含文件的方法.因此,它会发出警告,继续读取Makefile,找到重新制作包含文件的规则,重新制作它,然后重新启动自身(在如何重新制作Makefile"部分中对此进行了详细说明).

So basically, make cannot execute the recipe for remaking the include file before he has finished to parse the main Makefile. So it raises a warning, continue to read the Makefile, find the rule for remaking the included file, remake it, and then restart itself (that is explained in details in the How Makefiles Are Remade section).

这篇关于通过相同的Makefile生成Makefile的包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆