419 # Convenience functions for working around make's limitations with $(filter ). |
419 # Convenience functions for working around make's limitations with $(filter ). |
420 containing = $(foreach v,$2,$(if $(findstring $1,$v),$v)) |
420 containing = $(foreach v,$2,$(if $(findstring $1,$v),$v)) |
421 not-containing = $(foreach v,$2,$(if $(findstring $1,$v),,$v)) |
421 not-containing = $(foreach v,$2,$(if $(findstring $1,$v),,$v)) |
422 |
422 |
423 ifneq ($(DISABLE_CACHE_FIND), true) |
423 ifneq ($(DISABLE_CACHE_FIND), true) |
424 ################################################################################ |
424 ################################################################################ |
425 # In Cygwin, finds are very costly, both because of expensive forks and because |
425 # In Cygwin, finds are very costly, both because of expensive forks and because |
426 # of bad file system caching. Find is used extensively in $(shell) commands to |
426 # of bad file system caching. Find is used extensively in $(shell) commands to |
427 # find source files. This makes rerunning make with no or few changes rather |
427 # find source files. This makes rerunning make with no or few changes rather |
428 # expensive. To speed this up, these two macros are used to cache the results |
428 # expensive. To speed this up, these two macros are used to cache the results |
429 # of simple find commands for reuse. |
429 # of simple find commands for reuse. |
430 # |
430 # |
431 # Runs a find and stores both the directories where it was run and the results. |
431 # Runs a find and stores both the directories where it was run and the results. |
432 # This macro can be called multiple times to add to the cache. Only finds files |
432 # This macro can be called multiple times to add to the cache. Only finds files |
433 # with no filters. |
433 # with no filters. |
434 # |
434 # |
435 # Needs to be called with $(eval ) |
435 # Needs to be called with $(eval ) |
436 # |
436 # |
437 # Even if the performance benifit is negligible on other platforms, keep the |
437 # Even if the performance benifit is negligible on other platforms, keep the |
438 # functionality active unless explicitly disabled to exercise it more. |
438 # functionality active unless explicitly disabled to exercise it more. |
439 # |
439 # |
440 # Initialize FIND_CACHE_DIRS with := to make it a non recursively-expanded variable |
440 # Initialize FIND_CACHE_DIRS with := to make it a non recursively-expanded variable |
441 FIND_CACHE_DIRS := |
441 FIND_CACHE_DIRS := |
442 # Param 1 - Dir to find in |
442 # Param 1 - Dirs to find in |
|
443 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression. |
443 define FillCacheFind |
444 define FillCacheFind |
444 # Filter out already cached dirs. The - is needed when FIND_CACHE_DIR is empty |
445 # Filter out already cached dirs. The - is needed when FIND_CACHE_DIRS is empty |
445 # since filter out will then return empty. |
446 # since filter out will then return empty. |
446 FIND_CACHE_NEW_DIRS := $$(filter-out $$(addsuffix /%,\ |
447 FIND_CACHE_NEW_DIRS := $$(filter-out $$(addsuffix /%,\ |
447 - $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS), $1) |
448 - $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS), $1) |
448 ifneq ($$(FIND_CACHE_NEW_DIRS), ) |
449 ifneq ($$(FIND_CACHE_NEW_DIRS), ) |
449 # Remove any trailing slash from dirs in the cache dir list |
450 # Remove any trailing slash from dirs in the cache dir list |
450 FIND_CACHE_DIRS += $$(patsubst %/,%, $$(FIND_CACHE_NEW_DIRS)) |
451 FIND_CACHE_DIRS += $$(patsubst %/,%, $$(FIND_CACHE_NEW_DIRS)) |
451 FIND_CACHE := $$(sort $$(FIND_CACHE) $$(shell $(FIND) $$(FIND_CACHE_NEW_DIRS) -type f -o -type l)) |
452 FIND_CACHE := $$(sort $$(FIND_CACHE) $$(shell $(FIND) $$(FIND_CACHE_NEW_DIRS) \( -type f -o -type l \) $2)) |
452 endif |
453 endif |
453 endef |
454 endef |
454 |
455 |
455 # Mimics find by looking in the cache if all of the directories have been cached. |
456 # Mimics find by looking in the cache if all of the directories have been cached. |
456 # Otherwise reverts to shell find. This is safe to call on all platforms, even if |
457 # Otherwise reverts to shell find. This is safe to call on all platforms, even if |
457 # cache is deactivated. |
458 # cache is deactivated. |
458 # |
459 # |
459 # The extra - is needed when FIND_CACHE_DIR is empty but should be harmless. |
460 # The extra - is needed when FIND_CACHE_DIRS is empty but should be harmless. |
460 # Param 1 - Dirs to find in |
461 # |
461 define CacheFind |
462 # Param 1 - Dirs to find in |
|
463 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression. |
|
464 define CacheFind |
462 $(if $(filter-out $(addsuffix /%,- $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS),$1), \ |
465 $(if $(filter-out $(addsuffix /%,- $(FIND_CACHE_DIRS)) $(FIND_CACHE_DIRS),$1), \ |
463 $(shell $(FIND) $1 -type f -o -type l), \ |
466 $(shell $(FIND) $1 \( -type f -o -type l \) $2), \ |
464 $(filter $(addsuffix %,$1),$(FIND_CACHE))) |
467 $(filter $(addsuffix %,$1),$(FIND_CACHE))) |
465 endef |
468 endef |
466 else |
469 else |
467 # If CacheFind is disabled, just run the find command. |
470 # If CacheFind is disabled, just run the find command. |
|
471 # Param 1 - Dirs to find in |
|
472 # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression. |
468 define CacheFind |
473 define CacheFind |
469 $(shell $(FIND) $1 -type f -o -type l) |
474 $(shell $(FIND) $1 \( -type f -o -type l \) $2) |
470 endef |
475 endef |
471 endif |
476 endif |
472 |
477 |
473 ################################################################################ |
478 ################################################################################ |
474 |
479 |