common/makefiles/MakeBase.gmk
changeset 15051 d32ad37472e6
parent 14279 1c596d0f411c
child 15903 bc0e6cd9d760
--- a/common/makefiles/MakeBase.gmk	Thu Dec 27 20:15:22 2012 +0100
+++ b/common/makefiles/MakeBase.gmk	Thu Dec 27 20:18:21 2012 +0100
@@ -391,4 +391,46 @@
 endef
 endif
 
+# Convenience functions for working around make's limitations with $(filter ).
+containing = $(foreach v,$2,$(if $(findstring $1,$v),$v))
+not-containing = $(foreach v,$2,$(if $(findstring $1,$v),,$v))
+
+################################################################################
+# In Cygwin, finds are very costly, both because of expensive forks and because
+# of bad file system caching. Find is used extensively in $(shell) commands to
+# find source files. This makes rerunning make with no or few changes rather 
+# expensive. To speed this up, these two macros are used to cache the results
+# of simple find commands for reuse.
+# 
+# Runs a find and stores both the directories where it was run and the results.
+# This macro can be called multiple times to add to the cache. Only finds files
+# with no filters.
+#
+# Needs to be called with $(eval )
+# 
+# Param 1 - Dir to find in
+ifeq ($(OPENJDK_BUILD_OS),windows)
+define FillCacheFind
+    FIND_CACHE_DIR += $1
+    FIND_CACHE := $$(sort $$(FIND_CACHE) $$(shell $(FIND) $1 -type f -o -type l))
+endef
+else
+define FillCacheFind
+endef
+endif
+
+# Mimics find by looking in the cache if all of the directories have been cached.
+# Otherwise reverts to shell find. This is safe to call on all platforms, even if
+# cache is deactivated.
+#
+# The extra - is needed when FIND_CACHE_DIR is empty but should be harmless.
+# Param 1 - Dirs to find in
+define CacheFind
+    $(if $(filter-out $(addsuffix %,- $(FIND_CACHE_DIR)),$1),\
+        $(shell $(FIND) $1 -type f -o -type l),\
+        $(filter $(addsuffix %,$1),$(FIND_CACHE)))
+endef
+
+################################################################################
+
 endif # _MAKEBASE_GMK