views:

135

answers:

2

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  A: 

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.

toolic
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
+1  A: 

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.

Greg Bacon
Thanks, despite having programmed for years anything other than basic makefiles are just black magic. You have clearly answered my badly put question.
Frank