c++makefile

How to get only file name without extension in GNU 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?


Solution

  • In GNU Make, 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))\"