Using nmake with wildcards in the makefile

独自空忆成欢 提交于 2019-12-03 06:31:59

NMAKE pattern rules are a lot like GNU make old-school suffix rules. In your case, you had it almost right to begin with, but you were missing the .SUFFIXES declaration. For example:

.SUFFIXES: .bmml .png
.bmml.png:
    @echo Building $@ from $<

I think this is only part of your solution though, because you also mentioned wanting to avoid explicitly listing all of the files to be converted. Unfortunately, I don't know of a very clean way to do that in NMAKE, since it only expands wildcards in dependency lists, and what you really want in your dependency list is not the list of files that already exist (the *.bmml files), but the list of files that will be created from those files (the *.png files). Nevertheless, I think you can achieve your goal with a recursive NMAKE invocation like this:

all: *.bmml
    $(MAKE) $(**:.bmml=.png)

Here, NMAKE will expand *.bmml in the prereq list for all into the list of .bmml files in the directory, and then it will start a new NMAKE instance, specifying the goals to build as that list of files with all instances of .bmml replaced by .png. So, putting it all together:

.SUFFIXES: .bmml .png
all: *.bmml
    @echo Converting $(**) to .png...
    @$(MAKE) $(**:.bmml=.png)

.bmml.png:
    @echo Building $@ from $<

If I create files Test1.bmml and Test2.bmml and then run this makefile, I get the following output:

Converting Test1.bmml Test2.bmml to .png...
Building Test1.png from Test1.bmml
Building Test2.png from Test2.bmml

Of course, if you have very many of these .bmml files, you may run afoul of command-line length limitations, so watch out for that. In that case, I recommend either explicitly listing the source files, or using a more capable make tool, like GNU make (which is available for Windows in a variety of forms).

Will this work for you? Put this in MAKEFILE.:

export : *.bmml
    "C:\Program Files\Balsamiq Mockups\Balsamiq Mockups.exe" export $** $(**B).png

Then run:

nmake /A

I don't have Balsamiq so I can't test this but in my case if I have the following MAKEFILE.:

export : *.txt
    copy $** $(**B).dat

and run nmake /A in a folder with myFile.txt, it will create myFile.dat.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!