在Makefile中的子目录来源 [英] Sources from subdirectories in Makefile

查看:204
本文介绍了在Makefile中的子目录来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C使用的Makefile ++库建成。直到最近,所有的资源都在一个目录下,Makefile文件做了这样的事情。

I have a C++ library built using a Makefile. Until recently, all the sources were in a single directory, and the Makefile did something like this

SOURCES = $(通配符*的.cpp)

这工作得很好。

现在我已经添加了一些消息来源是在一个子目录中,说子目录。我知道我能做到这一点。

Now I've added some sources that are in a subdirectory, say subdir. I know I can do this

SOURCES = $(通配符*的.cpp)$(通配符子目录/ *。CPP)

但我在寻找一种方法来避免指定子目录手动,那就是让通配符调查子目录,或以某种方式产生子目录的列表并与多家通配符的功能扩展它。在这一点上,具有非递归溶液(即,扩大只有第一级)就可以了。

but I'm looking for a way to avoid specifying subdir manually, that is, make wildcard look into subdirectories, or generating a list of subdirectories somehow and expanding it with several wildcard functions. At this point, having a non-recursive solution (that is, expanding only the first level) would be fine.

我还没有发现任何东西 - 我最好的猜测是使用找到型ð来列出子目录,但感觉就像一个黑客攻击。是否有任何内置的方式做到这一点?

I haven't found anything - my best guess is using find -type d to list the subdirectories, but it feels like a hack. Is there any built-in way to do this?

推荐答案

这应该这样做:

SOURCES = $(wildcard *.cpp) $(wildcard */*.cpp)

如果你改变主意,想一个递归解决方案(即以任何深度),是可以做到的,但它涉及到一些更强大的制作功能。你知道,那些让你做事情,你真的不应该。

If you change you mind and want a recursive solution (i.e. to any depth), it can be done but it involves some of the more powerful Make functions. You know, the ones that allow you to do things you really shouldn't.

编辑:的结果
杰克·凯利指出, $(通配符** / *。CPP)工程,以任何深度,至少在某些平台上,使用gnumake的3.81。 (他怎么想通了这一点,我不知道。)


Jack Kelly points out that $(wildcard **/*.cpp) works to any depth, at least on some platforms, using GNUMake 3.81. (How he figured that out, I have no idea.)

这篇关于在Makefile中的子目录来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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