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