ifeq 问题我尝试理解

发布于 2024-10-17 00:21:46 字数 494 浏览 3 评论 0原文

这是我的第一个问题,也是我第一次管理 GNU Make,所以我想解释一下我的问题。也许你可以帮助我找到隧道尽头的光明。

我想做的就是在我的路径中检查一个单词,并在检查路径后执行一些操作,

我已经在 make 上得到了该代码:

WORD=GNUMAKE; \
    FOUND=1; \
    echo "$$FOUND"; \
    PWD=$(PWD); \
    ifeq ($(findstring $$WORD,$$PWD),) \
        $(warning list contains "$$WORD") \
    endif

但是当我运行 $make 时,我收到此错误,对我来说很奇怪,找不到解决方案 请你帮助我好吗?

/bin/sh: syntax error at line 1: `ifeq' unexpected
make: *** [all] Error 2

谢谢

is my first question here and first time I manage GNU Make so I want to explain my problem.perhaps you could help me to find a light at the end of this tunnel.

That thing Im trying to do is to check a word into my path and do something after check path

I've got that code on make:

WORD=GNUMAKE; \
    FOUND=1; \
    echo "$FOUND"; \
    PWD=$(PWD); \
    ifeq ($(findstring $WORD,$PWD),) \
        $(warning list contains "$WORD") \
    endif

but when I run $make I get this error, for me so strange and can't find a solution
could you please help me?

/bin/sh: syntax error at line 1: `ifeq' unexpected
make: *** [all] Error 2

Thank you

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

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

发布评论

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

评论(3

新人笑 2024-10-24 00:21:46

Gnu make 将使用 \ 连接的行视为单行。 ifeq 等。等人。需要在自己的行上,就像 C 中的 #ifdef (如果这对您有帮助的话)。

您似乎对 make 的作用感到相当困惑。

Make 在三个不同的阶段执行 makefile:

  1. 读取 Makefile、在内存中构建图形、根据需要保存宏/扩展宏。
  2. 它会查看您要求它做什么,并决定如何遍历图表。
  3. 它会遍历图表,在将制造的字符串传递到 shell 之前扩展 shell 配方。

您可以让 make 在读取 makefile 时执行您的命令,

WORD = GNUMAKE
FOUND = 1
$(warning ${FOUND})
ifneq ($(findstring ${WORD},${CURDIR}),)
    $(warning list contains "${WORD}")
endif

或者您可以让 make 在将命令传递到 shell 时执行此操作(即,之前 > shell 被执行):

.PHONY: target
target:
    $(if $(findstring ${WORD},${CURDIR}),$(warning list contains "${WORD}"))echo Shell command here

或者确实让 shell 执行它。

Gnu make treats lines joined with \ as a single line. ifeq et. al. need to be on their own line, rather like #ifdef in C (if that's any help to you).

You seem rather confused over what make does.

Make executes a makefile in three distinct phases:

  1. It reads in the Makefile, building a graph in memory, saving macros/expanding macros as necessary.
  2. It looks at what you asked it to make, and decides how to walk the graph.
  3. It walks the graph, expanding the shell recipes before passing the manufactured string to the shell.

You can get make to do your bidding as it reads the makefile

WORD = GNUMAKE
FOUND = 1
$(warning ${FOUND})
ifneq ($(findstring ${WORD},${CURDIR}),)
    $(warning list contains "${WORD}")
endif

Or you can get make to do this just as it is making the command to pass to the shell (i.e., before the shell is executed):

.PHONY: target
target:
    $(if $(findstring ${WORD},${CURDIR}),$(warning list contains "${WORD}"))echo Shell command here

Or indeed get the shell to do it.

相思故 2024-10-24 00:21:46

您将 make 命令与 shell 命令混为一谈。 ifeq 显然属于 make,但不知何故进入了 shell。

这将在当前路径中找到 GNUMAKE 单词的出现,即它将是父目录之一。将其放入 Makefile 并调用 make。

INPUT := $(shell pwd | tr -s "/" " ")
WORD=GNUMAKE 
ifneq ($(filter $(WORD),$(INPUT)),) 
   $(warning list contains $(WORD))
endif

You are messing make commands with shell commands. ifeq is apparently belongs to make but got into shell somehow.

This will find occurance of GNUMAKE word in current path, i.e. it will be one of parent directories. Put this into Makefile and call make.

INPUT := $(shell pwd | tr -s "/" " ")
WORD=GNUMAKE 
ifneq ($(filter $(WORD),$(INPUT)),) 
   $(warning list contains $(WORD))
endif
趁年轻赶紧闹 2024-10-24 00:21:46
WORD = GNUMAKE
FOUND = 0
$(warning $FOUND)
ifneq ($(findstring $WORD,$(PWD)),)
    $(warning list contains $WORD)
endif

这正是我所设定的
希望有帮助

WORD = GNUMAKE
FOUND = 0
$(warning $FOUND)
ifneq ($(findstring $WORD,$(PWD)),)
    $(warning list contains $WORD)
endif

that is exactly what I have been set
hope it helps

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