1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/config/makefiles/autotargets.mk Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 1.4 +# -*- makefile -*- 1.5 +# vim:set ts=8 sw=8 sts=8 noet: 1.6 +# 1.7 +# This Source Code Form is subject to the terms of the Mozilla Public 1.8 +# License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.9 +# You can obtain one at http://mozilla.org/MPL/2.0/. 1.10 +# 1.11 + 1.12 +ifndef INCLUDED_AUTOTARGETS_MK #{ 1.13 + 1.14 +# Conditional does not wrap the entire file so multiple 1.15 +# includes will be able to accumulate dependencies. 1.16 + 1.17 +########################################################################### 1.18 +# AUTO_DEPS - A list of deps/targets drived from other macros. 1.19 +########################################################################### 1.20 + 1.21 +MKDIR ?= mkdir -p 1.22 +TOUCH ?= touch 1.23 + 1.24 +# declare for local use, rules.mk may not have been loaded 1.25 +space = $(NULL) $(NULL) 1.26 + 1.27 +# Deps will be considered intermediate when used as a pre-requisite for 1.28 +# wildcard targets. Inhibit their removal, mkdir -p is a standalone op. 1.29 +.PRECIOUS: %/.mkdir.done 1.30 + 1.31 +######################### 1.32 +##---] FUNCTIONS [---## 1.33 +######################### 1.34 + 1.35 +# Squeeze can be overzealous, restore root for abspath 1.36 +getPathPrefix =$(if $(filter /%,$(1)),/) 1.37 + 1.38 +# Squeeze '//' from the path, easily created by string functions 1.39 +_slashSqueeze =$(foreach val,$(getargv),$(call getPathPrefix,$(val))$(subst $(space),/,$(strip $(subst /,$(space),$(val))))) 1.40 + 1.41 +# Squeeze extraneous directory slashes from the path 1.42 +# o protect embedded spaces within the path 1.43 +# o replace //+ sequences with / 1.44 +slash_strip = \ 1.45 + $(strip \ 1.46 + $(subst <--[**]-->,$(space),\ 1.47 + $(call _slashSqueeze,\ 1.48 + $(subst $(space),<--[**]-->,$(1))\ 1.49 + ))) 1.50 + 1.51 +# Extract directory path from a dependency file. 1.52 +mkdir_stem =$(foreach val,$(getargv),$(subst /.mkdir.done,$(NULL),$(val))) 1.53 + 1.54 +## Generate timestamp file for threadsafe directory creation 1.55 +mkdir_deps =$(foreach dir,$(getargv),$(call slash_strip,$(dir)/.mkdir.done)) 1.56 + 1.57 +####################### 1.58 +##---] TARGETS [---## 1.59 +####################### 1.60 + 1.61 +%/.mkdir.done: # mkdir -p -p => mkdir -p 1.62 + $(subst $(space)-p,$(null),$(MKDIR)) -p '$(dir $@)' 1.63 +# Make the timestamp old enough for not being a problem with symbolic links 1.64 +# targets depending on it. Use Jan 3, 1980 to accomodate any timezone where 1.65 +# 198001010000 would translate to something older than FAT epoch. 1.66 + @$(TOUCH) -t 198001030000 '$@' 1.67 + 1.68 +# A handful of makefiles are attempting "mkdir dot". 1.69 +# tbpl/valgrind builds are using this target 1.70 +# https://bugzilla.mozilla.org/show_bug.cgi?id=837754 1.71 +.mkdir.done: 1.72 + @echo 'WARNING: $(MKDIR) -dot- requested by $(MAKE) -C $(CURDIR) $(MAKECMDGOALS)' 1.73 + @$(TOUCH) -t 198001030000 '$@' 1.74 + 1.75 +INCLUDED_AUTOTARGETS_MK = 1 1.76 +endif #} 1.77 + 1.78 + 1.79 +## Accumulate deps and cleanup 1.80 +ifneq (,$(GENERATED_DIRS)) 1.81 + GENERATED_DIRS := $(strip $(sort $(GENERATED_DIRS))) 1.82 + tmpauto :=$(call mkdir_deps,GENERATED_DIRS) 1.83 + GENERATED_DIRS_DEPS +=$(tmpauto) 1.84 + GARBAGE_DIRS +=$(GENERATED_DIRS) 1.85 +endif 1.86 + 1.87 +################################################################# 1.88 +# One ring/dep to rule them all: 1.89 +# config/rules.mk::all target is available by default 1.90 +# Add $(AUTO_DEPS) as an explicit target dependency when needed. 1.91 +################################################################# 1.92 + 1.93 +AUTO_DEPS +=$(GENERATED_DIRS_DEPS) 1.94 +AUTO_DEPS := $(strip $(sort $(AUTO_DEPS))) 1.95 + 1.96 +# Complain loudly if deps have not loaded so getargv != $(NULL) 1.97 +$(call requiredfunction,getargv)