2 # Copyright 2015, Olivier MATZ <zer0@droids-corp.org>
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 # * Neither the name of the University of California, Berkeley nor the
13 # names of its contributors may be used to endorse or promote products
14 # derived from this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 # DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 # objcopy changes the format of a binary
29 # objcopy-hex-y-$(objcopy), objcopy-bin-y-$(objcopy) are provided by the user
30 # $(objcopy) is the path of the binary, and the variable contains
31 # the path to the elf. Several objcopy-y-$(objcopy) can be present.
33 # list all executable builds requested by user
34 all-objcopy-hex := $(patsubst objcopy-hex-y-%,%,$(filter objcopy-hex-y-%,$(.VARIABLES)))
35 all-objcopy-bin := $(patsubst objcopy-bin-y-%,%,$(filter objcopy-bin-y-%,$(.VARIABLES)))
37 # add them to the list of targets
38 all-targets += $(all-objcopy-hex) $(all-objcopy-bin)
40 # for each objcopy, create the following variables:
41 # out-$(objcopy) = output path of the executable
42 # pre-$(objcopy) = list of prerequisites for this executable
43 # We also add the generated files in $(all-clean-file).
44 $(foreach objcopy,$(all-objcopy-hex),\
45 $(if $(call compare,$(words $(objcopy-hex-y-$(objcopy))),1),\
46 $(error "only one source file is allowed in objcopy-hex-y-$(objcopy)")) \
47 $(eval out-$(objcopy) := $(dir $(objcopy))) \
48 $(eval pre-$(objcopy) := $(objcopy-hex-y-$(objcopy))) \
49 $(eval all-clean-file += $(objcopy)) \
52 # for each objcopy, create the following variables:
53 # out-$(objcopy) = output path of the executable
54 # pre-$(objcopy) = list of prerequisites for this executable
55 # We also add the generated files in $(all-clean-file).
56 $(foreach objcopy,$(all-objcopy-bin),\
57 $(if $(call compare,$(words $(objcopy-bin-y-$(objcopy))),1),\
58 $(error "only one source file is allowed in objcopy-bin-y-$(objcopy)")) \
59 $(eval out-$(objcopy) := $(dir $(objcopy))) \
60 $(eval pre-$(objcopy) := $(objcopy-bin-y-$(objcopy))) \
61 $(eval all-clean-file += $(objcopy)) \
64 # convert format of executable from elf to ihex
65 # $1: source executable (elf)
66 # $2: destination file
67 objcopy_hex_cmd = $(OBJCOPY) -O ihex $(1) $(2)
69 # print line used to convert executable format
71 objcopy_print_cmd = echo $(call protect_quote,$(call objcopy_hex_cmd,$1,$2))
73 objcopy_print_cmd = echo " OBJCOPY $(2)"
76 # convert format of executable from elf to binary
77 # $1: source executable (elf)
78 # $2: destination file
79 objcopy_bin_cmd = $(OBJCOPY) -O binary $(1) $(2)
81 # print line used to convert executable format
83 objcopy_print_cmd = echo $(call protect_quote,$(call objcopy_bin_cmd,$1,$2))
85 objcopy_print_cmd = echo " OBJCOPY $(2)"
89 all-clean-file += $(all-objcopy-hex) $(all-objcopy-bin)