diff --git a/config/makefiles/autotargets.mk b/config/makefiles/autotargets.mk index 595729e65586..5d6daa5fd943 100644 --- a/config/makefiles/autotargets.mk +++ b/config/makefiles/autotargets.mk @@ -18,26 +18,54 @@ ifndef INCLUDED_AUTOTARGETS_MK #{ 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 -########################################################################### -# Threadsafe directory creation -# GENERATED_DIRS - Automated creation of these directories. -# Squeeze '//' from the path, easily created by $(dir $(path)) -########################################################################### -mkdir_deps =$(subst //,/,$(foreach dir,$(getargv),$(dir)/.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 $@) + $(subst $(space)-p,$(null),$(MKDIR)) -p $(dir $@) @$(TOUCH) $@ # A handful of makefiles are attempting "mkdir dot". Likely not intended # or stale logic so add a stub target to handle the request and warn for now. .mkdir.done: +ifndef NOWARN_AUTOTARGETS # { @echo "WARNING: $(MKDIR) -dot- requested by $(MAKE) -C $(CURDIR) $(MAKECMDGOALS)" @$(TOUCH) $@ +endif #} INCLUDED_AUTOTARGETS_MK = 1 endif #} diff --git a/config/makefiles/test/Makefile.in b/config/makefiles/test/Makefile.in index 7462e2a4fe26..df8cfc258a0d 100644 --- a/config/makefiles/test/Makefile.in +++ b/config/makefiles/test/Makefile.in @@ -11,6 +11,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk +USE_AUTOTARGETS_MK = 1 MAKEUTILS_UNIT_TEST = 1 include $(topsrcdir)/config/makefiles/makeutils.mk diff --git a/config/makefiles/test/check-autotargets.mk b/config/makefiles/test/check-autotargets.mk index df10d4a918de..80c33060f685 100644 --- a/config/makefiles/test/check-autotargets.mk +++ b/config/makefiles/test/check-autotargets.mk @@ -8,8 +8,11 @@ ifdef VERBOSE $(warning loading test) endif +space=$(null) $(null) GENERATED_DIRS = bogus # test data +NOWARN_AUTOTARGETS = 1 # Unit test includes makefile twice. + undefine USE_AUTOTARGETS_MK undefine INCLUDED_AUTOTARGETS_MK include $(topsrcdir)/config/makefiles/autotargets.mk @@ -30,9 +33,54 @@ ifneq (bogus,$(findstring bogus,$(AUTO_DEPS))) $(error AUTO_DEPS=[$(AUTO_DEPS)] is not set correctly) endif -path = foo/bar.c -exp = foo/.mkdir.done -found = $(call mkdir_deps,$(dir $(path))) + +# relpath +path := foo/bar.c +exp := foo/.mkdir.done +found := $(call mkdir_deps,$(dir $(path))) ifneq ($(exp),$(found)) $(error mkdir_deps($(path))=$(exp) not set correctly [$(found)]) endif + +# abspath +path := /foo//bar/ +exp := /foo/bar/.mkdir.done +found := $(call mkdir_deps,$(path)) +ifneq ($(exp),$(found)) + $(error mkdir_deps($(path))=$(exp) not set correctly [$(found)]) +endif + + +## verify strip_slash +##################### + +path := a/b//c///d////e///// +exp := a/b/c/d/e/.mkdir.done +found := $(call mkdir_deps,$(path)) +ifneq ($(exp),$(found)) + $(error mkdir_deps($(path))=$(exp) not set correctly [$(found)]) +endif + + +## verify mkdir_stem() +###################### +path := verify/mkdir_stem +pathD = $(call mkdir_deps,$(path)) +pathS = $(call mkdir_stem,$(pathD)) +exp := $(path) + +ifeq ($(pathD),$(pathS)) + $(error mkdir_deps and mkdir_stem should not match [$(pathD)]) +endif +ifneq ($(pathS),$(exp)) + $(error mkdir_stem=[$(pathS)] != exp=[$(exp)]) +endif + + +## Verify embedded whitespace has been protected +path := a/b$(space)c//d +exp := a/b$(space)c/d +found := $(call slash_strip,$(path)) +ifneq ($(exp),$(found)) + $(error slash_strip($(path))=$(exp) not set correctly [$(found)]) +endif diff --git a/js/src/config/makefiles/autotargets.mk b/js/src/config/makefiles/autotargets.mk index 595729e65586..5d6daa5fd943 100644 --- a/js/src/config/makefiles/autotargets.mk +++ b/js/src/config/makefiles/autotargets.mk @@ -18,26 +18,54 @@ ifndef INCLUDED_AUTOTARGETS_MK #{ 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 -########################################################################### -# Threadsafe directory creation -# GENERATED_DIRS - Automated creation of these directories. -# Squeeze '//' from the path, easily created by $(dir $(path)) -########################################################################### -mkdir_deps =$(subst //,/,$(foreach dir,$(getargv),$(dir)/.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 $@) + $(subst $(space)-p,$(null),$(MKDIR)) -p $(dir $@) @$(TOUCH) $@ # A handful of makefiles are attempting "mkdir dot". Likely not intended # or stale logic so add a stub target to handle the request and warn for now. .mkdir.done: +ifndef NOWARN_AUTOTARGETS # { @echo "WARNING: $(MKDIR) -dot- requested by $(MAKE) -C $(CURDIR) $(MAKECMDGOALS)" @$(TOUCH) $@ +endif #} INCLUDED_AUTOTARGETS_MK = 1 endif #}