Add shared project top-level Makefile

The project top-level Makefile accept the all, clean and clean-all targets
and forward them to their sub-projects.

Create a common Makefile include that can be used to implement this
behavior. The shared Makefile collects all sub-directories that have a
Makefile and then forwards the all, clean and clean-all targets to them.

This is implemented by creating virtual targets for each combination of
sub-project and all, clean, clean-all targets in the form of
"$project/all", ... These virtual sub-targets are then listed as the
prerequisites of the project top-level Makefile targets.

This means there is no longer a need to re-generate top-level Makefiles
when a new project or sub-project is added.

It will also allow to remove a lot of boilerplate code.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
main
Lars-Peter Clausen 2018-03-23 14:29:32 +01:00 committed by István Csomortáni
parent 377247a434
commit 297940d5d9
1 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,19 @@
####################################################################################
## Copyright 2018(c) Analog Devices, Inc.
####################################################################################
SUBDIRS := $(dir $(wildcard */Makefile))
# Create virtual targets "$project/all", "$project/clean", "$project/clean-all"
SUBDIRS_ALL := $(addsuffix all,$(SUBDIRS))
SUBDIRS_CLEAN := $(addsuffix clean,$(SUBDIRS))
SUBDIRS_CLEANALL := $(addsuffix clean-all,$(SUBDIRS))
.PHONY: all clean clean-all $(SUBDIRS_ALL) $(SUBDIRS_CLEAN) $(SUBDIRS_CLEANALL)
all: $(SUBDIRS_ALL)
clean: $(SUBDIRS_CLEAN)
clean-all: $(SUBDIRS_CLEANALL)
$(SUBDIRS_ALL) $(SUBDIRS_CLEAN) $(SUBDIRS_CLEANALL):
$(MAKE) -C $(@D) $(@F)