2 # A Makefile with a collection of reusable functions.
4 # Copyright (C) 2009, Cisco Systems Inc.
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.
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.
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.
20 # Garrett Cooper, July 2009
25 # ' # to keep colorized editors from going nuts
27 MAKE_3_80_abspath
= $(shell readlink
-f
'$(subst $(SQUOTE),\\$(SQUOTE),$(1))')
30 # Generate the directory install dependency separate from generate_install_rule
31 # to avoid noise from Make about redefining existing targets, for good reason.
33 # 1 -> The base install directory, based off $(prefix), or another
34 # $(prefix)-like variable. Automatically gets $(DESTDIR) tacked on it.
35 # 2 -> The install target. This can be relative to $(srcdir), but will most
38 define generate_install_rule_dir_dep
39 ifdef MAKE_3_80_COMPAT
40 DIR
:= $$(call MAKE_3_80_abspath
,$(DESTDIR
)/$(1)/$(2))
42 DIR
:= $$(abspath
$(DESTDIR
)/$(1)/$(2))
49 # Generate an install rule which also creates the install directory if needed
50 # to avoid unnecessary bourne shell based for-loops and install errors, as well
51 # as adhoc install rules.
53 # 1 -> Target basename.
54 # 2 -> Source directory.
55 # 3 -> Destination directory.
57 define generate_install_rule
59 # This doesn't do Jack currently, as per the $(MAKECMDGOALS) check in
60 # env_post.mk. I can revisit this `enhancement' later.
61 #CLEAN_TARGETS += $$(INSTALL_FILE)
63 ifdef MAKE_3_80_COMPAT
64 INSTALL_FILES
+= $$(call MAKE_3_80_abspath
,$(DESTDIR
)/$(3)/$(1))
66 INSTALL_FILES
+= $$(abspath
$(DESTDIR
)/$(3)/$(1))
67 endif # MAKE_3_80_COMPAT
69 ifdef MAKE_3_80_COMPAT
70 $$(call MAKE_3_80_abspath
,$(DESTDIR
)/$(3)/$(1)): \
71 $$(call MAKE_3_80_abspath
,$$(dir $(DESTDIR
)/$(3)/$(1)))
73 $$(abspath
$(DESTDIR
)/$(3)/$(1)): \
74 $$(abspath
$$(dir $(DESTDIR
)/$(3)/$(1)))
75 endif # MAKE_3_80_COMPAT
77 @echo
"Executing preinstall command."
80 install -m
$$(INSTALL_MODE
) "$(2)/$(1)" "$$@"
82 @echo
"Executing preinstall command."
88 # Create a vpath rule for a given extension.
91 # 2 -> search directory. Defaults to $(abs_srcdir) if not specified.
93 define generate_vpath_rule
94 ifdef MAKE_3_80_COMPAT
95 ifeq ($$(strip $(2)),)
96 vpath
%.
$(1) $(abs_srcdir
)
99 endif # End $$(strip $(2))
101 vpath
%.
$(1) $$(if
$(2),$(2),$(abs_srcdir
))
102 endif # End ifdef MAKE_3_80_COMPAT
106 # Set SUBDIRS to the subdirectories where Makefiles were found.
109 SUBDIRS ?
= $$(subst $(abs_srcdir
)/,,$$(patsubst %/Makefile
,%,$$(wildcard $(abs_srcdir
)/*/Makefile
)))
110 SUBDIRS
:= $$(filter-out $$(FILTER_OUT_DIRS
),$$(SUBDIRS
))