Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get only file name without extension in GNU Makefile?

Tags:

c++

makefile

I have taken this answer from other post. Following prints file name with extension. This works only for cpp files, not for the header files when retrieved this pre processor value FILE_NAME inside C code.

-D FILE_NAME=\"$(<F)\"

How to get only source file name without extension?

like image 530
chan Avatar asked Mar 16 '23 07:03

chan


1 Answers

The predefined function basename removes the suffix (extension) from a filename, so if $(<F) is the filename you are interested in then $(basename $(<F)) is the name without the extension:

-D FILE_NAME=\"$(basename $(<F))\"
like image 104
Jonathan Wakely Avatar answered Apr 02 '23 05:04

Jonathan Wakely