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 check 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$(CHECK_TARGETS): | $(CHECK_DEPS) 72trunk-check: $(CHECK_TARGETS) $(SHELL_CHECK_TARGETS) 73 74# Avoid creating duplicate .PHONY references to all, clean, and install. IIRC, 75# I've seen some indeterministic behavior when one does this in the past with 76# GNU Make... 77.PHONY: $(filter-out $(RECURSIVE_TARGETS),all clean install) 78all: trunk-all 79 80clean:: trunk-clean 81ifdef VERBOSE 82 @set -e; for dir in $(SUBDIRS); do \ 83 $(MAKE) -C "$$dir" -f "$(abs_srcdir)/$$dir/Makefile" $@; \ 84 done 85else 86 @set -e; for dir in $(SUBDIRS); do \ 87 echo "DIR $$dir"; \ 88 $(MAKE) --no-print-directory -C "$$dir" -f "$(abs_srcdir)/$$dir/Makefile" $@; \ 89 done 90endif 91ifneq ($(abs_builddir),$(abs_srcdir)) 92 $(RM) -Rf $(SUBDIRS) 93endif 94 95install: trunk-install 96 97# Print out CURDIR to check for a recursion issue. 98ifeq ($(strip $(SUBDIRS)),) 99 $(warning CURDIR is: $(CURDIR)) 100 $(error SUBDIRS empty -- did you want generic_leaf_target instead?) 101else 102$(RECURSIVE_TARGETS): %: | $(SUBDIRS) 103ifdef VERBOSE 104 @set -e; for dir in $(SUBDIRS); do \ 105 $(MAKE) -C $$dir -f "$(abs_srcdir)/$$dir/Makefile" $@; \ 106 done 107else 108 @set -e; for dir in $(SUBDIRS); do \ 109 $(MAKE) --no-print-directory -C $$dir -f "$(abs_srcdir)/$$dir/Makefile" $@; \ 110 done 111endif 112endif 113 114check: trunk-check 115 116# vim: syntax=make 117