2
# vim:set ts=8 sw=8 sts=8 noet:
4
# This Source Code Form is subject to the terms of the Mozilla Public
5
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
6
# You can obtain one at http://mozilla.org/MPL/2.0/.
9
ifndef INCLUDED_AUTOTARGETS_MK #{
11
# Conditional does not wrap the entire file so multiple
12
# includes will be able to accumulate dependencies.
14
###########################################################################
15
# AUTO_DEPS - A list of deps/targets drived from other macros.
16
###########################################################################
21
# declare for local use, rules.mk may not have been loaded
22
space = $(NULL) $(NULL)
24
# Deps will be considered intermediate when used as a pre-requisite for
25
# wildcard targets. Inhibit their removal, mkdir -p is a standalone op.
26
.PRECIOUS: %/.mkdir.done
28
#########################
29
##---] FUNCTIONS [---##
30
#########################
32
# Squeeze can be overzealous, restore root for abspath
33
getPathPrefix =$(if $(filter /%,$(1)),/)
35
# Squeeze '//' from the path, easily created by string functions
36
_slashSqueeze =$(foreach val,$(getargv),$(call getPathPrefix,$(val))$(subst $(space),/,$(strip $(subst /,$(space),$(val)))))
38
# Squeeze extraneous directory slashes from the path
39
# o protect embedded spaces within the path
40
# o replace //+ sequences with /
43
$(subst <--[**]-->,$(space),\
44
$(call _slashSqueeze,\
45
$(subst $(space),<--[**]-->,$(1))\
48
# Extract directory path from a dependency file.
49
mkdir_stem =$(foreach val,$(getargv),$(subst /.mkdir.done,$(NULL),$(val)))
51
## Generate timestamp file for threadsafe directory creation
52
mkdir_deps =$(foreach dir,$(getargv),$(call slash_strip,$(dir)/.mkdir.done))
54
#######################
56
#######################
58
%/.mkdir.done: # mkdir -p -p => mkdir -p
59
$(subst $(space)-p,$(null),$(MKDIR)) -p $(dir $@)
60
# Make the timestamp old enough for not being a problem with symbolic links
61
# targets depending on it. Use Jan 3, 1970 to accomodate any timezone where
62
# 197001010000 would translate to something older than epoch.
63
@touch -t 197001030000 $@
65
# A handful of makefiles are attempting "mkdir dot". Likely not intended
66
# or stale logic so add a stub target to handle the request and warn for now.
68
ifndef NOWARN_AUTOTARGETS # {
69
@echo "WARNING: $(MKDIR) -dot- requested by $(MAKE) -C $(CURDIR) $(MAKECMDGOALS)"
70
@touch -t 197001030000 $@
73
INCLUDED_AUTOTARGETS_MK = 1
77
## Accumulate deps and cleanup
78
ifneq (,$(GENERATED_DIRS))
79
tmpauto :=$(call mkdir_deps,GENERATED_DIRS)
80
GENERATED_DIRS_DEPS +=$(tmpauto)
81
GARBAGE_DIRS +=$(GENERATED_DIRS)
84
#################################################################
85
# One ring/dep to rule them all:
86
# config/rules.mk::all target is available by default
87
# Add $(AUTO_DEPS) as an explicit target dependency when needed.
88
#################################################################
90
AUTO_DEPS +=$(GENERATED_DIRS_DEPS)
92
# Complain loudly if deps have not loaded so getargv != $(NULL)
93
$(call requiredfunction,getargv)