nmake.exe:有没有办法从宏中指定的一组文件中排除文件? [英] nmake.exe: is there a way to exclude a file from a set of files specified in a macro?

查看:42
本文介绍了nmake.exe:有没有办法从宏中指定的一组文件中排除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找类似排除 过滤器用于 msbuild,但我希望它在由 nmake 处理的 makefile 中.

I'm looking for something like the Exclude filter for msbuild, but I Want it in a makefile processed by nmake.

这可能吗?

假设我有一个定义这个宏的 makefile:

Suppose I have a makefile that defines this macro:

SOURCES=xxx.c  yyy.c  zzz.c

然后我用 nmake OLD=xxx.c NEW=bbb.c

...我可以在 makefile 中生成一个宏,其值类似于:

...can I produce, within the makefile, a macro with a value like:

yyy.c zzz.c  bbb.c 

...基本上用 bbb.c 代替 xxx.c ?

...basically substituting bbb.c for xxx.c ?

文件可以按任何顺序出现.

The files can appear in any order.

如果 nmake 宏中可能的字符串替换允许对宏进行评估,这将非常容易.

This would be pretty easy if the string substitution that is possible in nmake macros, allowed for evaluation of macros.

换句话说,我可以做到

sources=xxx.c yyy.c zzz.c
objs=$(sources:.c=.o)

而 $(objs) 的值是

and the value of $(objs) is

xxx.o yyy.o zzz.o

但是nmake 不允许对该替换的任一参数的值使用宏.我不能这样做:

new=.o
sources=xxx.c yyy.c zzz.c
objs=$(sources:.c=$(new))

推荐答案

我没有找到完全按照我想要做的方法,但我找到了解决方法.

I didn't find a way to do exactly what I wanted, but i found a workaround.

它涉及一种叫做 "inline files" 的东西,它们是文件nmake 动态创建然后在命令块中使用.就我而言,我使用内联文件"技巧来创建一个 .cmd 文件并运行它..cmd 文件执行包含/排除逻辑,然后在经过处理的源文件列表上运行编译器.

It involves something called "inline files" which are files that nmake creates dynamically and then uses in the command block. In my case I used the "inline file" trick to create a .cmd file and run it. The .cmd file did the include/exclude logic, and then ran the compiler on the massaged list of source files.

看起来像这样.

  CSOURCE=Fribble.c Zambda.c Twoolie.c
         ....
  target :
          <<tmp-build-file.cmd  $(CSOURCE)
      SETLOCAL ENABLEDELAYEDEXPANSION
      for %%I in (%*) do if NOT %%I == $(EXC) (
         set filesToBuild=!filesToBuild! %%I
      )
      $(CC) $(INC) !filesToBuild!
      ENDLOCAL
  <<

要调用它,您可以:

nmake INC=AdditionalFile.c  EXC=Zambda.c  target

...它做了正确的事情:编译 Fribble.c Twoolie.c 和 AdditionalFile.c,但不编译 Zambda.c.

...and it does the right thing: Compiles Fribble.c Twoolie.c and AdditionalFile.c, but not Zambda.c .

这篇关于nmake.exe:有没有办法从宏中指定的一组文件中排除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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