nmake.exe: is there a way to exclude a file from a set of files specified in a macro?
I'm looking for something like the Exclude filter for msbuild, but I Want it in a makefile processed by nmake.
Is that possible?
Suppose I have a makefile that defines this macro:
SOURCES=xxx.c yyy.c zzz.c
and I invoke it with nmake OLD=xxx.c NEW=bbb.c
...can I produce, within the makefile, a macro with a value like:
yyy.c zzz.c bbb.c
...basically substituting bbb.c for xxx.c ?
The files can appear in any order.
This would be pretty easy if 开发者_JS百科the string substitution that is possible in nmake macros, allowed for evaluation of macros.
In other words, I can do
sources=xxx.c yyy.c zzz.c
objs=$(sources:.c=.o)
and the value of $(objs) is
xxx.o yyy.o zzz.o
But nmake does not allow a macro for the value of either argument to that substitution. I cannot do this:
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.
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.
It looks like this.
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
<<
To invoke that, you can do:
nmake INC=AdditionalFile.c EXC=Zambda.c target
...and it does the right thing: Compiles Fribble.c Twoolie.c and AdditionalFile.c, but not Zambda.c .
精彩评论