The following example assumes that all sub-directories are listed in $(SUBDIRS) variable. All the entries in $(SUBDIRS) can be iterated using a “for” loop as shown below and “make clean” can be run in each directory.

SUBDIRS = dir1 dir2 dir3
clean:
	for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done

Note that if you doing are copy-n-paste of the above snippet, the “for” statement should be indented with a TAB. Otherwise it will result in make error.

In the above example “clean” rule can be replaced with any other rule.

The -C option tells GNU make to change to a specific directory before reading the makefiles.