linux # vpath
The value of the make variable VPATH specifies a list of directories that make should search.
Most often, the directories are expected to contain prerequisite files that are not in the current directory; however, make uses VPATH as a search list for both prerequisites and targets of rules.
VPATH用于指定一个目录列表,以便于make的时候在其中搜索。
这些目录中一般包含一些make必须的文件。
The VPATH is a list of directories to be searched for missing source files (actually for missing prerequisites: they don't have to be source files, but VPATH and vpath are best only used for source files).
The vpath directive has both a search path and a pattern.
Only missing prerequisites matching the pattern are searched using the associated path.
So vpath makes it possible, for example, to specify just a path to search for header (.h) files:
vpath %.h /usr/include
The % is the wildcard and matches anything, so that vpath directive solves the problem of the missing string.h in the example Makefile.
three forms
The vpath syntax is a little more complicated than VPATH and has three forms:
1. vpath pattern path
This sets the search path (colon or blank separated) for the pattern.
2. vpath pattern
This clears the path for the specified pattern.
3. vpath
Clears all vpath settings
examples
vpath %.h /usr/include
vpath %.c ../src
INCLUDE_DIRECTORIES = ../include
vpath %.h $(INCLUDE_DIRECTORIES)
ffmpeg的主Makefile中也用到了vpath:
MAIN_MAKEFILE=1
include ffbuild/config.mak
vpath %.c $(SRC_PATH)
vpath %.cpp $(SRC_PATH)
vpath %.h $(SRC_PATH)
vpath %.inc $(SRC_PATH)
vpath %.m $(SRC_PATH)
vpath %.S $(SRC_PATH)
vpath %.asm $(SRC_PATH)
vpath %.rc $(SRC_PATH)
vpath %.v $(SRC_PATH)
vpath %.texi $(SRC_PATH)
vpath %.cu $(SRC_PATH)
vpath %.ptx $(SRC_PATH)
vpath %/fate_config.sh.template $(SRC_PATH)
References:
https://www.cmcrossroads.com/article/basics-vpath-and-vpath
https://www.gnu.org/software/make/manual/html_node/General-Search.html