简体   繁体   English

做非递归make的正确方法?

[英]Right way to do non-recursive make?

There seem to be only a handful of resources on creating a non-recursive make system, and in none of the ones I've found can I figure out how to handle my use case.似乎只有少数资源可以用于创建非递归 make 系统,而且在我找到的所有资源中,我都无法弄清楚如何处理我的用例。 My hierarchy looks like this:我的层次结构如下所示:

project/
project/libA/...
project/libB/...
...
project/appA/...
project/appB/...

So maybe project/appA/makefile depends on libA and libB and project/appB/makefile depends on libA , libC , and libF or something.因此,也许project/appA/makefile取决于libAlibBproject/appB/makefile取决于libAlibClibF或其他东西。 I want to be able to make in every directory and have that work.我希望能够make每个目录中,并有工作。 I have a recursive solution for this already.我已经有了一个递归解决方案。

All the resources always define a root project/makefile that include s all the directories above it.所有资源总是定义一个根project/makefile ,其中include它上面的所有目录。 But I need that backwards.但我需要倒退。 Are there any examples in the wild for this?有没有这方面的例子? I think ideally I want a given library makefile to look like:我认为理想情况下我希望给定的库 makefile 看起来像:

include ../../rules.mk

SRC := $(wildcard src/*.cpp)
INCDIR := ./include

$(add_build_target)

... where the base rules.mk would define add_build_target to append the correct rules for the given SRC and INCDIR to build . ...其中基本 rules.mk 将定义add_build_target为给定的SRCINCDIR附加正确的规则来build Is this the correct approach?这是正确的方法吗? And how do I actually write add_build_target to add the correct targets (.o's for all the .cxx's) - everything I've tried gives me "no rule to make target whatever.o" issues, despite me thinking that I've defined them....以及我如何实际编写add_build_target来添加正确的目标(.o 是所有 .cxx 的)-我尝试过的所有内容都给了我“没有任何规则可以制定目标。o”问题,尽管我认为我已经定义了它们....

I have implemented and extended ideas from the paper我已经实现并扩展了论文中的想法

http://evbergen.home.xs4all.nl/nonrecursive-make.html http://evbergen.home.xs4all.nl/nonrecursive-make.html

on multiple occasions in corporate environments, and they work very well, in small or large scale environments.在公司环境中多次使用,并且它们在小型或大型环境中都能很好地工作。 Basically, there is implemented a "directory stack" there and recursive inclusion.基本上,在那里实现了一个“目录堆栈”和递归包含。 Like I said, works well for me.就像我说的,对我来说效果很好。 Read this paper, I recommend it.阅读这篇论文,我推荐它。

Have a look at my non-recursive build system implementation called prorab : https://github.com/cppfw/prorab看看我的名为prorab 的非递归构建系统实现: https : //github.com/cppfw/prorab

It allows to achieve exactly what you want.它可以准确地实现您想要的。 So, you will have independent makefile in each directory appA, appB, libA, libB,... and if you cd to that directory you'll be able to build the project by just typing make .因此,您将在每个目录appA, appB, libA, libB,...拥有独立的makefile ,如果您cd到该目录,您只需键入make即可构建项目。 In that makefile you'll be able to include a makefile from another directory and add a dependency for your app binary on library binary.在该生成文件中,您将能够包含来自另一个目录的生成文件,并为您的应用程序二进制文件添加对库二进制文件的依赖项。 So, that way if you do some changes to the library code and build the app, it will detect that and rebuild the library.因此,这样一来,如果您对库代码进行一些更改并构建应用程序,它将检测到并重建库。 Then it is also possible to have a top-level makefile which includes all makefiles from those sub-directories, for building everything.然后也可以有一个顶级makefile ,其中包含来自这些子目录的所有生成文件,用于构建所有内容。 Let me know if you need help with using prorab .如果您在使用prorab 方面需要帮助,请告诉我。

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

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