makefile - 测试 NMake 中的文件是否存在

标签 makefile nmake

在 GNU Make 的 makefile 中,我使用这个惯用法来测试文件是否存在:

static:
ifeq ($(wildcard $(FileName)),)
    # do something when the file doesn't exist
else
    # do something different when it does
endif

但它在 NMake 中不起作用( fatal error U1000:语法错误:宏调用中缺少“)”)。我该如何更换它?如果替换可以在两个构建系统中工作,那就完美了。

最佳答案

Nmake 可以运行预处理器指令:

http://msdn.microsoft.com/en-us/library/7y32zxwh.aspx

条件可能会有所不同,但 Exists() 是其中之一:

http://msdn.microsoft.com/en-us/library/8t2e8d78.aspx

!IF EXISTS(foo.txt)

最后使用命令行 http://msdn.microsoft.com/en-us/library/wkxa7sac.aspx

!IF [cmd /C IF NOT EXIST "foo.txt" exit 1]

无论哪种方式,这都应该可以工作,使用上面的 !IF 是完整的示例:

!IF !EXISTS(foo.txt)
!ERROR Unable to locate foo.
!ELSE
!MESSAGE I Found foo!
!ENDIF

关于makefile - 测试 NMake 中的文件是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4470275/

相关文章:

batch-file - Windows 批处理 (cmd.exe) 命令行参数和字符串操作

c++ - 编译Qt报错: nmake fatal error U1077

c - 如何使用makefile以及 "no such jobs "是什么意思

c - 这个 Makefile 有什么问题? (找不到头文件)

postgresql - 如何在 postgres 扩展的 Makefile 中为 installcheck 设置用户?

c - esp-gdbstub 编译错误

c++ - 链接器错误构建 GDAL

c - 一个做一个 nmake 的 visual studio 解决方案

windows - 在 jom/nmake 读取的 makefile 中设置环境变量

c - 学习makefile