Skip to content

Commit

Permalink
Add shared project top-level Makefile
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
larsclausen authored and Csomi committed Apr 11, 2018
1 parent 377247a commit 297940d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions projects/scripts/project-toplevel.mk
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 297940d

Please sign in to comment.