如何从 makefile 运行 Perl oneliner?
我知道下面的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你想运行 perl 作为目标操作的一部分,你可以使用
(请注意,
echo
之前有一个 TAB 字符。)Perl 的
-i
选项用于编辑文件-place,但这会让make
感到困惑(除非你正在编写一个 虚假目标)。更典型的模式是从源头制定目标。例如:如果您让我们知道您想要做什么,我们将能够为您提供更好、更有帮助的答案。
If you want to run perl as part of a target's action, you might use
(Note that there's a TAB character before
echo
.)Perl's
-i
option is for editing files in-place, but that will confusemake
(unless perhaps you're writing a phony target). A more typical pattern is to make targets from sources. For example:If you let us know what you're trying to do, we'll be able to give you better, more helpful answers.
您应该显示尽可能小的 Makefile 来演示您的问题,并显示您如何调用它。假设你的 Makefile 看起来像这样,我收到错误消息。请注意,
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 theall:
target.Perhaps you meant to do this instead:
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.