Fix the creation of the dumpdir directory in stress_floppy Makefile
[ltp-debian.git] / include / mk / functions.mk
blob7885db5cd00568798c091f1268a2e2b483db595a
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
23 SQUOTE := '
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
36 # likely be `empty'.
38 define generate_install_rule_dir_dep
39 ifdef MAKE_3_80_COMPAT
40 DIR := $$(call MAKE_3_80_abspath,$(DESTDIR)/$(1)/$(2))
41 else
42 DIR := $$(abspath $(DESTDIR)/$(1)/$(2))
43 endif
44 $$(DIR):
45 mkdir -p "$$@"
46 endef
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))
65 else
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)))
72 else
73 $$(abspath $(DESTDIR)/$(3)/$(1)): \
74 $$(abspath $$(dir $(DESTDIR)/$(3)/$(1)))
75 endif # MAKE_3_80_COMPAT
76 ifdef INSTALL_PRE
77 @echo "Executing preinstall command."
78 $$(INSTALL_PRE)
79 endif
80 install -m $$(INSTALL_MODE) "$(2)/$(1)" "$$@"
81 ifdef INSTALL_POST
82 @echo "Executing preinstall command."
83 $$(INSTALL_POST)
84 endif
85 endef
88 # Create a vpath rule for a given extension.
90 # 1 -> file 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)
97 else
98 vpath %.$(1) $(2)
99 endif # End $$(strip $(2))
100 else
101 vpath %.$(1) $$(if $(2),$(2),$(abs_srcdir))
102 endif # End ifdef MAKE_3_80_COMPAT
103 endef
106 # Set SUBDIRS to the subdirectories where Makefiles were found.
108 define get_make_dirs
109 SUBDIRS ?= $$(subst $(abs_srcdir)/,,$$(patsubst %/Makefile,%,$$(wildcard $(abs_srcdir)/*/Makefile)))
110 SUBDIRS := $$(filter-out $$(FILTER_OUT_DIRS),$$(SUBDIRS))
111 endef