如何在Makefile中使用括号进行依赖

发布于 2024-12-14 20:03:36 字数 720 浏览 0 评论 0 原文

以下是我的 Makefile:

.PHONY: all

all: /Users/wu/qqaa/homepage\ 1\ 2\ 3/icons\ (a-b)
        @tar cjvf 1.tar.bz2 --exclude=*~ /Users/wu/qqaa/homepage\ 1\ 2\ 3/icons\ \(a-b\)

它不起作用。问题在于依赖项中的括号。在 之前添加 \ 也不起作用。错误是这样的:

make: *** No rule to make target `/Users/wu/qqaa/homepage 1 2 3/icons (a-b)', needed by `all'. Stop

目录 /Users/wu/qqaa/homepage 1 2 3/icons (ab) 确实存在。看来括号不能用于依赖关系。正确吗?或者我错过了什么?

听起来冒号也不能用于依赖。

我编写了一个 bash shell 脚本来备份我的系统。我使用 maketar 来备份。使用 make 仅更新较新的文件并 tar 目录。问题是许多文件的名称带有冒号或括号,它们在 Makefile 中具有特殊含义。从而导致出现上述问题。

我真的很感谢任何帮助。谢谢。

Following is my Makefile:

.PHONY: all

all: /Users/wu/qqaa/homepage\ 1\ 2\ 3/icons\ (a-b)
        @tar cjvf 1.tar.bz2 --exclude=*~ /Users/wu/qqaa/homepage\ 1\ 2\ 3/icons\ \(a-b\)

It didn't work. The problem is the parenthesis in dependency. Adding \ before ( and ) also didn't work. The error is this:

make: *** No rule to make target `/Users/wu/qqaa/homepage 1 2 3/icons (a-b)', needed by `all'. Stop

The directory /Users/wu/qqaa/homepage 1 2 3/icons (a-b) does exist. It seemed that parenthesis couldn't be used in dependency. Is it correct? Or do I miss something?

Sound that colon also couldn't be used in dependency.

I wrote a bash shell script to backup my system. I used make and tar to backup. Using make is to only update the newer files and tar the directory. The problem is that the names of many files have colon or parenthesis and they have special meaning in Makefile. It results in the above problem.

I really appreciate any help. Thank you.

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

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

发布评论

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

评论(2

花期渐远 2024-12-21 20:03:36

问题在于括号标记了存档成员并且似乎无法转义。常用的技巧是反斜杠转义和使用变量转义:

.PHONY : all
leftparen:=(
rightparen:=)
all: /Users/wu/qqaa/homepage\ 1\ 2\ 3/icons\ $(leftparen)a-b$(rightparen)
        @tar cjvf 1.tar.bz2 --exclude=*~ "$@"

并且由于在这种情况下两者都不起作用,因此您可能必须忍受此限制或针对 GNU make 提交错误。

The problem is that parentheses mark archive members and seem to be unescapeable. The usual tricks are backslash-escape and escaping by using a variable:

.PHONY : all
leftparen:=(
rightparen:=)
all: /Users/wu/qqaa/homepage\ 1\ 2\ 3/icons\ $(leftparen)a-b$(rightparen)
        @tar cjvf 1.tar.bz2 --exclude=*~ "$@"

And since both don't work in this case, you'll probably have to live with this limitation or file a bug against GNU make.

别挽留 2024-12-21 20:03:36

对我来说,我在 Windows 中使用的 Makefile 遇到了这个问题。编译器是 MinGW64-W32 的 32 位版本。

gcc --version 显示:gcc(i686-posix-sjlj-rev0,由 MinGW-W64 项目构建)5.1.0

make --version 显示:GNU Make 3.81

我正在编写一个 Makefile,需要包含已更改的目录(即,32 位编译器的包含目录与 32 位编译器的包含目录不同) 64 位编译器)。我需要包括类似的内容:
-IC:/Program Files (x86)/mingw-w64/gtk+-3.6.4_win32/include/gtk-3.0

例如。我遇到了同样的问题,当我尝试编译时,编译器会在第 0 行或其他地方出错 ( )。我的解决方案很简单。我只需使用双引号,如下所示:

-I"C:/ Program Files (x86)/mingw-w64/gtk+-3.6.4_win32/include/gtk-3.0"

使用双引号有效。它使我能够成功编译我的程序。

这里附注。通常,在 Linux 中,对于带有空格的目录,我们需要类似:

-I"C:/Program\ Files\ (x86)/mingw-w64/gtk+-3.6.4_win32/include/gtk-3.0"

以及\ 在 Makefile 中,如果我使用 \ 来表示空格,并使用双引号,则程序无法编译。 我相信 Makefile 认为 \ 实际上是目录名称,当我使用双引号时,

请尝试以下操作:

.PHONY: all

all: /Users/wu/qqaa/homepage\ 1\ 2\ 3/icons\ (a-b)
        @tar cjvf 1.tar.bz2 --exclude=*~ "/Users/wu/qqaa/homepage 1 2 3/icons (a-b)"

如果这不起作用,请尝试以下操作:

.PHONY: all

all: /Users/wu/qqaa/homepage\ 1\ 2\ 3/icons\ (a-b)
        @tar cjvf 1.tar.bz2 --exclude=*~ "/Users/wu/qqaa/homepage\ 1\ 2\ 3/icons\ (a-b)"

无论如何,祝你好运。

For me, I had this problem with a Makefile that I was using in Windows. The compiler is a 32-bit version of MinGW64-W32.

gcc --version shows: gcc (i686-posix-sjlj-rev0, Built by MinGW-W64 project) 5.1.0

make --version shows: GNU Make 3.81

I was writing a Makefile that needed to include directories that changed (ie, the include directories for the 32-bit compiler are different than the include directories for the 64-bit compiler). I needed to include something like:
-IC:/Program Files (x86)/mingw-w64/gtk+-3.6.4_win32/include/gtk-3.0

For example. I had the same problem, when I tried to compile, the compiler would error out about ( on line 0 or something. My solution was simple. I just had to use double quotes, like this:

-I"C:/Program Files (x86)/mingw-w64/gtk+-3.6.4_win32/include/gtk-3.0"

Using the double quotes worked. It allowed me to successfully compile my program.

A side note here. Normally, in Linux, for a directory with spaces, we need something like:

-I"C:/Program\ Files\ (x86)/mingw-w64/gtk+-3.6.4_win32/include/gtk-3.0"

with the \ before the space. In the Makefile, if I use \'s for spaces, with the double quote, the program does not compile. I believe the Makefile believes the \'s are actually part of the directories name, when I use double quotes.

For your code, try something like:

.PHONY: all

all: /Users/wu/qqaa/homepage\ 1\ 2\ 3/icons\ (a-b)
        @tar cjvf 1.tar.bz2 --exclude=*~ "/Users/wu/qqaa/homepage 1 2 3/icons (a-b)"

If that doesn't work, then try something like:

.PHONY: all

all: /Users/wu/qqaa/homepage\ 1\ 2\ 3/icons\ (a-b)
        @tar cjvf 1.tar.bz2 --exclude=*~ "/Users/wu/qqaa/homepage\ 1\ 2\ 3/icons\ (a-b)"

Anyway, good luck.

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