Makefile Pattern Rules & Dependency Generation/dir and notdir with automatic vars

Extract target directory or file name.

Section: Automatic variables

dir and notdir with automatic vars

makefile
makefile
copy:
	@echo dir=$(dir $@) file=$(notdir $@)
Explanation

Combine automatic vars with text functions.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Automatic variables
$@ target name
Expand to the current target file.
OpenIn sheetmakefilesame section
$< first prerequisite
Expand to the first prerequisite.
OpenIn sheetmakefilesame section
$^ all prerequisites
Expand to all prerequisites without duplicates.
OpenIn sheetmakefilesame section
$? newer prerequisites
Expand to prerequisites newer than the target.
OpenIn sheetmakefilesame section
$* stem in pattern rules
Use the matched stem from the target pattern.
OpenIn sheetmakefilesame section
sort for deduplication
Sort and deduplicate a list of words.
OpenIn sheetmakefile1 tag match