michael@0: # -*- makefile -*- michael@0: # vim:set ts=8 sw=8 sts=8 noet: michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: # You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: # michael@0: michael@0: ifndef INCLUDED_AUTOTARGETS_MK #{ michael@0: michael@0: # Conditional does not wrap the entire file so multiple michael@0: # includes will be able to accumulate dependencies. michael@0: michael@0: ########################################################################### michael@0: # AUTO_DEPS - A list of deps/targets drived from other macros. michael@0: ########################################################################### michael@0: michael@0: MKDIR ?= mkdir -p michael@0: TOUCH ?= touch michael@0: michael@0: # declare for local use, rules.mk may not have been loaded michael@0: space = $(NULL) $(NULL) michael@0: michael@0: # Deps will be considered intermediate when used as a pre-requisite for michael@0: # wildcard targets. Inhibit their removal, mkdir -p is a standalone op. michael@0: .PRECIOUS: %/.mkdir.done michael@0: michael@0: ######################### michael@0: ##---] FUNCTIONS [---## michael@0: ######################### michael@0: michael@0: # Squeeze can be overzealous, restore root for abspath michael@0: getPathPrefix =$(if $(filter /%,$(1)),/) michael@0: michael@0: # Squeeze '//' from the path, easily created by string functions michael@0: _slashSqueeze =$(foreach val,$(getargv),$(call getPathPrefix,$(val))$(subst $(space),/,$(strip $(subst /,$(space),$(val))))) michael@0: michael@0: # Squeeze extraneous directory slashes from the path michael@0: # o protect embedded spaces within the path michael@0: # o replace //+ sequences with / michael@0: slash_strip = \ michael@0: $(strip \ michael@0: $(subst <--[**]-->,$(space),\ michael@0: $(call _slashSqueeze,\ michael@0: $(subst $(space),<--[**]-->,$(1))\ michael@0: ))) michael@0: michael@0: # Extract directory path from a dependency file. michael@0: mkdir_stem =$(foreach val,$(getargv),$(subst /.mkdir.done,$(NULL),$(val))) michael@0: michael@0: ## Generate timestamp file for threadsafe directory creation michael@0: mkdir_deps =$(foreach dir,$(getargv),$(call slash_strip,$(dir)/.mkdir.done)) michael@0: michael@0: ####################### michael@0: ##---] TARGETS [---## michael@0: ####################### michael@0: michael@0: %/.mkdir.done: # mkdir -p -p => mkdir -p michael@0: $(subst $(space)-p,$(null),$(MKDIR)) -p '$(dir $@)' michael@0: # Make the timestamp old enough for not being a problem with symbolic links michael@0: # targets depending on it. Use Jan 3, 1980 to accomodate any timezone where michael@0: # 198001010000 would translate to something older than FAT epoch. michael@0: @$(TOUCH) -t 198001030000 '$@' michael@0: michael@0: # A handful of makefiles are attempting "mkdir dot". michael@0: # tbpl/valgrind builds are using this target michael@0: # https://bugzilla.mozilla.org/show_bug.cgi?id=837754 michael@0: .mkdir.done: michael@0: @echo 'WARNING: $(MKDIR) -dot- requested by $(MAKE) -C $(CURDIR) $(MAKECMDGOALS)' michael@0: @$(TOUCH) -t 198001030000 '$@' michael@0: michael@0: INCLUDED_AUTOTARGETS_MK = 1 michael@0: endif #} michael@0: michael@0: michael@0: ## Accumulate deps and cleanup michael@0: ifneq (,$(GENERATED_DIRS)) michael@0: GENERATED_DIRS := $(strip $(sort $(GENERATED_DIRS))) michael@0: tmpauto :=$(call mkdir_deps,GENERATED_DIRS) michael@0: GENERATED_DIRS_DEPS +=$(tmpauto) michael@0: GARBAGE_DIRS +=$(GENERATED_DIRS) michael@0: endif michael@0: michael@0: ################################################################# michael@0: # One ring/dep to rule them all: michael@0: # config/rules.mk::all target is available by default michael@0: # Add $(AUTO_DEPS) as an explicit target dependency when needed. michael@0: ################################################################# michael@0: michael@0: AUTO_DEPS +=$(GENERATED_DIRS_DEPS) michael@0: AUTO_DEPS := $(strip $(sort $(AUTO_DEPS))) michael@0: michael@0: # Complain loudly if deps have not loaded so getargv != $(NULL) michael@0: $(call requiredfunction,getargv)