Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 978
Frank Avatar asked Jan 24 '10 13:01

Frank


1 Answers

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.

like image 138
Greg Bacon Avatar answered Oct 15 '22 12:10

Greg Bacon