390 |
390 |
391 $2 |
391 $2 |
392 endef |
392 endef |
393 |
393 |
394 # Make directory without forking mkdir if not needed |
394 # Make directory without forking mkdir if not needed |
395 define MakeDir |
395 MakeDir = \ |
396 ifneq ($$(wildcard $1 $2 $3 $4 $5 $6 $7 $8 $9),$$(strip $1 $2 $3 $4 $5 $6 $7 $8 $9)) |
396 $(strip $(if $(subst $(wildcard $1 $2 $3 $4 $5 $6 $7 $8 $9),,$(strip $1 $2 $3 $4 $5 $6 $7 $8 $9)),\ |
397 $$(shell $(MKDIR) -p $1 $2 $3 $4 $5 $6 $7 $8 $9) |
397 $(shell $(MKDIR) -p $1 $2 $3 $4 $5 $6 $7 $8 $9))) |
398 endif |
|
399 endef |
|
400 |
398 |
401 ifeq ($(OPENJDK_TARGET_OS),solaris) |
399 ifeq ($(OPENJDK_TARGET_OS),solaris) |
402 # On Solaris, if the target is a symlink and exists, cp won't overwrite. |
400 # On Solaris, if the target is a symlink and exists, cp won't overwrite. |
403 # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the |
401 # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the |
404 # name of the target file differs from the source file, rename after copy. |
402 # name of the target file differs from the source file, rename after copy. |
444 not-containing = $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),,$v))) |
442 not-containing = $(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),,$v))) |
445 |
443 |
446 # Filter out duplicate sub strings while preserving order. Keeps the first occurance. |
444 # Filter out duplicate sub strings while preserving order. Keeps the first occurance. |
447 uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) |
445 uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) |
448 |
446 |
|
447 # String equals |
|
448 equals = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1))) |
|
449 |
449 ifneq ($(DISABLE_CACHE_FIND), true) |
450 ifneq ($(DISABLE_CACHE_FIND), true) |
450 ################################################################################ |
451 ################################################################################ |
451 # In Cygwin, finds are very costly, both because of expensive forks and because |
452 # In Cygwin, finds are very costly, both because of expensive forks and because |
452 # of bad file system caching. Find is used extensively in $(shell) commands to |
453 # of bad file system caching. Find is used extensively in $(shell) commands to |
453 # find source files. This makes rerunning make with no or few changes rather |
454 # find source files. This makes rerunning make with no or few changes rather |
561 $$($1_DEST)/$$(if $$($1_FLATTEN),$$(notdir $$f),$$f), $1, $$($1_MACRO)))) |
562 $$($1_DEST)/$$(if $$($1_FLATTEN),$$(notdir $$f),$$f), $1, $$($1_MACRO)))) |
562 |
563 |
563 endef |
564 endef |
564 |
565 |
565 ################################################################################ |
566 ################################################################################ |
|
567 # ShellQuote |
|
568 # |
|
569 # Quotes a string with single quotes and replaces single quotes with '\'' so |
|
570 # that the contents survives being given to the shell. |
|
571 |
|
572 ShellQuote = \ |
|
573 $(SQUOTE)$(subst $(SQUOTE),$(SQUOTE)\$(SQUOTE)$(SQUOTE),$(strip $1))$(SQUOTE) |
|
574 |
|
575 ################################################################################ |
|
576 # Write to and read from file |
|
577 |
|
578 # Param 1 - File to read |
|
579 ReadFile = \ |
|
580 $(shell $(CAT) $1) |
|
581 |
|
582 # Param 1 - Text to write |
|
583 # Param 2 - File to write to |
|
584 # Use printf to get consistent behavior on all platforms. |
|
585 WriteFile = \ |
|
586 $(shell $(PRINTF) "%s" $(call ShellQuote, $1) > $2) |
|
587 |
|
588 ################################################################################ |
|
589 # DependOnVariable |
|
590 # |
|
591 # This macro takes a variable name and puts the value in a file only if the |
|
592 # value has changed since last. The name of the file is returned. This can be |
|
593 # used to create rule dependencies on make variable values. The following |
|
594 # example would get rebuilt if the value of SOME_VAR was changed: |
|
595 # |
|
596 # path/to/some-file: $(call DependOnVariable, SOME_VAR) |
|
597 # echo $(SOME_VAR) > $@ |
|
598 # |
|
599 # Note that leading and trailing white space in the value is ignored. |
|
600 # |
|
601 |
|
602 # Defines the sub directory structure to store variable value file in |
|
603 DependOnVariableDirName = \ |
|
604 $(strip $(subst $(SRC_ROOT)/,,\ |
|
605 $(if $(filter /%, $(firstword $(MAKEFILE_LIST))), \ |
|
606 $(firstword $(MAKEFILE_LIST)), \ |
|
607 $(CURDIR)/$(firstword $(MAKEFILE_LIST))))) |
|
608 |
|
609 # Defines the name of the file to store variable value in. Generates a name |
|
610 # unless parameter 2 is given. |
|
611 # Param 1 - Name of variable |
|
612 # Param 2 - (optional) name of file to store value in |
|
613 DependOnVariableFileName = \ |
|
614 $(strip $(if $(strip $2), $2, \ |
|
615 $(MAKESUPPORT_OUTPUTDIR)/vardeps/$(DependOnVariableDirName)/$(strip $1).vardeps)) |
|
616 |
|
617 # Does the actual work with parameters stripped. |
|
618 # If the file exists AND the contents is the same as the variable, do nothing |
|
619 # else print a new file. |
|
620 # Always returns the name of the file where the value was printed. |
|
621 # Param 1 - Name of variable |
|
622 # Param 2 - (optional) name of file to store value in |
|
623 DependOnVariableHelper = \ |
|
624 $(strip $(if $(and $(wildcard $(call DependOnVariableFileName, $1, $2)),\ |
|
625 $(call equals, $(strip $($1)), \ |
|
626 $(call ReadFile, $(call DependOnVariableFileName, $1, $2)))),,\ |
|
627 $(call MakeDir, $(dir $(call DependOnVariableFileName, $1, $2))) \ |
|
628 $(if $(findstring $(LOG_LEVEL), trace), \ |
|
629 $(info Variable $1: $(strip $($1))) \ |
|
630 $(info File: $(call ReadFile, $(call DependOnVariableFileName, $1, $2)))) \ |
|
631 $(call WriteFile, $($1), $(call DependOnVariableFileName, $1, $2))) \ |
|
632 $(call DependOnVariableFileName, $1, $2)) |
|
633 |
|
634 # Main macro |
|
635 # Param 1 - Name of variable |
|
636 # Param 2 - (optional) name of file to store value in |
|
637 DependOnVariable = \ |
|
638 $(call DependOnVariableHelper,$(strip $1),$(strip $2)) |
|
639 |
|
640 ################################################################################ |
566 |
641 |
567 # Hook to include the corresponding custom file, if present. |
642 # Hook to include the corresponding custom file, if present. |
568 $(eval $(call IncludeCustomExtension, , common/MakeBase.gmk)) |
643 $(eval $(call IncludeCustomExtension, , common/MakeBase.gmk)) |
569 |
644 |
570 endif # _MAKEBASE_GMK |
645 endif # _MAKEBASE_GMK |