node_any: check attribute presence
[protos/libecoli.git] / mk / ecoli-objcopy-vars.mk
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2015, Olivier MATZ <zer0@droids-corp.org>
3
4 # objcopy changes the format of a binary
5 # objcopy-hex-y-$(objcopy), objcopy-bin-y-$(objcopy) are provided by the user
6 #   $(objcopy) is the path of the binary, and the variable contains
7 #   the path to the elf. Several objcopy-y-$(objcopy) can be present.
8
9 # list all executable builds requested by user
10 all-objcopy-hex := $(patsubst objcopy-hex-y-%,%,$(filter objcopy-hex-y-%,$(.VARIABLES)))
11 all-objcopy-bin := $(patsubst objcopy-bin-y-%,%,$(filter objcopy-bin-y-%,$(.VARIABLES)))
12
13 # add them to the list of targets
14 all-targets += $(all-objcopy-hex) $(all-objcopy-bin)
15
16 # for each objcopy, create the following variables:
17 #   out-$(objcopy) = output path of the executable
18 #   pre-$(objcopy) = list of prerequisites for this executable
19 # We also add the generated files in $(all-clean-file).
20 $(foreach objcopy,$(all-objcopy-hex),\
21         $(if $(call compare,$(words $(objcopy-hex-y-$(objcopy))),1),\
22                 $(error "only one source file is allowed in objcopy-hex-y-$(objcopy)")) \
23         $(eval out-$(objcopy) := $(dir $(objcopy))) \
24         $(eval pre-$(objcopy) := $(objcopy-hex-y-$(objcopy))) \
25         $(eval all-clean-file += $(objcopy)) \
26 )
27
28 # for each objcopy, create the following variables:
29 #   out-$(objcopy) = output path of the executable
30 #   pre-$(objcopy) = list of prerequisites for this executable
31 # We also add the generated files in $(all-clean-file).
32 $(foreach objcopy,$(all-objcopy-bin),\
33         $(if $(call compare,$(words $(objcopy-bin-y-$(objcopy))),1),\
34                 $(error "only one source file is allowed in objcopy-bin-y-$(objcopy)")) \
35         $(eval out-$(objcopy) := $(dir $(objcopy))) \
36         $(eval pre-$(objcopy) := $(objcopy-bin-y-$(objcopy))) \
37         $(eval all-clean-file += $(objcopy)) \
38 )
39
40 # convert format of executable from elf to ihex
41 #   $1: source executable (elf)
42 #   $2: destination file
43 objcopy_hex_cmd = $(OBJCOPY) -O ihex $(1) $(2)
44
45 # print line used to convert executable format
46 ifeq ($(V),1)
47 objcopy_print_cmd = echo $(call protect_quote,$(call objcopy_hex_cmd,$1,$2))
48 else
49 objcopy_print_cmd = echo "  OBJCOPY $(2)"
50 endif
51
52 # convert format of executable from elf to binary
53 #   $1: source executable (elf)
54 #   $2: destination file
55 objcopy_bin_cmd = $(OBJCOPY) -O binary $(1) $(2)
56
57 # print line used to convert executable format
58 ifeq ($(V),1)
59 objcopy_print_cmd = echo $(call protect_quote,$(call objcopy_bin_cmd,$1,$2))
60 else
61 objcopy_print_cmd = echo "  OBJCOPY $(2)"
62 endif
63
64 # XXX dup ?
65 all-clean-file += $(all-objcopy-hex) $(all-objcopy-bin)