如何在(GNU)Makefile 中创建带引号的逗号分隔列表。

huangapple go评论54阅读模式
英文:

How to make a comma-separated list with quotes in (GNU) Makefile

问题

Here's the translated Makefile section you provided:

我有一个简单的Makefile:

MARKDOWNS = $(shell find . -type f -name "*.md" ! -name "index.md" ! -name "README.md")
all: list

list:
    echo $(MARKDOWNS)

我的目录中有这些`*.md`文件:

$ ls *.md

foo.md bla.md ra.md

因此,Makefile 给了我:

./foo.md ./bla.md ./ra.md

但期望的输出是:

"./foo.md", "./bla.md", "./ra.md"

如何将 `$(MARKDOWNS)` 转换为实现这一目标?我使用 GNU Make 4.4.1。

Please note that the translated content maintains the structure of the original text. If you need further assistance with the Makefile or have any questions, feel free to ask.

英文:

I have a simply Makefile:

MARKDOWNS = $(shell find . -type f -name "*.md" ! -name "index.md" ! -name "README.md")
all: list

list:
    echo $(MARKDOWNS)

My directory has this *.md files:

$ ls *.md

foo.md bla.md ra.md

So, the Makefile gives me:

./foo.md ./bla.md ./ra.md

But the desired output were

"./foo.md", "./bla.md", "./ra.md"

How can I transform $(MARKDOWNS) to achive that? I use GNU Make 4.4.1.

答案1

得分: 1

Certainly, here is the translated code portion:

也许不是最简单的解决方案,但有效:

    MARKDOWNS = $(shell find . -type f -name "*.md" ! -name "index.md" ! -name "README.md" | sed 's/^/"/;s/$$/",/' | tr '\n' ' ' | sed 's/..$$//')
    all: list

    list:
        echo '$(MARKDOWNS)'
英文:

Maybe not the simplest solution but works:

MARKDOWNS = $(shell find . -type f -name "*.md" ! -name "index.md" ! -name "README.md" | sed 's/^/"/;s/$$/",/' | tr '\n' ' ' | sed 's/..$$//')
all: list

list:
    echo '$(MARKDOWNS)'

huangapple
  • 本文由 发表于 2023年5月7日 04:32:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76191008.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定