1#
2#  A Makefile with a collection of reusable functions.
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
23SQUOTE			:= '
24
25# ' # to keep colorized editors from going nuts
26
27MAKE_3_80_realpath	= $(shell $(top_srcdir)/scripts/realpath.sh '$(subst $(SQUOTE),\\$(SQUOTE),$(1))')
28
29MAKE_3_80_abspath	= $(shell $(top_srcdir)/scripts/abspath.sh '$(subst $(SQUOTE),\\$(SQUOTE),$(1))')
30
31#
32# NOTE (garrcoop):
33#
34# The following functions are (sometimes) split into 3.80 and 3.81+
35# counterparts, and not conditionalized inside of the define(s) to work around
36# an issue with how make 3.80 evaluates defines.
37#
38# SO DO NOT INTERNALIZE CONDITIONALS IN DEFINES OR YOU WILL BREAK MAKE 3.80!
39#
40
41#
42# Generate an install rule which also creates the install directory if needed
43# to avoid unnecessary bourne shell based for-loops and install errors, as well
44# as adhoc install rules.
45#
46# 1 -> Target basename.
47# 2 -> Source directory.
48# 3 -> Destination directory.
49#
50ifdef MAKE_3_80_COMPAT
51define generate_install_rule
52
53INSTALL_FILES		+= $$(call MAKE_3_80_abspath,$$(DESTDIR)/$(3)/$(1))
54
55$$(call MAKE_3_80_abspath,$$(DESTDIR)/$(3)/$(1)): \
56    $$(call MAKE_3_80_abspath,$$(dir $$(DESTDIR)/$(3)/$(1)))
57	install -m $$(INSTALL_MODE) "$(2)/$(1)" "$$@"
58endef
59else # not MAKE_3_80_COMPAT
60define generate_install_rule
61
62INSTALL_FILES		+= $$(abspath $$(DESTDIR)/$(3)/$(1))
63
64$$(abspath $$(DESTDIR)/$(3)/$(1)): \
65    $$(abspath $$(dir $$(DESTDIR)/$(3)/$(1)))
66	install -m $$(INSTALL_MODE) "$(2)/$(1)" "$$@"
67endef
68endif # END MAKE_3_80_COMPAT
69
70#
71# Set SUBDIRS to the subdirectories where Makefiles were found.
72#
73define get_make_dirs
74SUBDIRS	?= $$(subst $$(abs_srcdir)/,,$$(patsubst %/Makefile,%,$$(wildcard $$(abs_srcdir)/*/Makefile)))
75SUBDIRS	:= $$(filter-out $$(FILTER_OUT_DIRS),$$(SUBDIRS))
76endef
77