• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2#    Generic trunk rules include Makefile.
3#
4#    Copyright (C) 2009, Cisco Systems Inc.
5#
6#    This program is free software; you can redistribute it and/or modify
7#    it under the terms of the GNU General Public License as published by
8#    the Free Software Foundation; either version 2 of the License, or
9#    (at your option) any later version.
10#
11#    This program is distributed in the hope that it will be useful,
12#    but WITHOUT ANY WARRANTY; without even the implied warranty of
13#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14#    GNU General Public License for more details.
15#
16#    You should have received a copy of the GNU General Public License along
17#    with this program; if not, write to the Free Software Foundation, Inc.,
18#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19#
20# Ngie Cooper, July 2009
21#
22
23#
24# generic_trunk_target
25#
26# Generate a set of recursive targets to apply over a trunk directory (has
27# directories) -- optionally with a set of trunk-based files.
28#
29# All variables in this canned define are essentially the same as
30# generic_leaf_target, with the exception that the install flow for local
31# targets is:
32#
33# $(INSTALL_FILES) -> trunk-install -> install (recursive)
34#
35# All recursive targets are traverse SUBDIRS as defined by the user, or if
36# undefined, defaults to any subdirectories where Makefile's are contained
37# within.
38#
39# generic_trunk_target specific variables are:
40#
41# RECURSIVE_TARGETS		: a list of targets to apply over an entire
42# 				  directory tree. This defaults to
43# 				  `all install'.
44#
45# See generic_leaf_target, generic_target_env_setup, and get_make_dirs for
46# more details and design notes.
47#
48
49include $(top_srcdir)/include/mk/functions.mk
50
51RECURSIVE_TARGETS		?= all install
52
53$(eval $(get_make_dirs))
54
55.PHONY: $(RECURSIVE_TARGETS) $(addprefix trunk-,$(RECURSIVE_TARGETS))
56
57$(SUBDIRS): %:
58	mkdir -m 00755 -p "$@"
59
60$(MAKE_TARGETS): | $(MAKE_DEPS)
61
62trunk-all: $(MAKE_TARGETS)
63
64trunk-clean:: | $(SUBDIRS)
65	$(if $(strip $(CLEAN_TARGETS)),$(RM) -f $(CLEAN_TARGETS))
66
67$(INSTALL_FILES): | $(INSTALL_DEPS)
68
69trunk-install: $(INSTALL_FILES)
70
71# Avoid creating duplicate .PHONY references to all, clean, and install. IIRC,
72# I've seen some indeterministic behavior when one does this in the past with
73# GNU Make...
74.PHONY: $(filter-out $(RECURSIVE_TARGETS),all clean install)
75all: trunk-all
76
77clean:: trunk-clean
78	@set -e; for dir in $(SUBDIRS); do \
79	    $(MAKE) -C "$$dir" -f "$(abs_srcdir)/$$dir/Makefile" $@; \
80	done
81ifneq ($(abs_builddir),$(abs_srcdir))
82	$(RM) -Rf $(SUBDIRS)
83endif
84
85install: trunk-install
86
87# Print out CURDIR to check for a recursion issue.
88ifeq ($(strip $(SUBDIRS)),)
89	$(warning CURDIR is: $(CURDIR))
90	$(error SUBDIRS empty -- did you want generic_leaf_target instead?)
91else
92$(RECURSIVE_TARGETS): %: | $(SUBDIRS)
93	@set -e; for dir in $(SUBDIRS); do \
94	    $(MAKE) -C $$dir -f "$(abs_srcdir)/$$dir/Makefile" $@; \
95	done
96endif
97
98# vim: syntax=make
99