source: rtems-tools/rtemstoolkit/wscript @ 558cab8

5
Last change on this file since 558cab8 was 558cab8, checked in by Chris Johns <chrisj@…>, on 05/08/18 at 05:09:38

rtemstoolkit: Add libdwarf C++ interface.

Provide a C++ interface to libdwarf to:

  • Manage DWARF debug data
  • Manage CU
  • Manage DIE
  • Handle CU line addresses
  • Handle CU source files

Update #3417

  • Property mode set to 100644
File size: 14.8 KB
RevLine 
[0382b68]1#
2# RTEMS Tools Project (http://www.rtems.org/)
[771e7f1]3# Copyright 2014-2018 Chris Johns (chrisj@rtems.org)
[0382b68]4# All rights reserved.
5#
6# This file is part of the RTEMS Tools package in 'rtems-tools'.
7#
[635a28f]8# Permission to use, copy, modify, and/or distribute this software for any
9# purpose with or without fee is hereby granted, provided that the above
10# copyright notice and this permission notice appear in all copies.
[0382b68]11#
[635a28f]12# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
[0382b68]19#
20
[87e0e76]21#
22# RTEMS Toolkit build script.
23#
24import sys
25
26#
27# Waf system setup. Allow more than one build in the same tree.
28#
29top = '.'
30out = 'build-' + sys.platform
31
[7148cae]32def init(ctx):
33    pass
34
[87e0e76]35def options(opt):
[b7d48ef]36    opt.load('compiler_c')
37    opt.load('compiler_cxx')
[87e0e76]38
39def configure(conf):
[b7d48ef]40    conf.load('compiler_c')
41    conf.load('compiler_cxx')
[87e0e76]42    conf_libiberty(conf)
[771e7f1]43    conf_elftoolchain(conf)
[87e0e76]44
[0382b68]45    conf.find_program('m4')
46
[de1beea]47    conf.check(header_name = 'sys/wait.h',  features = 'c', mandatory = False)
48    conf.check_cc(function_name = 'kill', header_name="signal.h",
[87e0e76]49                  features = 'c', mandatory = False)
50    conf.write_config_header('config.h')
51
52def build(bld):
53    #
54    # The local configuration.
55    #
56    conf = {}
57
58    #
59    # The include paths.
60    #
[771e7f1]61    conf['includes'] = ['elftoolchain/libelf',
[4bb3996]62                        'elftoolchain/libdwarf',
[771e7f1]63                        'elftoolchain/common',
64                        'libiberty']
[3badbb0]65    if bld.env.DEST_OS == 'win32':
[87e0e76]66        conf['includes'] += ['win32']
67
68    #
69    # Build flags.
70    #
71    conf['warningflags'] = ['-Wall', '-Wextra', '-pedantic']
72    conf['optflags'] = bld.env.C_OPTS
[558cab8]73    conf['cflags'] = list(set(['-pipe', '-g'] + conf['optflags']))
74    conf['cxxflags'] = list(set(['-pipe', '-g', '-std=c++11'] + conf['optflags']))
[87e0e76]75    conf['linkflags'] = ['-g']
76
77    #
78    # Create each of the modules as object files each with their own
79    # configurations.
80    #
[771e7f1]81    bld_elftoolchain(bld, conf)
[87e0e76]82    bld_libiberty(bld, conf)
83
84    #
85    # RLD source.
86    #
87    rld_source = ['ConvertUTF.c',
88                  'pkgconfig.cpp',
[635a28f]89                  'rld-buffer.cpp',
90                  'rld-cc.cpp',
91                  'rld-compression.cpp',
[87e0e76]92                  'rld-config.cpp',
[558cab8]93                  'rld-dwarf.cpp',
[87e0e76]94                  'rld-elf.cpp',
95                  'rld-files.cpp',
96                  'rld-outputter.cpp',
97                  'rld-path.cpp',
98                  'rld-process.cpp',
[635a28f]99                  'rld-rap.cpp',
[87e0e76]100                  'rld-resolver.cpp',
101                  'rld-rtems.cpp',
102                  'rld-symbols.cpp',
103                  'rld.cpp']
104
105    #
106    # RTEMS Utilities.
107    #
108    rtems_utils = ['rtems-utils.cpp']
109
[435d879]110    #
111    # Compression.
112    #
113    compression = ['fastlz.c']
114
[87e0e76]115    #
116    # RTL static library
117    #
118    bld.stlib(target = 'rld',
119              install_path = None,
[435d879]120              source = rld_source + rtems_utils + compression,
121              defines = ['HAVE_CONFIG_H=1',
[efc4f09]122                         'RTEMS_VERSION=\"%s\"' % (bld.env.RTEMS_VERSION),
123                         'RTEMS_RELEASE=\"%s\"' % (bld.env.RTEMS_RELEASE),
[435d879]124                         'FASTLZ_LEVEL=1'],
[87e0e76]125              includes = ['.'] + conf['includes'],
126              cflags = conf['cflags'] + conf['warningflags'],
127              cxxflags = conf['cxxflags'] + conf['warningflags'],
128              linkflags = conf['linkflags'])
129
[b7d48ef]130    #
131    # The Python toolkit.
132    #
133    bld(features = 'py',
134        source = ['__init__.py',
135                  'check.py',
136                  'config.py',
[ed80d2c]137                  'configuration.py',
[b7d48ef]138                  'darwin.py',
139                  'error.py',
140                  'execute.py',
141                  'freebsd.py',
142                  'git.py',
[224fb21]143                  'host.py',
[b7d48ef]144                  'linux.py',
145                  'log.py',
146                  'macros.py',
147                  'mailer.py',
148                  'options.py',
149                  'path.py',
[5df7c3c]150                  'reraise.py',
[b7d48ef]151                  'stacktraces.py',
[224fb21]152                  'textbox.py',
[b7d48ef]153                  'version.py',
154                  'windows.py'],
[a6f5f18]155        install_from = '.',
156        install_path = '${PREFIX}/share/rtems/rtemstoolkit')
[b7d48ef]157
[87e0e76]158def rebuild(ctx):
159    import waflib.Options
160    waflib.Options.commands.extend(['clean', 'build'])
161
162def tags(ctx):
163    ctx.exec_command('etags $(find . -name \*.[sSch])', shell = True)
164
165#
166# Libelf module.
167#
[771e7f1]168def conf_elftoolchain(conf):
[87e0e76]169    pass
170
[771e7f1]171def bld_elftoolchain(bld, conf):
[87e0e76]172    libelf = 'elftoolchain/libelf/'
[4bb3996]173    libdwarf = 'elftoolchain/libdwarf/'
[771e7f1]174    libelf_m4_rule = '${M4} -D SRCDIR=../rtemstoolkit/' + libelf[:-1] + ' ${SRC} > ${TGT}'
[4bb3996]175    libdwarf_m4_rule = '${M4} -D SRCDIR=../rtemstoolkit/' + libdwarf[:-1] + ' ${SRC} > ${TGT}'
[3badbb0]176    if bld.env.DEST_OS == 'win32':
177        includes = ['win32']
178    else:
[87e0e76]179        includes = []
180
[771e7f1]181    libelf_m4_source = ['libelf_convert.c',
182                        'libelf_fsize.c',
183                        'libelf_msize.c']
184    for s in libelf_m4_source:
185        bld(target = s, source = libelf + s[:-2] + '.m4', rule = libelf_m4_rule)
[87e0e76]186
187    host_source = []
188
[69c955d]189    if bld.env.DEST_OS == 'linux':
[87e0e76]190        common = 'elftoolchain/common/'
191        bld(target = common + 'native-elf-format.h',
192            source = common + 'native-elf-format',
193            name = 'native-elf-format',
194            rule   = './${SRC} > ${TGT}')
195        bld.add_group ()
[3badbb0]196    elif bld.env.DEST_OS == 'win32':
[87e0e76]197        host_source += [libelf + 'mmap_win32.c']
198
199    bld.stlib(target = 'elf',
200              features = 'c',
201              install_path = None,
202              uses = ['native-elf-format'],
[3badbb0]203              includes = [bld.bldnode.abspath(),
204                          'elftoolchain/libelf', 'elftoolchain/common'] + includes,
[87e0e76]205              cflags = conf['cflags'],
206              source =[libelf + 'elf.c',
207                       libelf + 'elf_begin.c',
208                       libelf + 'elf_cntl.c',
209                       libelf + 'elf_end.c',
210                       libelf + 'elf_errmsg.c',
211                       libelf + 'elf_errno.c',
212                       libelf + 'elf_data.c',
213                       libelf + 'elf_fill.c',
214                       libelf + 'elf_flag.c',
215                       libelf + 'elf_getarhdr.c',
216                       libelf + 'elf_getarsym.c',
217                       libelf + 'elf_getbase.c',
218                       libelf + 'elf_getident.c',
219                       libelf + 'elf_hash.c',
220                       libelf + 'elf_kind.c',
221                       libelf + 'elf_memory.c',
222                       libelf + 'elf_next.c',
[771e7f1]223                       libelf + 'elf_open.c',
[87e0e76]224                       libelf + 'elf_rand.c',
225                       libelf + 'elf_rawfile.c',
226                       libelf + 'elf_phnum.c',
227                       libelf + 'elf_shnum.c',
228                       libelf + 'elf_shstrndx.c',
229                       libelf + 'elf_scn.c',
230                       libelf + 'elf_strptr.c',
231                       libelf + 'elf_update.c',
232                       libelf + 'elf_version.c',
233                       libelf + 'gelf_cap.c',
234                       libelf + 'gelf_checksum.c',
235                       libelf + 'gelf_dyn.c',
236                       libelf + 'gelf_ehdr.c',
237                       libelf + 'gelf_getclass.c',
238                       libelf + 'gelf_fsize.c',
239                       libelf + 'gelf_move.c',
240                       libelf + 'gelf_phdr.c',
241                       libelf + 'gelf_rel.c',
242                       libelf + 'gelf_rela.c',
243                       libelf + 'gelf_shdr.c',
244                       libelf + 'gelf_sym.c',
245                       libelf + 'gelf_syminfo.c',
246                       libelf + 'gelf_symshndx.c',
247                       libelf + 'gelf_xlate.c',
248                       libelf + 'libelf_align.c',
249                       libelf + 'libelf_allocate.c',
250                       libelf + 'libelf_ar.c',
251                       libelf + 'libelf_ar_util.c',
252                       libelf + 'libelf_checksum.c',
253                       libelf + 'libelf_data.c',
254                       libelf + 'libelf_ehdr.c',
255                       libelf + 'libelf_extended.c',
[771e7f1]256                       libelf + 'libelf_memory.c',
257                       libelf + 'libelf_open.c',
[87e0e76]258                       libelf + 'libelf_phdr.c',
259                       libelf + 'libelf_shdr.c',
[771e7f1]260                       libelf + 'libelf_xlate.c'] + libelf_m4_source + host_source)
[87e0e76]261
[4bb3996]262    libdwarf_m4_source = ['dwarf_funcs.c',
263                          'dwarf_pro_funcs.c',
264                          'dwarf_pro_pubnames.c',
265                          'dwarf_pro_types.c',
266                          'dwarf_pro_vars.c',
267                          'dwarf_pro_weaks.c',
268                          'dwarf_pubnames.c',
269                          'dwarf_pubtypes.c',
270                          'dwarf_types.c',
271                          'dwarf_vars.c',
272                          'dwarf_weaks.c']
273    for s in libdwarf_m4_source:
274        bld(target = s, source = libdwarf + s[:-2] + '.m4', rule = libdwarf_m4_rule)
275
276    bld.stlib(target = 'dwarf',
277              features = 'c',
278              install_path = None,
279              includes = [bld.bldnode.abspath(),
280                          'elftoolchain/libelf',
281                          'elftoolchain/libdwarf',
282                          'elftoolchain/common'] + includes,
283              cflags = conf['cflags'],
284              source =[libdwarf + 'dwarf_abbrev.c',
285                       libdwarf + 'dwarf_arange.c',
286                       libdwarf + 'dwarf_attr.c',
287                       libdwarf + 'dwarf_attrval.c',
288                       libdwarf + 'dwarf_cu.c',
289                       libdwarf + 'dwarf_dealloc.c',
290                       libdwarf + 'dwarf_die.c',
291                       libdwarf + 'dwarf_dump.c',
292                       libdwarf + 'dwarf_errmsg.c',
293                       libdwarf + 'dwarf_finish.c',
294                       libdwarf + 'dwarf_form.c',
295                       libdwarf + 'dwarf_frame.c',
296                       libdwarf + 'dwarf_init.c',
297                       libdwarf + 'dwarf_lineno.c',
298                       libdwarf + 'dwarf_loclist.c',
299                       libdwarf + 'dwarf_macinfo.c',
300                       libdwarf + 'dwarf_pro_arange.c',
301                       libdwarf + 'dwarf_pro_attr.c',
302                       libdwarf + 'dwarf_pro_die.c',
303                       libdwarf + 'dwarf_pro_expr.c',
304                       libdwarf + 'dwarf_pro_finish.c',
305                       libdwarf + 'dwarf_pro_frame.c',
306                       libdwarf + 'dwarf_pro_init.c',
307                       libdwarf + 'dwarf_pro_lineno.c',
308                       libdwarf + 'dwarf_pro_macinfo.c',
309                       libdwarf + 'dwarf_pro_reloc.c',
310                       libdwarf + 'dwarf_pro_sections.c',
311                       libdwarf + 'dwarf_ranges.c',
312                       libdwarf + 'dwarf_reloc.c',
313                       libdwarf + 'dwarf_seterror.c',
314                       libdwarf + 'dwarf_str.c',
315                       libdwarf + 'libdwarf.c',
316                       libdwarf + 'libdwarf_abbrev.c',
317                       libdwarf + 'libdwarf_arange.c',
318                       libdwarf + 'libdwarf_attr.c',
319                       libdwarf + 'libdwarf_die.c',
320                       libdwarf + 'libdwarf_error.c',
321                       libdwarf + 'libdwarf_elf_access.c',
322                       libdwarf + 'libdwarf_elf_init.c',
323                       libdwarf + 'libdwarf_frame.c',
324                       libdwarf + 'libdwarf_info.c',
325                       libdwarf + 'libdwarf_init.c',
326                       libdwarf + 'libdwarf_lineno.c',
327                       libdwarf + 'libdwarf_loc.c',
328                       libdwarf + 'libdwarf_loclist.c',
329                       libdwarf + 'libdwarf_macinfo.c',
330                       libdwarf + 'libdwarf_nametbl.c',
331                       libdwarf + 'libdwarf_ranges.c',
332                       libdwarf + 'libdwarf_reloc.c',
333                       libdwarf + 'libdwarf_rw.c',
334                       libdwarf + 'libdwarf_sections.c',
335                       libdwarf + 'libdwarf_str.c'] + libdwarf_m4_source)
336
[87e0e76]337#
338# Libiberty module.
339#
340def conf_libiberty(conf):
341    conf.check(header_name='alloca.h',    features = 'c', mandatory = False)
342    conf.check(header_name='fcntl.h',     features = 'c', mandatory = False)
343    conf.check(header_name='process.h',   features = 'c', mandatory = False)
344    conf.check(header_name='stdlib.h',    features = 'c')
345    conf.check(header_name='string.h',    features = 'c')
346    conf.check(header_name='strings.h',   features = 'c', mandatory = False)
347    conf.check(header_name='sys/file.h',  features = 'c', mandatory = False)
348    conf.check(header_name='sys/stat.h',  features = 'c', mandatory = False)
349    conf.check(header_name='sys/time.h',  features = 'c', mandatory = False)
350    conf.check(header_name='sys/types.h', features = 'c', mandatory = False)
351    conf.check(header_name='sys/wait.h',  features = 'c', mandatory = False)
352    conf.check(header_name='unistd.h',    features = 'c', mandatory = False)
353    conf.check(header_name='vfork.h',     features = 'c', mandatory = False)
354
355    conf.check_cc(function_name='getrusage',
356                  header_name="sys/time.h sys/resource.h",
357                  features = 'c', mandatory = False)
358
359    conf.write_config_header('libiberty/config.h')
360
361def bld_libiberty(bld, conf):
[3badbb0]362    if bld.env.DEST_OS == 'win32':
[87e0e76]363        pex_host = 'libiberty/pex-win32.c'
364    else:
365        pex_host = 'libiberty/pex-unix.c'
366    bld.stlib(target = 'iberty',
367              features = 'c',
368              install_path = None,
369              includes = ['libiberty'],
370              cflags = conf['cflags'],
371              defines = ['HAVE_CONFIG_H=1'],
372              source =['libiberty/concat.c',
373                       'libiberty/cplus-dem.c',
374                       'libiberty/cp-demangle.c',
[78bbe4c]375                       'libiberty/d-demangle.c',
376                       'libiberty/rust-demangle.c',
[87e0e76]377                       'libiberty/make-temp-file.c',
378                       'libiberty/mkstemps.c',
379                       'libiberty/safe-ctype.c',
380                       'libiberty/stpcpy.c',
381                       'libiberty/pex-common.c',
382                       'libiberty/pex-one.c',
[78bbe4c]383                       'libiberty/xmalloc.c',
384                       'libiberty/xmemdup.c',
385                       'libiberty/xstrdup.c',
386                       'libiberty/xstrerror.c',
[87e0e76]387                       pex_host])
388
389#
390# The doxy command.
391#
392from waflib import Build
393class doxy(Build.BuildContext):
394    fun = 'build'
395    cmd = 'doxy'
Note: See TracBrowser for help on using the repository browser.