6

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

1
  • So what is the line that starts APP? It sounds like you're doing something wrong there; the declaration of APP itself looks fine.
    – Porculus
    Commented Jan 24, 2010 at 14:05

2 Answers 2

4

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.

0
1

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.

1
  • Yes, I want to run a perl substitution on a file from a makefile. The real substitution is more complex but that's not the point.
    – Frank
    Commented Jan 24, 2010 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.