0

I'm trying to list all relevant source files in a make project so that the relevant part of a code coverage report generated during unit testing can be filtered out.

My solution so far works well but has the flaw that it doesn't list files in subdirectories. It only lists files in the root of the specified directories.

USER_DIR is set to the location of the source files. It can contain several directories. Then the following lines will create the lists used to filter out relevant files from the code coverage report:

SRCEXTS = .c .cc .cpp
HDREXTS = .h .H .hh .hpp .HPP .h++ .hxx .hp

SW_SOURCE := $(foreach d,$(USER_DIR),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
SW_HEADERS := $(foreach d,$(USER_DIR),$(wildcard $(addprefix $(d)/*,$(HDREXTS))))

How could i alter my solution so that it also finds files in all subdirectories of USER_DIR? Alternatively, of course, if there is a better approach to this rather than the foreach i have that would also be of interest, but i think i would like to keep the format of the lists.

Martin G
  • 17,357
  • 9
  • 82
  • 98
  • Take a look at [this](http://stackoverflow.com/questions/4036191/sources-from-subdirectories-in-makefile). – Beta Nov 24 '14 at 06:52
  • possible duplicate of [Recursive wildcards in GNU make?](http://stackoverflow.com/questions/2483182/recursive-wildcards-in-gnu-make) – reinierpost Nov 24 '14 at 08:36

1 Answers1

0

This is what i ended up doing:

SW_SOURCE := $(foreach ext, $(SRCEXTS), $(foreach d, $(USER_DIR), $(shell find $(d) -name '*$(ext)')))
SW_HEADERS := $(foreach ext, $(HDREXTS), $(foreach d, $(USER_DIR), $(shell find $(d) -name '*$(ext)')))

Loop over extensions and directories and retrieve the files with find. Perhaps not the most efficient way but there it is.

Martin G
  • 17,357
  • 9
  • 82
  • 98