如何从 makefile 运行 Perl oneliner?

发布于 2024-08-18 14:13:46 字数 436 浏览 6 评论 0原文

我知道下面的 perl one 衬垫非常简单,可以工作并进行全局替换,A 替换 a;但如何在 makefile 中运行它呢?

perl -pi -e "s/a/A/g" filename

我已经尝试过(我现在认为帖子的其余部分是垃圾,因为 shell 命令执行命令行扩展 - 不是我想要的!)上面的问题仍然存在!

APP = $(shell perl -pi -e "s/a/A/g" filename)

有或没有以下行

EXE = $(APP)

,我总是收到以下错误

make: APP: Command not found

,我认为该错误来自启动 APP 的行

谢谢

I know the perl one liner below is very simple, works and does a global substitution, A for a; but how do I run it in a makefile?

perl -pi -e "s/a/A/g" filename

I have tried (I now think the rest of the post is junk as the shell command does a command line expansion - NOT WHAT I WANT!) The question above still stands!

APP = $(shell perl -pi -e "s/a/A/g" filename)

with and without the following line

EXE = $(APP)

and I always get the following error

make: APP: Command not found

which I assume comes from the line that starts APP

Thanks

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

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

发布评论

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

评论(2

愿与i 2024-08-25 14:13:46

如果你想运行 perl 作为目标操作的一部分,你可以使用

$ cat Makefile
all:
        echo abc | perl -pe 's/a/A/g'
$ make
echo abc | perl -pe 's/a/A/g'
Abc

(请注意,echo 之前有一个 TAB 字符。)

Perl 的 -i 选项用于编辑文件-place,但这会让 make 感到困惑(除非你正在编写一个 虚假目标)。更典型的模式是从源头制定目标。例如:

$ cat Makefile
all: bAr

bAr: bar.in
        perl -pe 's/a/A/g' bar.in > bAr
$ cat bar.in
bar
$ make
perl -pe 's/a/A/g' bar.in > bAr
$ cat bAr
bAr

如果您让我们知道您想要做什么,我们将能够为您提供更好、更有帮助的答案。

If you want to run perl as part of a target's action, you might use

$ cat Makefile
all:
        echo abc | perl -pe 's/a/A/g'
$ make
echo abc | perl -pe 's/a/A/g'
Abc

(Note that there's a TAB character before echo.)

Perl's -i option is for editing files in-place, but that will confuse make (unless perhaps you're writing a phony target). A more typical pattern is to make targets from sources. For example:

$ cat Makefile
all: bAr

bAr: bar.in
        perl -pe 's/a/A/g' bar.in > bAr
$ cat bar.in
bar
$ make
perl -pe 's/a/A/g' bar.in > bAr
$ cat bAr
bAr

If you let us know what you're trying to do, we'll be able to give you better, more helpful answers.

望笑 2024-08-25 14:13:46

您应该显示尽可能小的 Makefile 来演示您的问题,并显示您如何调用它。假设你的 Makefile 看起来像这样,我收到错误消息。请注意,all: 目标中的 APP 前面有一个制表符。

APP = $(shell date)

all:
    APP

也许您打算这样做:

APP = $(shell date)

all:
    $(APP)

我没有使用您的 perl 命令,因为它不能按原样为我运行。
您真的想使用 Perl 的替换运算符吗? perl -pi -e "s/a/A/g"

这里是 GNU make 文档。

You should show the smallest possible Makefile which demonstrates your problem, and show how you are calling it. Assuming your Makefile looks something like this, I get the error message. Note that there is a tab character preceding the APP in the all: target.

APP = $(shell date)

all:
    APP

Perhaps you meant to do this instead:

APP = $(shell date)

all:
    $(APP)

I did not use your perl command because it does not run for me as-is.
Do you really mean to use Perl's substitution operator? perl -pi -e "s/a/A/g"

Here is a link to GNU make documentation.

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