如何检查Makefile中是否存在文件 [英] How to check if a file exists in a makefile

查看:1385
本文介绍了如何检查Makefile中是否存在文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个makefile模板来编译单个DLL(用于插件系统). 用户的makefile如下所示:

I have a makefile template to compile a single DLL (for a plugin system). The makefile of the user looks like this:

EXTRA_SRCS=file1 file2
include makefile.in

makefile.in中,我有:

plugin.dll: plugin.os $(patsubst %,%.os,$(EXTRA_SRCS))

plugin.os是要编译的主要C ++文件.顺便说一句,结尾为.os的文件是为共享库编译的目标文件(即,将-fpic选项与gcc一起使用)

Where plugin.os is the main C++ file to be compiled. Btw, the files ending is .os are the object files compiled for shared library (i.e. using the -fpic option with gcc)

现在,问题在于额外的源可能(但不一定)是头文件.理想情况下,我想将它们添加为目标plugin.osfile.cpp的依赖项,但前提是它们存在.

Now, the problem is that the extra sources will probably (but not necessarily) be header files. Ideally I would like to add them as dependencies for the target plugin.os and the file.cpp, but only if they exist.

该方法对Windows和Linux均适用,或者至少适用于每种方法.但是,我只使用make的GNU版本.

The method should work for both windows and linux, or at least be adaptable to each. However, I only use the GNU version of make.

推荐答案

使用通配符"功能:

$(wildcard *.h)

为了匹配特定列表,请

$(wildcard $(HEADER_FILES))

不需要使用$(filter ...),通配符功能会自动过滤不存在​​的文件.

There is no need to use $(filter ...), the wildcard function automatically filters files which don't exist.

这篇关于如何检查Makefile中是否存在文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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