config/makefiles/autotargets.mk
author Dorel Luca <dluca@mozilla.com>
Sat, 13 Jan 2018 15:17:49 +0200
changeset 399195 64f82460345884dd0f5935645765acccf771d7c4
parent 158331 942d149a7c0c6c4f85f8c212a2414f58b90585f7
permissions -rw-r--r--
Backed out 19 changesets (bug 1411654) for Android nightly bustages a=backout Backed out changeset 649e7aa405ca (bug 1411654) Backed out changeset c2e51b70519f (bug 1411654) Backed out changeset a371f3ef4312 (bug 1411654) Backed out changeset db978e230556 (bug 1411654) Backed out changeset 56538ed998cf (bug 1411654) Backed out changeset 6ff0cdf46a3d (bug 1411654) Backed out changeset 0e493bacc5e3 (bug 1411654) Backed out changeset 23cbcf427745 (bug 1411654) Backed out changeset eda74143389f (bug 1411654) Backed out changeset 359fadf9b3e9 (bug 1411654) Backed out changeset 5c64eda20f1e (bug 1411654) Backed out changeset bffb6a5b78d1 (bug 1411654) Backed out changeset 43787f4089c3 (bug 1411654) Backed out changeset 9141bbdfd13b (bug 1411654) Backed out changeset 108674372ef7 (bug 1411654) Backed out changeset fb15e1f54987 (bug 1411654) Backed out changeset 264476c77210 (bug 1411654) Backed out changeset d23f467218da (bug 1411654) Backed out changeset 78576ff98660 (bug 1411654)

# -*- 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/.
#

ifndef INCLUDED_AUTOTARGETS_MK #{

# Conditional does not wrap the entire file so multiple
# includes will be able to accumulate dependencies.

###########################################################################
#      AUTO_DEPS - A list of deps/targets drived from other macros.
###########################################################################

MKDIR ?= mkdir -p
TOUCH ?= touch

# declare for local use, rules.mk may not have been loaded
space = $(NULL) $(NULL)

# 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

#########################
##---]  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 /
slash_strip = \
  $(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
mkdir_deps =$(foreach dir,$(getargv),$(call slash_strip,$(dir)/.mkdir.done))

#######################
##---]  TARGETS  [---##
#######################

%/.mkdir.done: # mkdir -p -p => mkdir -p
	$(subst $(space)-p,$(null),$(MKDIR)) -p '$(dir $@)'
# Make the timestamp old enough for not being a problem with symbolic links
# targets depending on it. Use Jan 3, 1980 to accomodate any timezone where
# 198001010000 would translate to something older than FAT epoch.
	@$(TOUCH) -t 198001030000 '$@'

# 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:
	@echo 'WARNING: $(MKDIR) -dot- requested by $(MAKE) -C $(CURDIR) $(MAKECMDGOALS)'
	@$(TOUCH) -t 198001030000 '$@'

INCLUDED_AUTOTARGETS_MK = 1
endif #}


## 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

#################################################################
# 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.
#################################################################

AUTO_DEPS +=$(GENERATED_DIRS_DEPS)
AUTO_DEPS := $(strip $(sort $(AUTO_DEPS)))

# Complain loudly if deps have not loaded so getargv != $(NULL)
$(call requiredfunction,getargv)