1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2015, Olivier MATZ <zer0@droids-corp.org>
5 # copy-y-$(copy) is provided by the user
6 # $(copy) is the path of the directory containing the destination
7 # files, and the variable contains the path of the files to copy. Several
8 # copy-y-$(copy) can be present.
10 # list all path requested by user
11 _all-copy := $(patsubst copy-y-%,%,$(filter copy-y-%,$(.VARIABLES)))
14 # for each copy, create the following variables:
15 # out-$(copy) = output path of the executable
16 # pre-$(copy) = list of prerequisites for this executable
17 # We also add the files in $(all-copy).
18 $(foreach copy,$(_all-copy),\
19 $(if $(notdir $(copy)), \
20 $(if $(call compare,$(words $(copy-y-$(copy))),1), \
21 $(error "only one source file is allowed in copy-y-$(copy)")) \
22 $(eval dst := $(dir $(copy))$(notdir $(copy-y-$(copy)))) \
23 $(eval out-$(copy) := $(dir $(copy))) \
24 $(eval pre-$(copy) := $(copy-y-$(copy))) \
25 $(eval all-copy += $(dst)) \
27 $(foreach src,$(copy-y-$(copy)),\
28 $(eval dst := $(copy)$(notdir $(src))) \
29 $(eval out-$(copy) := $(copy)) \
30 $(eval pre-$(dst) := $(src)) \
31 $(eval all-copy += $(dst)) \
36 # add them to the list of targets and clean
37 all-targets += $(all-copy)
38 all-clean-file += $(all-copy)
40 # convert format of executable from elf to ihex
41 # $1: source executable (elf)
42 # $2: destination file
43 copy_cmd = $(CP) $(1) $(2)
45 # print line used to convert executable format
47 copy_print_cmd = echo $(call protect_quote,$(call copy_cmd,$1,$2))
49 copy_print_cmd = echo " COPY $(2)"