是否可以实现使用Addsuffix&#x27创建的自动完成目标。或ADDPREFIX?

发布于 2025-01-21 11:40:29 字数 1022 浏览 3 评论 0原文

当然使用GNU。
我有以下设置:

Makefile

subdir1
--- Makefile
--- source1.c
--- binary1

subdir2
--- Makefile
--- source2.c
--- binary2

两个子段中的两个makefiles都有一个运行目标,该目标可以执行自身生成的二进制目标。 root makefile包含all target,该目标运行make -c subir1&& make -c subdir2

SUBDIRS = subdir1 subdir2

all:
    @for DIR in $(SUBDIRS); do \
        $(MAKE) -C $$DIR; \
    done

clean:
    @for DIR in $(SUBDIRS); do \
        $(MAKE) -C $$DIR clean; \
    done

$(SUBDIRS):
    $(MAKE) -C $@

底部钻头让我执行使单个子dir全部。 我想要制作运行的类似目标,由$(subdirs)生成。 我尝试了

run-$(SUBDIRS):
   make -C $(subst run-,,$@) run

,但是目标将扩展到run-subdir1 subdir2,并且不会在$(subdirs)中的第二个项目中添加前缀,

如果我添加了新的var run_targets = $(addprefix run-,$(subdirs),它有效,但make not bects不识别utocomplettion的目标。是否有任何选项可以让您知道必须扩展run_targets或任何其他方法要

为我编辑

问题的列表是我的shell,ZSH,而不是做正确的。

Using GNU Make of course.
I have the following setup:

Makefile

subdir1
--- Makefile
--- source1.c
--- binary1

subdir2
--- Makefile
--- source2.c
--- binary2

Both makefiles in the subdirs have a run target, which executes the binary generated by itself.
The root makefile contains the all target, which runs make -C subir1 && make -C subdir2:

SUBDIRS = subdir1 subdir2

all:
    @for DIR in $(SUBDIRS); do \
        $(MAKE) -C $DIR; \
    done

clean:
    @for DIR in $(SUBDIRS); do \
        $(MAKE) -C $DIR clean; \
    done

$(SUBDIRS):
    $(MAKE) -C $@

The bottom bit lets me execute make all for a single subdir.
I want a similar target for make run, generated by $(SUBDIRS).
I tried

run-$(SUBDIRS):
   make -C $(subst run-,,$@) run

but the target expands to run-subdir1 subdir2, and doesn't add the prefix to the second item in $(SUBDIRS)

If i add a new var RUN_TARGETS = $(addprefix run-, $(SUBDIRS), it works, but make doesn't recognize the targets for utocompletion. Is there any option to let make know that is has to expand RUN_TARGETS or any other method to prefix a list of item?

EDIT

The issue for me is my shell, zsh, and not make itself. Bash completion gets it right.

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

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

发布评论

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

评论(2

心凉 2025-01-28 11:40:29

您可以使用“ nofollow noreferrer”>“模式规则

run-%:
        $(MAKE) -C $* run

”希望更明确,a

$(addprefix run-,$(SUBDIRS)): run-%:
        $(MAKE) -C $* run

You can use a pattern rule:

run-%:
        $(MAKE) -C $* run

or if you prefer to be more explicit, a static pattern rule:

$(addprefix run-,$(SUBDIRS)): run-%:
        $(MAKE) -C $* run
厌倦 2025-01-28 11:40:29

补充@madscientist的解决方案:

使用简化代码(如果您熟悉此概念)。

$(SUBDIRS:%=run-%): run-%:
    $(MAKE) -C $* run

To complement the solution by @MadScientist:

Use Substitution References to simplify the code (if you're familiar with this concept).

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