11

For example, I have a variable that holds a list of dependencies

BOARDS:=lance.mcm light.mcm sac.mcm

I need another variable named NET such that

NET:=lance.net light.net sac.net

It should be set such that when I change the BOARDS variable, NET should change as well. For example, if I add a new zor.mcm into the BOARDS variable, it should automatically add zor.net into the NET variable.

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
wonton
  • 7,568
  • 9
  • 56
  • 93

2 Answers2

27

The best solution I have found is to use this syntax:

NET:=$(BOARDS:.mcm=.net)

This will look at BOARDS and change the .mcm into .net

wonton
  • 7,568
  • 9
  • 56
  • 93
  • 1
    A little more explanation at [How to change the extension of each file in a list with multiple extensions in GNU make?](http://stackoverflow.com/a/12071918/1730674) – askewchan Sep 26 '15 at 21:57
13

As an alternative:

BOARDS:=lance.mcm light.mcm sac.mcm
NET:= $(addsuffix .net, $(basename $(BOARDS)))

This will preserve contents inside the file pathnames should they match pattern

Roman Saveljev
  • 2,544
  • 1
  • 21
  • 20