Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the filename extension of a Makefile rule

Tags:

makefile

If I have the following rule

myfile.ext:
    ...
    # `extname $@` or something

How can I reference the extension (ext in this case) from the rule body?

like image 942
jviotti Avatar asked Sep 17 '25 08:09

jviotti


1 Answers

The $(suffix) function does what you want.

$(suffix names…)

Extracts the suffix of each file name in names. If the file name contains a period, the suffix is everything starting with the last period. Otherwise, the suffix is the empty string. This frequently means that the result will be empty when names is not, and if names contains multiple file names, the result may contain fewer file names.

For example,

$(suffix src/foo.c src-1.0/bar.c hacks)

produces the result ‘.c .c’.

like image 117
Etan Reisner Avatar answered Sep 19 '25 16:09

Etan Reisner