Reputation: 5959
I have two files as below (from tree command).
.
|-- Makefile
|-- dir1
| `-- file1.c
`-- dir2
`-- file2.c
I wanted to compiles files in dir1 and dir2 directory so I wrote a Makefile as below.
VPATH = dir1:dir2
CFILES := ${wildcard *.v}
$(info CFILES = ${CFILES})
output :
CFILES =
So the wildcar function doesn't automatically search paths set by the VPATH variable.
If I specifically write the path in the wildcard function, it works.
CFILES := ${wildcard dir1/*.c dir2/*.c} <== this makes it work
$(info CFILES = ${CFILES})
output :
CFILES = dir1/file1.c dir2/file2.c
I want to add only the existing paths to the Makefile but is there any way that I can use wildcard function for paths set by VPATH? (Suppose I need to remove some files from compile list so I need the files list. Just curious..)
Upvotes: 1
Views: 1742
Reputation: 4692
You can use Make's text transformation functions to turn a list of directories into your desired wildcard command. Take a look at the GNU Make manual, they even use extracting the directories of VPATH in their examples. Consider something like:
$(wildcard $(addsuffix /*.c,$(subst :, ,$(VPATH))
Since you get the full path to the file via wildcard, it seems like using VPATH shouldn't be necessary. IMHO, VPATH is a bad idea and well designed build system don't use it.
Also consider what you want to happen if files with the same name appear in different directories!
Upvotes: 1