third_party:waf: update to upstream 2.0.4 release
[nivanova/samba-autobuild/.git] / third_party / waf / waflib / extras / objcopy.py
1 #! /usr/bin/env python
2 # encoding: utf-8
3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
4
5 #!/usr/bin/python
6 # Grygoriy Fuchedzhy 2010
7
8 """
9 Support for converting linked targets to ihex, srec or binary files using
10 objcopy. Use the 'objcopy' feature in conjunction with the 'cc' or 'cxx'
11 feature. The 'objcopy' feature uses the following attributes:
12
13 objcopy_bfdname         Target object format name (eg. ihex, srec, binary).
14                                            Defaults to ihex.
15 objcopy_target           File name used for objcopy output. This defaults to the
16                                            target name with objcopy_bfdname as extension.
17 objcopy_install_path   Install path for objcopy_target file. Defaults to ${PREFIX}/fw.
18 objcopy_flags             Additional flags passed to objcopy.
19 """
20
21 from waflib.Utils import def_attrs
22 from waflib import Task
23 from waflib.TaskGen import feature, after_method
24
25 class objcopy(Task.Task):
26         run_str = '${OBJCOPY} -O ${TARGET_BFDNAME} ${OBJCOPYFLAGS} ${SRC} ${TGT}'
27         color   = 'CYAN'
28
29 @feature('objcopy')
30 @after_method('apply_link')
31 def map_objcopy(self):
32         def_attrs(self,
33            objcopy_bfdname = 'ihex',
34            objcopy_target = None,
35            objcopy_install_path = "${PREFIX}/firmware",
36            objcopy_flags = '')
37
38         link_output = self.link_task.outputs[0]
39         if not self.objcopy_target:
40                 self.objcopy_target = link_output.change_ext('.' + self.objcopy_bfdname).name
41         task = self.create_task('objcopy', src=link_output, tgt=self.path.find_or_declare(self.objcopy_target))
42
43         task.env.append_unique('TARGET_BFDNAME', self.objcopy_bfdname)
44         try:
45                 task.env.append_unique('OBJCOPYFLAGS', getattr(self, 'objcopy_flags'))
46         except AttributeError:
47                 pass
48
49         if self.objcopy_install_path:
50                 self.add_install_files(install_to=self.objcopy_install_path, install_from=task.outputs[0])
51
52 def configure(ctx):
53         ctx.find_program('objcopy', var='OBJCOPY', mandatory=True)
54