config/makefiles/autotargets.mk

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 # -*- makefile -*-
     2 # vim:set ts=8 sw=8 sts=8 noet:
     3 #
     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/.
     7 #
     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 ###########################################################################
    18 MKDIR ?= mkdir -p
    19 TOUCH ?= touch
    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 /
    41 slash_strip = \
    42   $(strip \
    43     $(subst <--[**]-->,$(space),\
    44 	$(call _slashSqueeze,\
    45     $(subst $(space),<--[**]-->,$(1))\
    46   )))
    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 #######################
    55 ##---]  TARGETS  [---##
    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, 1980 to accomodate any timezone where
    62 # 198001010000 would translate to something older than FAT epoch.
    63 	@$(TOUCH) -t 198001030000 '$@'
    65 # A handful of makefiles are attempting "mkdir dot".
    66 # tbpl/valgrind builds are using this target
    67 # https://bugzilla.mozilla.org/show_bug.cgi?id=837754
    68 .mkdir.done:
    69 	@echo 'WARNING: $(MKDIR) -dot- requested by $(MAKE) -C $(CURDIR) $(MAKECMDGOALS)'
    70 	@$(TOUCH) -t 198001030000 '$@'
    72 INCLUDED_AUTOTARGETS_MK = 1
    73 endif #}
    76 ## Accumulate deps and cleanup
    77 ifneq (,$(GENERATED_DIRS))
    78   GENERATED_DIRS := $(strip $(sort $(GENERATED_DIRS)))
    79   tmpauto :=$(call mkdir_deps,GENERATED_DIRS)
    80   GENERATED_DIRS_DEPS +=$(tmpauto)
    81   GARBAGE_DIRS        +=$(GENERATED_DIRS)
    82 endif
    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)
    91 AUTO_DEPS := $(strip $(sort $(AUTO_DEPS)))
    93 # Complain loudly if deps have not loaded so getargv != $(NULL)
    94 $(call requiredfunction,getargv)

mercurial