0

I need to recursively get list of all subdirectories of a given top level directory. On an UNIX system, I can do it like this:

SUBDIRS := $(shell find $(TOP_DIR) -type d)

However, I need a solution which would be platform independent or at least a solution which works on Windows.

It should be possible to do using recursive wildcards (see this question) but I need to adapt this solution to work for directories instead of files.

Garnagar
  • 71
  • 6

2 Answers2

1

If you do not have spaces in your directory names:

define dfind
$(foreach d,$1,$(wildcard $d**/) $(call dfind,$(wildcard $d**/)))
endef

SUBDIRS := $(call dfind,$(TOP_DIR)/)
Renaud Pacalet
  • 25,260
  • 3
  • 34
  • 51
0

You may try detect which shell is in use and define variables or functions depending on which. From How to detect shell used in GNU make?

# detect what shell is used
ifeq ($(findstring cmd.exe,$(SHELL)),cmd.exe)
$(info "shell Windows cmd.exe")
DEVNUL := NUL
WHICH := where
else
$(info "shell Bash")
DEVNUL := /dev/null
WHICH := which
endif

Instead (or in addition to) DEVNUL and WHICH you may define FINDDIR. Because of how the arguments work I guess functions is the way to go, see https://www.gnu.org/software/make/manual/html_node/Call-Function.html

Andreas
  • 5,086
  • 3
  • 16
  • 36