在 makefile 中使用带有通配符的 nmake

发布于 2024-07-07 18:17:25 字数 1272 浏览 7 评论 0 原文

我正在尝试设置一个 nmake makefile 以自动将我们的 balsamiq 模型文件导出为 png 文件,但恐怕我无法弄清楚如何制定通用规则来执行此操作,而无需明确列出所有文件我要出口。

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

到目前为止我尝试过的 makefile 看起来像这样:

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

但这不起作用。

如果我只是运行 nmake (使用一些过时的 png 文件),nmake 就会这样做:

[C:\Temp] :nmake

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


[C:\Temp] :

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

[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 大师可以帮助我解决问题吗?

一个示例 makefile 通过复制 .txt 文件来简单地从 .dat 文件中生成 .dat 文件进行实验,如下所示:

.txt.dat:
    copy $< $@

这也没有执行任何操作,所以显然我不明白这种通用规则是如何工作的。 我是否需要在上面指定一个目标,以某种方式列出我想要的文件?

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.

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.

The makefile I have tried so far looks like this:

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

But this doesn't work.

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] :

Any nmake gurus out there that can set me straight?

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

.txt.dat:
    copy 
lt; $@

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一向肩并 2024-07-14 18:17:25

NMAKE 模式规则很像 GNU make 的老式后缀规则。 就您而言,您一开始就几乎是正确的,但您缺少 .SUFFIXES 声明。 例如:

.SUFFIXES: .bmml .png
.bmml.png:
    @echo Building $@ from 
lt;

我认为这只是您解决方案的一部分,因为您还提到希望避免显式列出所有要转换的文件。 不幸的是,我不知道在 NMAKE 中是否有一种非常干净的方法来做到这一点,因为它只扩展依赖项列表中的通配符,而您在依赖项列表中真正想要的并不是已经存在的文件列表(*.bmml文件),但将从这些文件(*.png 文件)创建的文件列表。 尽管如此,我认为你可以通过像这样的递归 NMAKE 调用来实现你的目标:

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

在这里,NMAKE 会将 all 的 prereq 列表中的 *.bmml 扩展到 .bmml 列表中。 bmml 文件放在目录中,然后它将启动一个新的 NMAKE 实例,指定要构建的目标为文件列表,其中所有 .bmml 实例替换为 .png 。 因此,将它们放在一起:

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

.bmml.png:
    @echo Building $@ from 
lt;

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

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

当然,如果您有很多这样的 .bmml 文件,则可能会运行命令- 行长度限制,所以要小心。 在这种情况下,我建议要么明确列出源文件,要么使用功能更强大的 make 工具,例如 GNU make(它以多种形式适用于 Windows)。

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 
lt;

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 
lt;

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

长安忆 2024-07-14 18:17:25

这对你有用吗? 将其放入 MAKEFILE.:

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

然后运行:

nmake /A

我没有 Balsamiq,所以我无法测试它,但在我的情况下,如果我有以下 MAKEFILE.:

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

并在文件夹中运行 nmake /A myFile.txt,它将创建 myFile.dat。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文