Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
328 views
in Technique[技术] by (71.8m points)

Using Perl to expand a string into a list of numbers in Makefile

I am trying to expand a variable in the Makefile:

 LIST = 1,3-6,9

so that "3-6" would expand into a list of numbers between 3 and 6.

I tried the following command in the terminal:

echo 1,3-6,9 | perl -pe 's/(d+)-(d+)/join(",", $1..$2)/ge'

It does produce the exact output. I then tried the following approach in the Makefile:

LIST_NEW = $(shell printf $(shell echo ${LIST} | perl -pe 's/(d+)-(d+)/join(",", $1..$2)/ge'))

which then has the error message as:

syntax error at -e line 1, near ", .."

How can I solve this issue?

question from:https://stackoverflow.com/questions/65910166/using-perl-to-expand-a-string-into-a-list-of-numbers-in-makefile

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have to escape any $ you don't want to be expanded by make, as $$.

Also, why are you running $(shell ...) twice?

This will work:

LIST_NEW = $(shell echo ${LIST} | perl -pe 's/(d+)-(d+)/join(",", $$1..$$2)/ge')

You might consider using := instead, here, if the value of LIST is constant for a given invocation of make.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...