1

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..)

Chan Kim
  • 5,177
  • 12
  • 57
  • 112
  • it looks like you can't. Details are here http://stackoverflow.com/questions/2483182/recursive-wildcards-in-gnu-make – vasily-vm Jan 10 '17 at 08:22

1 Answers1

1

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!

TrentP
  • 4,240
  • 24
  • 35