source: rtems-tools/linkers/wscript @ 6fb1409

4.104.115
Last change on this file since 6fb1409 was 6506aa1, checked in by Chris Johns <chrisj@…>, on 09/08/14 at 06:06:48

RTEMS trace linker builds trace applications.

The trace linker builds the both_hello example in examples-v2.

Move the various string support functions into a C++ file and stop being
inlined. Make them return const std::string.

Add ld support to rld-cc.

Add search path support to rld-config so installed common files can be used.

Fix the path bugs.

Add an absolute path function to rld-path.

  • Property mode set to 100644
File size: 13.4 KB
Line 
1#
2# RTEMS Linker build script.
3#
4import sys
5
6version_major = 1
7version_minor = 0
8version_revision = 0
9
10#
11# Waf system setup. Allow more than one build in the same tree.
12#
13top = '.'
14out = 'build-' + sys.platform
15
16def options(opt):
17    opt.load("g++")
18    opt.load("gcc")
19    opt.add_option('--rtems-version',
20                   default = '4.11',
21                   dest='rtems_version',
22                   help = 'Set the RTEMS version')
23    opt.add_option('--c-opts',
24                   default = '-O2',
25                   dest='c_opts',
26                   help = 'Set build options, default: -O2.')
27    opt.add_option('--show-commands',
28                   action = 'store_true',
29                   default = False,
30                   dest = 'show_commands',
31                   help = 'Print the commands as strings.')
32
33def configure(conf):
34    try:
35        conf.load("doxygen", tooldir = 'waf-tools')
36    except:
37        pass
38    conf.load("g++")
39    conf.load("gcc")
40    conf_libiberty(conf)
41    conf_libelf(conf)
42
43    conf.check(header_name='sys/wait.h',  features = 'c', mandatory = False)
44    conf.check_cc(function_name='kill', header_name="signal.h",
45                  features = 'c', mandatory = False)
46    conf.write_config_header('config.h')
47
48    conf.env.C_OPTS = conf.options.c_opts.split(',')
49    conf.env.RTEMS_VERSION = conf.options.rtems_version
50
51    if conf.options.show_commands:
52        show_commands = 'yes'
53    else:
54        show_commands = 'no'
55    conf.env.SHOW_COMMANDS = show_commands
56
57def build(bld):
58    #
59    # Build the doxygen documentation.
60    #
61    if bld.cmd == 'doxy':
62        bld(features = 'doxygen',
63            doxyfile = 'rtl-host.conf')
64        return
65
66    if bld.env.SHOW_COMMANDS == 'yes':
67        output_command_line()
68
69    #
70    # The include paths.
71    #
72    bld.includes = ['elftoolchain/libelf', 'elftoolchain/common', 'libiberty']
73    if sys.platform == 'win32':
74        bld.includes += ['win32']
75
76    #
77    # Build flags.
78    #
79    bld.warningflags = ['-Wall', '-Wextra', '-pedantic']
80    bld.optflags = bld.env.C_OPTS
81    bld.cflags = ['-pipe', '-g'] + bld.optflags
82    bld.cxxflags = ['-pipe', '-g'] + bld.optflags
83    bld.linkflags = ['-g']
84
85    #
86    # Create each of the modules as object files each with their own
87    # configurations.
88    #
89    bld_fastlz(bld)
90    bld_libelf(bld)
91    bld_libiberty(bld)
92
93    #
94    # RLD source.
95    #
96    rld_source = ['ConvertUTF.c',
97                  'pkgconfig.cpp',
98                  'rld-config.cpp',
99                  'rld-elf.cpp',
100                  'rld-files.cpp',
101                  'rld-cc.cpp',
102                  'rld-compression.cpp',
103                  'rld-outputter.cpp',
104                  'rld-path.cpp',
105                  'rld-process.cpp',
106                  'rld-resolver.cpp',
107                  'rld-rtems.cpp',
108                  'rld-symbols.cpp',
109                  'rld-rap.cpp',
110                  'rld.cpp']
111
112    #
113    # RTEMS Utilities.
114    #
115    rtems_utils = ['rtems-utils.cpp']
116
117    #
118    # RTL static library
119    #
120    bld.stlib(target = 'rld',
121              source = rld_source + rtems_utils,
122              defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
123              includes = ['.'] + bld.includes,
124              cflags = bld.cflags + bld.warningflags,
125              cxxflags = bld.cxxflags + bld.warningflags,
126              linkflags = bld.linkflags)
127
128    #
129    # The list of modules.
130    #
131    modules = ['rld', 'fastlz', 'elf', 'iberty']
132
133    #
134    # Build the linker.
135    #
136    bld.program(target = 'rtems-ld',
137                source = ['rtems-ld.cpp'],
138                defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
139                includes = ['.'] + bld.includes,
140                cflags = bld.cflags + bld.warningflags,
141                cxxflags = bld.cxxflags + bld.warningflags,
142                linkflags = bld.linkflags,
143                use = modules)
144
145    #
146    # Build the ra linker.
147    #
148    bld.program(target = 'rtems-ra',
149                source = ['rtems-ra.cpp'],
150                defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
151                includes = ['.'] + bld.includes,
152                cflags = bld.cflags + bld.warningflags,
153                cxxflags = bld.cxxflags + bld.warningflags,
154                linkflags = bld.linkflags,
155                use = modules)
156
157    #
158    # Build the trace linker.
159    #
160    bld.program(target = 'rtems-tld',
161                source = ['rtems-tld.cpp'],
162                defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
163                includes = ['.'] + bld.includes,
164                cflags = bld.cflags + bld.warningflags,
165                cxxflags = bld.cxxflags + bld.warningflags,
166                linkflags = bld.linkflags,
167                use = modules)
168    bld.install_files('${PREFIX}/share/rtems/trace-linker',
169                      ['rtems.ini', 'rtld-base.ini'])
170
171    #
172    # Build the symbols.
173    #
174    bld.program(target = 'rtems-syms',
175                source = ['rtems-syms.cpp'],
176                defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
177                includes = ['.'] + bld.includes,
178                cflags = bld.cflags + bld.warningflags,
179                cxxflags = bld.cxxflags + bld.warningflags,
180                linkflags = bld.linkflags,
181                use = modules)
182
183    #
184    # Build the RAP utility.
185    #
186    bld.program(target = 'rtems-rap',
187                source = ['rtems-rapper.cpp'],
188                defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
189                includes = ['.'] + bld.includes,
190                cflags = bld.cflags + bld.warningflags,
191                cxxflags = bld.cxxflags + bld.warningflags,
192                linkflags = bld.linkflags,
193                use = modules)
194
195def rebuild(ctx):
196    import waflib.Options
197    waflib.Options.commands.extend(['clean', 'build'])
198
199def tags(ctx):
200    ctx.exec_command('etags $(find . -name \*.[sSch])', shell = True)
201
202#
203# Libelf module.
204#
205def conf_libelf(conf):
206    pass
207
208def bld_fastlz(bld):
209    bld(target = 'fastlz',
210        features = 'c',
211        source = 'fastlz.c',
212        cflags = bld.cflags,
213        defines = ['FASTLZ_LEVEL=1'])
214
215def bld_libelf(bld):
216    libelf = 'elftoolchain/libelf/'
217
218    #
219    # Work around the ${SRC} having Windows slashes which the MSYS m4 does not
220    # understand.
221    #
222    if sys.platform == 'win32':
223        m4_rule = 'type ${SRC} | m4 -D SRCDIR=../' + libelf[:-1] + '> ${TGT}"'
224        includes = ['win32']
225    else:
226        m4_rule = 'm4 -D SRCDIR=../' + libelf[:-1] + ' ${SRC} > ${TGT}'
227        includes = []
228
229    bld(target = 'libelf_convert.c', source = libelf + 'libelf_convert.m4', rule = m4_rule)
230    bld(target = 'libelf_fsize.c',   source = libelf + 'libelf_fsize.m4',   rule = m4_rule)
231    bld(target = 'libelf_msize.c',   source = libelf + 'libelf_msize.m4',   rule = m4_rule)
232
233    host_source = []
234
235    if sys.platform == 'linux2':
236        common = 'elftoolchain/common/'
237        bld(target = common + 'native-elf-format.h',
238            source = common + 'native-elf-format',
239            name = 'native-elf-format',
240            rule   = './${SRC} > ${TGT}')
241        bld.add_group ()
242    elif sys.platform == 'win32':
243        host_source += [libelf + 'mmap_win32.c']
244
245    bld.stlib(target = 'elf',
246              features = 'c',
247              uses = ['native-elf-format'],
248              includes = [bld.bldnode.abspath(), 'elftoolchain/libelf', 'elftoolchain/common'] + includes,
249              cflags = bld.cflags,
250              source =[libelf + 'elf.c',
251                       libelf + 'elf_begin.c',
252                       libelf + 'elf_cntl.c',
253                       libelf + 'elf_end.c',
254                       libelf + 'elf_errmsg.c',
255                       libelf + 'elf_errno.c',
256                       libelf + 'elf_data.c',
257                       libelf + 'elf_fill.c',
258                       libelf + 'elf_flag.c',
259                       libelf + 'elf_getarhdr.c',
260                       libelf + 'elf_getarsym.c',
261                       libelf + 'elf_getbase.c',
262                       libelf + 'elf_getident.c',
263                       libelf + 'elf_hash.c',
264                       libelf + 'elf_kind.c',
265                       libelf + 'elf_memory.c',
266                       libelf + 'elf_next.c',
267                       libelf + 'elf_rand.c',
268                       libelf + 'elf_rawfile.c',
269                       libelf + 'elf_phnum.c',
270                       libelf + 'elf_shnum.c',
271                       libelf + 'elf_shstrndx.c',
272                       libelf + 'elf_scn.c',
273                       libelf + 'elf_strptr.c',
274                       libelf + 'elf_update.c',
275                       libelf + 'elf_version.c',
276                       libelf + 'gelf_cap.c',
277                       libelf + 'gelf_checksum.c',
278                       libelf + 'gelf_dyn.c',
279                       libelf + 'gelf_ehdr.c',
280                       libelf + 'gelf_getclass.c',
281                       libelf + 'gelf_fsize.c',
282                       libelf + 'gelf_move.c',
283                       libelf + 'gelf_phdr.c',
284                       libelf + 'gelf_rel.c',
285                       libelf + 'gelf_rela.c',
286                       libelf + 'gelf_shdr.c',
287                       libelf + 'gelf_sym.c',
288                       libelf + 'gelf_syminfo.c',
289                       libelf + 'gelf_symshndx.c',
290                       libelf + 'gelf_xlate.c',
291                       libelf + 'libelf_align.c',
292                       libelf + 'libelf_allocate.c',
293                       libelf + 'libelf_ar.c',
294                       libelf + 'libelf_ar_util.c',
295                       libelf + 'libelf_checksum.c',
296                       libelf + 'libelf_data.c',
297                       libelf + 'libelf_ehdr.c',
298                       libelf + 'libelf_extended.c',
299                       libelf + 'libelf_phdr.c',
300                       libelf + 'libelf_shdr.c',
301                       libelf + 'libelf_xlate.c',
302                       'libelf_convert.c',
303                       'libelf_fsize.c',
304                       'libelf_msize.c'] + host_source)
305
306#
307# Libiberty module.
308#
309def conf_libiberty(conf):
310    conf.check(header_name='alloca.h',    features = 'c', mandatory = False)
311    conf.check(header_name='fcntl.h',     features = 'c', mandatory = False)
312    conf.check(header_name='process.h',   features = 'c', mandatory = False)
313    conf.check(header_name='stdlib.h',    features = 'c')
314    conf.check(header_name='string.h',    features = 'c')
315    conf.check(header_name='strings.h',   features = 'c', mandatory = False)
316    conf.check(header_name='sys/file.h',  features = 'c', mandatory = False)
317    conf.check(header_name='sys/stat.h',  features = 'c', mandatory = False)
318    conf.check(header_name='sys/time.h',  features = 'c', mandatory = False)
319    conf.check(header_name='sys/types.h', features = 'c', mandatory = False)
320    conf.check(header_name='sys/wait.h',  features = 'c', mandatory = False)
321    conf.check(header_name='unistd.h',    features = 'c', mandatory = False)
322    conf.check(header_name='vfork.h',     features = 'c', mandatory = False)
323
324    conf.check_cc(function_name='getrusage',
325                  header_name="sys/time.h sys/resource.h",
326                  features = 'c', mandatory = False)
327
328    conf.write_config_header('libiberty/config.h')
329
330def bld_libiberty(bld):
331    if sys.platform == 'win32':
332        pex_host = 'libiberty/pex-win32.c'
333    else:
334        pex_host = 'libiberty/pex-unix.c'
335    bld.stlib(target = 'iberty',
336              features = 'c',
337              includes = ['libiberty'],
338              cflags = bld.cflags,
339              defines = ['HAVE_CONFIG_H=1'],
340              source =['libiberty/concat.c',
341                       'libiberty/cplus-dem.c',
342                       'libiberty/cp-demangle.c',
343                       'libiberty/make-temp-file.c',
344                       'libiberty/mkstemps.c',
345                       'libiberty/safe-ctype.c',
346                       'libiberty/stpcpy.c',
347                       'libiberty/pex-common.c',
348                       'libiberty/pex-one.c',
349                       pex_host])
350
351#
352# From the demos. Use this to get the command to cut+paste to play.
353#
354def output_command_line():
355    # first, display strings, people like them
356    from waflib import Utils, Logs
357    from waflib.Context import Context
358    def exec_command(self, cmd, **kw):
359        subprocess = Utils.subprocess
360        kw['shell'] = isinstance(cmd, str)
361        if isinstance(cmd, str):
362            Logs.info('%s' % cmd)
363        else:
364            Logs.info('%s' % ' '.join(cmd)) # here is the change
365        Logs.debug('runner_env: kw=%s' % kw)
366        try:
367            if self.logger:
368                self.logger.info(cmd)
369                kw['stdout'] = kw['stderr'] = subprocess.PIPE
370                p = subprocess.Popen(cmd, **kw)
371                (out, err) = p.communicate()
372                if out:
373                    self.logger.debug('out: %s' % out.decode(sys.stdout.encoding or 'iso8859-1'))
374                if err:
375                    self.logger.error('err: %s' % err.decode(sys.stdout.encoding or 'iso8859-1'))
376                return p.returncode
377            else:
378                p = subprocess.Popen(cmd, **kw)
379                return p.wait()
380        except OSError:
381            return -1
382    Context.exec_command = exec_command
383
384    # Change the outputs for tasks too
385    from waflib.Task import Task
386    def display(self):
387        return '' # no output on empty strings
388
389    Task.__str__ = display
390
391#
392# The doxy command.
393#
394from waflib import Build
395class doxy(Build.BuildContext):
396    fun = 'build'
397    cmd = 'doxy'
Note: See TracBrowser for help on using the repository browser.