Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile pattern rule for no extension?

Tags:

I have a bunch of applications that are built with the same type of make rule:

apps = foo bar baz  all: $(apps)  foo: foo.o $(objects)     $(link)  bar: bar.o $(objects)     $(link)  baz: baz.o $(objects)     $(link) 

If they had an extension (for example .x) I could make a pattern rule like:

%.x: %.o $(objects)     $(link) 

and I wouldn't have to write out a new rule for each app.

But they don't have an extension, and I'm pretty sure that:

%: %.o $(objects)     $(link) 

won't work (because it specifies that to build any file you can use this rule).

Is there anyway to specify one rule that will cover all the $(apps) build rules?

like image 877
Andrew Tomazos Avatar asked Mar 30 '13 12:03

Andrew Tomazos


People also ask

What is pattern rule in makefile?

A pattern rule looks like an ordinary rule, except that its target contains the character ' % ' (exactly one of them). The target is considered a pattern for matching file names; the ' % ' can match any nonempty substring, while other characters match only themselves.

What is $@ in makefile?

$@ is the name of the target being generated, and $< the first prerequisite (usually a source file). You can find a list of all these special variables in the GNU Make manual.

What is percentage in makefile?

Special characters in a makefile In commands, a percent symbol ( % ) is a file specifier. To represent % literally in a command, specify a double percent sign ( %% ) in place of a single one. In other situations, NMAKE interprets a single % literally, but it always interprets a double %% as a single % .

What is a makefile target?

A simple makefile consists of "rules" with the following shape: target ... : dependencies ... command ... ... A target is usually the name of a file that is generated by a program; examples of targets are executable or object files.


1 Answers

This looks like a job for a static pattern rule:

$(apps) : % : %.o $(objects)     $(link) 
like image 178
Beta Avatar answered Oct 19 '22 19:10

Beta