在makefile中使用nmake与通配符 [英] Using nmake with wildcards in the makefile

查看:312
本文介绍了在makefile中使用nmake与通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个nmake makefile来将我们的balsamiq模型文件自动导出到png文件,但是我恐怕不能做出这样做的一般规则的头和尾,没有明确列出我想要导出的所有文件。

I am attempting to set up an nmake makefile to export our balsamiq mockup files to png files automatically, but I'm afraid I can't make heads nor tails of how to make a generic rule for doing so, without explicitly listing all the files I want exported.

此页面详细介绍了导出文件的命令行语法,并此页面包含一个示例,其中包含.obj文件到.exe文件的通用规则。

This page details the command line syntax for exporting the files, and this page contains an example which looks like it contains a generic rule for .obj files to .exe files.

我已经尝试过的makefile看起来像这样:

The makefile I have tried so far looks like this:

.bmml.png:
    "C:\Program Files\Balsamiq Mockups\Balsamiq Mockups.exe" export $< $@

但这不行。

如果我只是运行nmake(有些过时的png文件),那么nmake只是这样做:

If I simply run nmake (with some outdated png files), nmake just does this:

[C:\Temp] :nmake

Microsoft (R) Program Maintenance Utility Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.


[C:\Temp] :

如果我要求它构建一个特定的文件,它是这样的:

If I ask it to build one specific file, it does this:

[C:\Temp] :nmake "TestFile.png"

Microsoft (R) Program Maintenance Utility Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

NMAKE : fatal error U1073: don't know how to make '"TestFile.png"'
Stop.

[C:\Temp] :

任何nmake gurus在那里这可以让我直线?

Any nmake gurus out there that can set me straight?

一个例子makefile只是通过复制它们来实现.txt文件的.dat文件,如下所示:

An example makefile which simply makes .dat files from .txt files by copying them, to experiment with, looks like this:

.txt.dat:
    copy $< $@

这样做也没有,所以很明显我不明白这样的一般规则如何工作。我需要指定一个以上的目标,列出我想要的文件吗?

this does nothing as well, so clearly I'm not understanding how such generic rules work. Do I need to specify a goal above that somehow lists the files I want?

编辑 :对于新的答案:

此makefile:

{}.txt{}.dat:
    copy $** $@

与此文件(test.dat)

with this file (test.dat)

1
2
3

此命令:

NMAKE test.txt

生成此错误消息:

[C:\] :nmake test.txt

Microsoft (R) Program Maintenance Utility Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

NMAKE : fatal error U1073: don't know how to make 'test.txt'
Stop.


推荐答案

NMAKE模式规则很像GNU make old-学校后缀规则。在你的情况下,你开始几乎是正确的,但你错过了.SUFFIXES声明。例如:

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 $<

我认为这只是您解决方案的一部分,因为您也提到要避免明确列出所有的要转换的文件。不幸的是,我不知道在NMAKE中有一个非常干净的方法,因为它仅在依赖关系列表中扩展通配符,并且您在依赖关系列表中真正需要的不是已存在的文件列表(* .bmml文件),但是将从这些文件(* .png文件)创建的文件列表。不过,我认为您可以通过递归的NMAKE调用来实现您的目标:

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)

这里,NMAKE将展开 *。bmml 在目录中的.bmml文件列表中的所有的prereq列表中,然后它将启动一个新的NMAKE实例,指定要构建为具有 .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 $<

如果我创建Test1.bmml和Test2.bmml文件,然后运行这个makefile,我得到以下输出:

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

当然,如果你有很多的这些.bmml文件,您可能会遇到命令行长度限制,因此请注意。在这种情况下,我建议您明确列出源文件,或使用更有效的制作工具,如GNU make(可用于各种形式的Windows)。

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).

这篇关于在makefile中使用nmake与通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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