开发者

How do I run a Perl one liner from a makefile?

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 t开发者_如何学Pythonhe line that starts APP

Thanks


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜