Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you change makefile variables file extension?

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.

like image 398
wonton Avatar asked Aug 09 '12 17:08

wonton


People also ask

What is the file extension for makefile?

Well on a Linux machine it usually doesn't have an extension at all - it's just "makefile" or "Makefile". You can call it anything you want and use the -f option to tell "make" which to use. If your text editor can't save a file called Makefile , use a better text editor.

Does makefile need an extension?

NOTE: The term "Makefile" typically refers to a file named Makefile, which is used to build source code into an executable program. This type of file does not have a file extension.

Can we use variables in makefile?

A variable is a name defined in a makefile to represent a string of text, called the variable's value. These values are substituted by explicit request into targets, prerequisites, commands, and other parts of the makefile. (In some other versions of make , variables are called macros.)


2 Answers

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

like image 72
Roman Saveljev Avatar answered Sep 27 '22 20:09

Roman Saveljev


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

like image 35
wonton Avatar answered Sep 27 '22 20:09

wonton