Blame | Last modification | View Log | RSS feed
# Copyright (c) 2008 Fabio Checconi <fabio@gandalf.sssup.it>
#
# Helper file defining standard targets for Shark applications. It should
# be included from the application makefiles in this way (preserving much
# of the old behavior):
#
# # Example of Shark application makefile.
# S?=<source tree>
# B?=<build tree, if different from $(S)>
#
# SUBDIRS:= <list of subdirectories>
# APPS:= <list of applications>
#
# include $(S)/mk/App.mk
#
# # For each <application>:
# <application>:
# make -f $(S)/Makefile APP=<application> \
# OTHEROBJS="<list of objects>" \
# OTHERINCL="<list of extra include dirs>" \
# SHARKOPT="<list of options>"
#
# # End of Shark application makefile example.
#
ifndef S
$(error Missing Shark source tree specification)
endif
define subdir-templ
.PHONY: $(1)-$(2)
$(1)-$(2):
make -C $(1) $(2)
endef
define export-if-defined
ifdef $(1)
export $(1)
endif
endef
to-be-exported:= S B O CROSS_COMPILE AR CC LD RM INSTALL V
$(foreach v, $(to-be-exported),$(eval $(call export-if-defined,$(v))))
foreach-subdir=$(foreach d, $(SUBDIRS),$(eval $(call subdir-templ,$d,$1)))
# The default target: build all subdirs and all the applications in the
# current directory.
.PHONY: all
all: subdirs $(APPS)
# Build subdirs before applications.
$(APPS): subdirs
.PHONY: subdirs
# Build all the subdirs
$(call foreach-subdir,all)
subdirs: $(addsuffix -all,$(SUBDIRS))
.PHONY: clean
$(call foreach-subdir,clean)
clean: $(addsuffix -clean,$(SUBDIRS))
rm -f *.o $(APPS)
.PHONY: distclean
$(call foreach-subdir,distclean)
distclean: clean $(addsuffix -distclean,$(SUBDIRS))
rm -f .*.deps