Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU Make with patsubst: need two substitutions

Tags:

makefile

I need to reference the stem twice in the replacement for a variable substitution:

O23=$(OROOTS:%=$(ODIR)/overx-%2wk-%3wk.mlb)

I need to perform two replacements with the same stem, but the substitution uses patsubst which only does the first. How can we accomplish both?

like image 367
Alexy Avatar asked Mar 07 '11 19:03

Alexy


People also ask

What does Patsubst do in Makefile?

Finds whitespace-separated words in TEXT that match PATTERN and replaces them with REPLACEMENT. Here PATTERN may contain a % which acts as a wildcard, matching any number of any characters within a word.

How do I replace in Makefile?

A substitution reference substitutes the value of a variable with alterations that you specify. It has the form ' $( var : a = b ) ' (or ' ${ var : a = b } ') and its meaning is to take the value of the variable var , replace every a at the end of a word with b in that value, and substitute the resulting string.

What is := in Makefile?

= defines a recursively-expanded variable. := defines a simply-expanded variable.

What is Makefile_list?

MAKEFILE_LIST. Contains the name of each makefile that is parsed by make , in the order in which it was parsed. The name is appended just before make begins to parse the makefile. Thus, if the first thing a makefile does is examine the last word in this variable, it will be the name of the current makefile.


1 Answers

In fact, Jack got it almost right -- foreach to the rescue! We know the full stem anyway and stick it into a var, and foreach expands all occurrences of the var:

O23 := $(foreach root,$(OROOTS),$(ODIR)/overx-$(root)2wk-$(root)3wk.mlb)

I'll check Beta's anyway for the new perspective.

like image 109
Alexy Avatar answered Sep 30 '22 00:09

Alexy