make/common/MakeBase.gmk

changeset 2223
01cc48ed67f3
parent 912
a667caba1e84
child 2316
64a3eeabf6e5
child 2422
84adf64edebb
     1.1 --- a/make/common/MakeBase.gmk	Fri May 04 11:00:26 2018 +0100
     1.2 +++ b/make/common/MakeBase.gmk	Wed May 16 15:52:51 2018 -0700
     1.3 @@ -446,4 +446,51 @@
     1.4  
     1.5  ################################################################################
     1.6  
     1.7 +define AddFileToCopy
     1.8 +  # Helper macro for SetupCopyFiles
     1.9 +  # 1 : Source file
    1.10 +  # 2 : Dest file
    1.11 +  # 3 : Variable to add targets to
    1.12 +  # 4 : Macro to call for copy operation
    1.13 +  $2: $1
    1.14 +	$(ECHO) $(LOG_INFO) Copying $$(patsubst $(OUTPUT_ROOT)/%,%,$$@)
    1.15 +	$$($$(strip $4))
    1.16 +
    1.17 +  $3 += $2
    1.18 +endef
    1.19 +
    1.20 +define SetupCopyFiles
    1.21 +  # param 1 is for example COPY_MYFILES
    1.22 +  # param 2,3,4,5 are named args.
    1.23 +  #   SRC     : Source root dir (defaults to dir of first file)
    1.24 +  #   DEST    : Dest root dir
    1.25 +  #   FILES   : List of files to copy with absolute paths, or path relative to SRC.
    1.26 +  #             Must be in SRC.
    1.27 +  #   FLATTEN : Set to flatten the directory structure in the DEST dir.
    1.28 +  #   MACRO   : Optionally override the default macro used for making the copy.
    1.29 +  #             Default is 'install-file'
    1.30 +  $(foreach i,2 3 4 5 6, $(if $($i),$1_$(strip $($i)))$(NEWLINE))
    1.31 +  $(call LogSetupMacroEntry,SetupCopyFiles($1),$2,$3,$4,$5,$6)
    1.32 +  $(if $(7),$(error Internal makefile error: Too many arguments to SetupCopyFiles))
    1.33 +
    1.34 +  ifeq ($$($1_MACRO), )
    1.35 +    $1_MACRO := install-file
    1.36 +  endif
    1.37 +
    1.38 +  # Default SRC to the dir of the first file.
    1.39 +  ifeq ($$($1_SRC), )
    1.40 +    $1_SRC := $$(dir $$(firstword $$($1_FILES)))
    1.41 +  endif
    1.42 +
    1.43 +  # Remove any trailing slash from SRC
    1.44 +  $1_SRC := $$(patsubst %/,%,$$($1_SRC))
    1.45 +
    1.46 +  $$(foreach f, $$(patsubst $$($1_SRC)/%,%,$$($1_FILES)), \
    1.47 +      $$(eval $$(call AddFileToCopy, $$($1_SRC)/$$f, \
    1.48 +      $$($1_DEST)/$$(if $$($1_FLATTEN),$$(notdir $$f),$$f), $1, $$($1_MACRO))))
    1.49 +
    1.50 +endef
    1.51 +
    1.52 +################################################################################
    1.53 +
    1.54  endif # _MAKEBASE_GMK

mercurial