< prev index next >

make/common/MakeBase.gmk

Print this page




 241     $(strip \
 242         $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, \
 243           $(if $(findstring ?, $d), '$(call DecodeSpace, $d)', \
 244             $(if $(wildcard $d), , $d) \
 245           ) \
 246         ))) \
 247         $(if $(MakeDir_dirs_to_make), $(shell $(MKDIR) -p $(MakeDir_dirs_to_make))) \
 248     )
 249 
 250 # Make directory for target file. Should handle spaces in filenames. Just
 251 # calling $(call MakeDir $(@D)) will not work if the directory contains a space
 252 # and the target file already exists. In that case, the target file will have
 253 # its wildcard ? resolved and the $(@D) will evaluate each space separated dir
 254 # part on its own.
 255 MakeTargetDir = \
 256     $(call MakeDir, $(dir $(call EncodeSpace, $@)))
 257 
 258 ################################################################################
 259 # All install-file and related macros automatically call DecodeSpace when needed.
 260 
 261 ifeq ($(OPENJDK_TARGET_OS),solaris)
 262   # On Solaris, if the target is a symlink and exists, cp won't overwrite.
 263   # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the
 264   # name of the target file differs from the source file, rename after copy.
 265   # If the source and target parent directories are the same, recursive copy doesn't work
 266   # so we fall back on regular copy, which isn't preserving symlinks.
 267   define install-file
 268         $(call MakeTargetDir)
 269         $(RM) '$(call DecodeSpace, $@)'
 270         if [ '$(call DecodeSpace, $(dir $(call EncodeSpace, $@)))' != \
 271             '$(call DecodeSpace, $(dir $(call EncodeSpace, $<)))' ]; then \
 272           $(CP) -f -r -P '$(call DecodeSpace, $<)' \
 273               '$(call DecodeSpace, $(dir $(call EncodeSpace, $@)))'; \
 274           if [ '$(call DecodeSpace, $(notdir $(call EncodeSpace, $@)))' != \
 275               '$(call DecodeSpace, $(notdir $(call EncodeSpace, $(<))))' ]; then \
 276             $(MV) '$(call DecodeSpace, $(dir $(call EncodeSpace, $@))/$(notdir $(call EncodeSpace, $<)))' \
 277                 '$(call DecodeSpace, $@)'; \
 278           fi; \
 279         else \
 280           if [ -L '$(call DecodeSpace, $<)' ]; then \
 281             $(ECHO) "Source file is a symlink and target is in the same directory: $< $@" ; \
 282             exit 1; \
 283           fi; \
 284           $(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \
 285         fi
 286   endef
 287 else ifeq ($(OPENJDK_TARGET_OS),macosx)
 288   # On mac, extended attributes sometimes creep into the source files, which may later
 289   # cause the creation of ._* files which confuses testing. Clear these with xattr if
 290   # set. Some files get their write permissions removed after being copied to the
 291   # output dir. When these are copied again to images, xattr would fail. By only clearing
 292   # attributes when they are present, failing on this is avoided.
 293   #
 294   # If copying a soft link to a directory, need to delete the target first to avoid
 295   # weird errors.
 296   define install-file
 297         $(call MakeTargetDir)
 298         $(RM) '$(call DecodeSpace, $@)'
 299         # Work around a weirdness with cp on Macosx. When copying a symlink, if
 300         # the target of the link is write protected (e.g. 444), cp will add
 301         # write permission for the user on the target file (644). Avoid this by
 302         # using ln to create a new link instead.
 303         if [ -h '$(call DecodeSpace, $<)' ]; then \
 304           $(LN) -s "`$(READLINK) '$(call DecodeSpace, $<)'`" '$(call DecodeSpace, $@)'; \
 305         else \
 306           $(CP) -fRP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \
 307         fi


 401 
 402 else
 403   # If CacheFind is disabled, just run the find command.
 404   # Param 1 - Dirs to find in
 405   # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression.
 406   define CacheFind
 407     $(if $(wildcard $1, \
 408       $(shell $(FIND) $(wildcard $1) \( -type f -o -type l \) $2 | $(TR) ' ' '?') \
 409     )
 410   endef
 411 endif
 412 
 413 ################################################################################
 414 # FixPath
 415 #
 416 # On Windows, converts a path from cygwin/unix style (e.g. /bin/foo) into
 417 # "mixed mode" (e.g. c:/cygwin/bin/foo). On other platforms, return the path
 418 # unchanged.
 419 # This is normally not needed since we use the FIXPATH prefix for command lines,
 420 # but might be needed in certain circumstances.
 421 ifeq ($(OPENJDK_TARGET_OS), windows)
 422   FixPath = \
 423       $(shell $(CYGPATH) -m $1)
 424 else
 425   FixPath = \
 426       $1
 427 endif
 428 
 429 ################################################################################
 430 # DependOnVariable
 431 #
 432 # This macro takes a variable name and puts the value in a file only if the
 433 # value has changed since last. The name of the file is returned. This can be
 434 # used to create rule dependencies on make variable values. The following
 435 # example would get rebuilt if the value of SOME_VAR was changed:
 436 #
 437 # path/to/some-file: $(call DependOnVariable, SOME_VAR)
 438 #         echo $(SOME_VAR) > $@
 439 #
 440 # Note that leading and trailing white space in the value is ignored.
 441 #




 241     $(strip \
 242         $(eval MakeDir_dirs_to_make := $(strip $(foreach d, $1, \
 243           $(if $(findstring ?, $d), '$(call DecodeSpace, $d)', \
 244             $(if $(wildcard $d), , $d) \
 245           ) \
 246         ))) \
 247         $(if $(MakeDir_dirs_to_make), $(shell $(MKDIR) -p $(MakeDir_dirs_to_make))) \
 248     )
 249 
 250 # Make directory for target file. Should handle spaces in filenames. Just
 251 # calling $(call MakeDir $(@D)) will not work if the directory contains a space
 252 # and the target file already exists. In that case, the target file will have
 253 # its wildcard ? resolved and the $(@D) will evaluate each space separated dir
 254 # part on its own.
 255 MakeTargetDir = \
 256     $(call MakeDir, $(dir $(call EncodeSpace, $@)))
 257 
 258 ################################################################################
 259 # All install-file and related macros automatically call DecodeSpace when needed.
 260 
 261 ifeq ($(call isTargetOs, solaris), true)
 262   # On Solaris, if the target is a symlink and exists, cp won't overwrite.
 263   # Cp has to operate in recursive mode to allow for -P flag, to preserve soft links. If the
 264   # name of the target file differs from the source file, rename after copy.
 265   # If the source and target parent directories are the same, recursive copy doesn't work
 266   # so we fall back on regular copy, which isn't preserving symlinks.
 267   define install-file
 268         $(call MakeTargetDir)
 269         $(RM) '$(call DecodeSpace, $@)'
 270         if [ '$(call DecodeSpace, $(dir $(call EncodeSpace, $@)))' != \
 271             '$(call DecodeSpace, $(dir $(call EncodeSpace, $<)))' ]; then \
 272           $(CP) -f -r -P '$(call DecodeSpace, $<)' \
 273               '$(call DecodeSpace, $(dir $(call EncodeSpace, $@)))'; \
 274           if [ '$(call DecodeSpace, $(notdir $(call EncodeSpace, $@)))' != \
 275               '$(call DecodeSpace, $(notdir $(call EncodeSpace, $(<))))' ]; then \
 276             $(MV) '$(call DecodeSpace, $(dir $(call EncodeSpace, $@))/$(notdir $(call EncodeSpace, $<)))' \
 277                 '$(call DecodeSpace, $@)'; \
 278           fi; \
 279         else \
 280           if [ -L '$(call DecodeSpace, $<)' ]; then \
 281             $(ECHO) "Source file is a symlink and target is in the same directory: $< $@" ; \
 282             exit 1; \
 283           fi; \
 284           $(CP) -f '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \
 285         fi
 286   endef
 287 else ifeq ($(call isTargetOs, macosx), true)
 288   # On mac, extended attributes sometimes creep into the source files, which may later
 289   # cause the creation of ._* files which confuses testing. Clear these with xattr if
 290   # set. Some files get their write permissions removed after being copied to the
 291   # output dir. When these are copied again to images, xattr would fail. By only clearing
 292   # attributes when they are present, failing on this is avoided.
 293   #
 294   # If copying a soft link to a directory, need to delete the target first to avoid
 295   # weird errors.
 296   define install-file
 297         $(call MakeTargetDir)
 298         $(RM) '$(call DecodeSpace, $@)'
 299         # Work around a weirdness with cp on Macosx. When copying a symlink, if
 300         # the target of the link is write protected (e.g. 444), cp will add
 301         # write permission for the user on the target file (644). Avoid this by
 302         # using ln to create a new link instead.
 303         if [ -h '$(call DecodeSpace, $<)' ]; then \
 304           $(LN) -s "`$(READLINK) '$(call DecodeSpace, $<)'`" '$(call DecodeSpace, $@)'; \
 305         else \
 306           $(CP) -fRP '$(call DecodeSpace, $<)' '$(call DecodeSpace, $@)'; \
 307         fi


 401 
 402 else
 403   # If CacheFind is disabled, just run the find command.
 404   # Param 1 - Dirs to find in
 405   # Param 2 - (optional) specialization. Normally "-a \( ... \)" expression.
 406   define CacheFind
 407     $(if $(wildcard $1, \
 408       $(shell $(FIND) $(wildcard $1) \( -type f -o -type l \) $2 | $(TR) ' ' '?') \
 409     )
 410   endef
 411 endif
 412 
 413 ################################################################################
 414 # FixPath
 415 #
 416 # On Windows, converts a path from cygwin/unix style (e.g. /bin/foo) into
 417 # "mixed mode" (e.g. c:/cygwin/bin/foo). On other platforms, return the path
 418 # unchanged.
 419 # This is normally not needed since we use the FIXPATH prefix for command lines,
 420 # but might be needed in certain circumstances.
 421 ifeq ($(call isTargetOs, windows), true)
 422   FixPath = \
 423       $(shell $(CYGPATH) -m $1)
 424 else
 425   FixPath = \
 426       $1
 427 endif
 428 
 429 ################################################################################
 430 # DependOnVariable
 431 #
 432 # This macro takes a variable name and puts the value in a file only if the
 433 # value has changed since last. The name of the file is returned. This can be
 434 # used to create rule dependencies on make variable values. The following
 435 # example would get rebuilt if the value of SOME_VAR was changed:
 436 #
 437 # path/to/some-file: $(call DependOnVariable, SOME_VAR)
 438 #         echo $(SOME_VAR) > $@
 439 #
 440 # Note that leading and trailing white space in the value is ignored.
 441 #


< prev index next >