使用 Makefile 中的通用目标进行 make 的 Bash 补全

发布于 2024-07-13 17:53:57 字数 385 浏览 7 评论 0原文

我有一个 Makefile,其中大多数目标通常都是通过固定序列创建的。 bash 完成似乎仅建议完成正常目标,例如,

target_name:
        #$@

而不建议完成通用目标。 有没有办法让 bash 完成完成所有目标,即使它们没有像上面的示例那样明确? 更具体地说,假设我定义了一个目标名称列表,并执行如下操作:

list=target1 target2
$(list):
        #$@

是否有某种方法可以使这些目标可用于 bash 完成? 或者,更高级的是,假设我有两个列表,并且我希望目标由两个列表的元素的所有可能组合组成。 我还可以让这些目标可用于 bash 完成吗?

I have a Makefile where most of my targets are created generically through a canned sequence. It seems that bash completion only suggests completions for normal targets, e.g.

target_name:
        #$@

and not for generic targets. Is there any way to make bash completion complete all the targets, even though they are not made explicit as the example above? To be more spesific, lets say I define a list of target names, and do something like this:

list=target1 target2
$(list):
        #$@

Is there some way to make these targets available for bash completion? Or, even more advanced, say I have two lists and I want the targets to be made of all possible combinations of the elements of the two lists. Can I also have these targets available for bash completion?

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

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

发布评论

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

评论(2

羁客 2024-07-20 17:53:57
$ make -qp | grep '^[^.#].*: '
all: bin1 bin2 bin3
bin1: obj1.o obj2.o obj3.o
obj1.o: obj1.c obj1.h
...
$ make -qp | sed -n -e 's/^\([^.#[:space:]][^:[:space:]]*\): .*/\1/p'
all
bin1
obj1.o
...

-q 阻止 Make 实际运行任何内容,而 -p 要求它转储其数据库。

然后你需要做的就是编写并注册一个完成函数< /a> (示例)。

$ make -qp | grep '^[^.#].*: '
all: bin1 bin2 bin3
bin1: obj1.o obj2.o obj3.o
obj1.o: obj1.c obj1.h
...
$ make -qp | sed -n -e 's/^\([^.#[:space:]][^:[:space:]]*\): .*/\1/p'
all
bin1
obj1.o
...

The -q prevents Make from actually running anything, and the -p asks it to dump its database.

Then all you need to do is write and register a completion function (example).

一笑百媚生 2024-07-20 17:53:57

AFAIK,没有可行的解决方案。

此命令:

make -qsp 2>/dev/null | egrep '^[^#%\.=]*:[^=]' | awk -F ': ' '{ print $2}'

将扩展您的 makefile 目标。

您可以尝试将其添加到您的 /etc/bash_competion 中,但我认为它需要进一步调试以应对更复杂的情况。

There is no working solution, AFAIK.

This command:

make -qsp 2>/dev/null | egrep '^[^#%\.=]*:[^=]' | awk -F ': ' '{ print $2}'

will expand your makefile targets.

You may try to add it into your /etc/bash_competion, but I think it will need further debugging to cope with more complex situations.

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