source: rtems-tools/linkers/wscript @ 977c3de

4.104.11
Last change on this file since 977c3de was 977c3de, checked in by Chris Johns <chrisj@…>, on Nov 17, 2012 at 6:34:33 AM

Refactor the ELF support to allow ELF write suppport.

The refactoring allows better reuse of the ELF support and cleans up
some hacks from the generic file and archive handling improving the
separation of the file handling from the file format, ie ELF. The
handling of ELF object files and ELF object files inside archives
is cleaner.

The refactor cleaned up the symbol handling where the symbols now
reside in the ELF file object and references are take in symbol
pointer containers and symbol table containers.

The main purpose of the refactor is to allow support for creating
and writing ELF files.

Also added an rtems-syms command where special symbol support
can be added.

  • Property mode set to 100644
File size: 10.8 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('--show-commands',
24                   action = 'store_true',
25                   default = False,
26                   dest = 'show_commands',
27                   help = 'Print the commands as strings.')
28
29def configure(conf):
30    conf.load("g++")
31    conf.load("gcc")
32    conf_libiberty(conf)
33    conf_libelf(conf)
34
35    conf.check(header_name='sys/wait.h',  features = 'c', mandatory = False)
36    conf.check_cc(function_name='kill', header_name="signal.h",
37                  features = 'c', mandatory = False)
38    conf.write_config_header('config.h')
39
40    conf.env.RTEMS_VERSION = conf.options.rtems_version
41
42    if conf.options.show_commands:
43        show_commands = 'yes'
44    else:
45        show_commands = 'no'
46    conf.env.SHOW_COMMANDS = show_commands
47
48def build(bld):
49    if bld.env.SHOW_COMMANDS == 'yes':
50        output_command_line()
51
52    #
53    # The include paths.
54    #
55    bld.includes = ['elftoolchain/libelf', 'elftoolchain/common', 'libiberty']
56    if sys.platform == 'win32':
57        bld.includes += ['win32']
58
59    #
60    # Build flags.
61    #
62    bld.warningflags = ['-Wall', '-Wextra', '-pedantic']
63    bld.optflags = [] #['-O2']
64    bld.cflags = ['-pipe', '-g'] + bld.optflags
65    bld.cxxflags = ['-pipe', '-g'] + bld.optflags
66    bld.linkflags = ['-g']
67
68    #
69    # Create each of the modules as object files each with their own
70    # configurations.
71    #
72    bld_fastlz(bld)
73    bld_libelf(bld)
74    bld_libiberty(bld)
75
76    #
77    # The list of modules.
78    #
79    modules = ['fastlz', 'elf', 'iberty']
80
81    #
82    # RLD source.
83    #
84    rld_source = ['rld-elf.cpp',
85                  'rld-files.cpp',
86                  'rld-cc.cpp',
87                  'rld-outputter.cpp',
88                  'rld-process.cpp',
89                  'rld-resolver.cpp',
90                  'rld-symbols.cpp',
91                  'rld.cpp']
92
93    #
94    # Build the linker.
95    #
96    bld.program(target = 'rtems-ld',
97                source = ['rtems-ld.cpp',
98                          'pkgconfig.cpp'] + rld_source,
99                defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
100                includes = ['.'] + bld.includes,
101                cflags = bld.cflags + bld.warningflags,
102                cxxflags = bld.cxxflags + bld.warningflags,
103                linkflags = bld.linkflags,
104                use = modules)
105
106    #
107    # Build the symbols.
108    #
109    bld.program(target = 'rtems-syms',
110                source = ['rtems-syms.cpp'] + rld_source,
111                defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
112                includes = ['.'] + bld.includes,
113                cflags = bld.cflags + bld.warningflags,
114                cxxflags = bld.cxxflags + bld.warningflags,
115                linkflags = bld.linkflags,
116                use = modules)
117
118def rebuild(ctx):
119    import waflib.Options
120    waflib.Options.commands.extend(['clean', 'build'])
121
122def tags(ctx):
123    ctx.exec_command('etags $(find . -name \*.[sSch])', shell = True)
124
125#
126# Libelf module.
127#
128def conf_libelf(conf):
129    pass
130
131def bld_fastlz(bld):
132    bld(target = 'fastlz',
133        features = 'c',
134        source = 'fastlz.c',
135        cflags = bld.cflags,
136        defines = ['FASTLZ_LEVEL=1'])
137
138def bld_libelf(bld):
139    libelf = 'elftoolchain/libelf/'
140
141    #
142    # Work around the ${SRC} having Windows slashes which the MSYS m4 does not
143    # understand.
144    #
145    if sys.platform == 'win32':
146        m4_rule = 'type ${SRC} | m4 -D SRCDIR=../' + libelf[:-1] + '> ${TGT}"'
147        includes = ['win32']
148    else:
149        m4_rule = 'm4 -D SRCDIR=../' + libelf[:-1] + ' ${SRC} > ${TGT}'
150        includes = []
151
152    bld(target = 'libelf_convert.c', source = libelf + 'libelf_convert.m4', rule = m4_rule)
153    bld(target = 'libelf_fsize.c',   source = libelf + 'libelf_fsize.m4',   rule = m4_rule)
154    bld(target = 'libelf_msize.c',   source = libelf + 'libelf_msize.m4',   rule = m4_rule)
155
156    host_source = []
157
158    if sys.platform == 'linux2':
159        common = 'elftoolchain/common/'
160        bld(target = common + 'native-elf-format.h',
161            source = common + 'native-elf-format',
162            name = 'native-elf-format',
163            rule   = './${SRC} > ${TGT}')
164    elif sys.platform == 'win32':
165        host_source += [libelf + 'mmap_win32.c']
166
167    bld.stlib(target = 'elf',
168              features = 'c',
169              uses = ['native-elf-format'],
170              includes = [bld.bldnode.abspath(), 'elftoolchain/libelf', 'elftoolchain/common'] + includes,
171              cflags = bld.cflags,
172              source =[libelf + 'elf.c',
173                       libelf + 'elf_begin.c',
174                       libelf + 'elf_cntl.c',
175                       libelf + 'elf_end.c',
176                       libelf + 'elf_errmsg.c',
177                       libelf + 'elf_errno.c',
178                       libelf + 'elf_data.c',
179                       libelf + 'elf_fill.c',
180                       libelf + 'elf_flag.c',
181                       libelf + 'elf_getarhdr.c',
182                       libelf + 'elf_getarsym.c',
183                       libelf + 'elf_getbase.c',
184                       libelf + 'elf_getident.c',
185                       libelf + 'elf_hash.c',
186                       libelf + 'elf_kind.c',
187                       libelf + 'elf_memory.c',
188                       libelf + 'elf_next.c',
189                       libelf + 'elf_rand.c',
190                       libelf + 'elf_rawfile.c',
191                       libelf + 'elf_phnum.c',
192                       libelf + 'elf_shnum.c',
193                       libelf + 'elf_shstrndx.c',
194                       libelf + 'elf_scn.c',
195                       libelf + 'elf_strptr.c',
196                       libelf + 'elf_update.c',
197                       libelf + 'elf_version.c',
198                       libelf + 'gelf_cap.c',
199                       libelf + 'gelf_checksum.c',
200                       libelf + 'gelf_dyn.c',
201                       libelf + 'gelf_ehdr.c',
202                       libelf + 'gelf_getclass.c',
203                       libelf + 'gelf_fsize.c',
204                       libelf + 'gelf_move.c',
205                       libelf + 'gelf_phdr.c',
206                       libelf + 'gelf_rel.c',
207                       libelf + 'gelf_rela.c',
208                       libelf + 'gelf_shdr.c',
209                       libelf + 'gelf_sym.c',
210                       libelf + 'gelf_syminfo.c',
211                       libelf + 'gelf_symshndx.c',
212                       libelf + 'gelf_xlate.c',
213                       libelf + 'libelf_align.c',
214                       libelf + 'libelf_allocate.c',
215                       libelf + 'libelf_ar.c',
216                       libelf + 'libelf_ar_util.c',
217                       libelf + 'libelf_checksum.c',
218                       libelf + 'libelf_data.c',
219                       libelf + 'libelf_ehdr.c',
220                       libelf + 'libelf_extended.c',
221                       libelf + 'libelf_phdr.c',
222                       libelf + 'libelf_shdr.c',
223                       libelf + 'libelf_xlate.c',
224                       'libelf_convert.c',
225                       'libelf_fsize.c',
226                       'libelf_msize.c'] + host_source)
227
228#
229# Libiberty module.
230#
231def conf_libiberty(conf):
232    conf.check(header_name='alloca.h',    features = 'c', mandatory = False)
233    conf.check(header_name='fcntl.h',     features = 'c', mandatory = False)
234    conf.check(header_name='process.h',   features = 'c', mandatory = False)
235    conf.check(header_name='stdlib.h',    features = 'c')
236    conf.check(header_name='string.h',    features = 'c')
237    conf.check(header_name='strings.h',   features = 'c', mandatory = False)
238    conf.check(header_name='sys/file.h',  features = 'c', mandatory = False)
239    conf.check(header_name='sys/stat.h',  features = 'c', mandatory = False)
240    conf.check(header_name='sys/time.h',  features = 'c', mandatory = False)
241    conf.check(header_name='sys/types.h', features = 'c', mandatory = False)
242    conf.check(header_name='sys/wait.h',  features = 'c', mandatory = False)
243    conf.check(header_name='unistd.h',    features = 'c', mandatory = False)
244    conf.check(header_name='vfork.h',     features = 'c', mandatory = False)
245
246    conf.check_cc(function_name='getrusage',
247                  header_name="sys/time.h sys/resource.h",
248                  features = 'c', mandatory = False)
249
250    conf.write_config_header('libiberty/config.h')
251
252def bld_libiberty(bld):
253    if sys.platform == 'win32':
254        pex_host = 'libiberty/pex-win32.c'
255    else:
256        pex_host = 'libiberty/pex-unix.c'
257    bld.stlib(target = 'iberty',
258              features = 'c',
259              includes = ['libiberty'],
260              cflags = bld.cflags,
261              defines = ['HAVE_CONFIG_H=1'],
262              source =['libiberty/concat.c',
263                       'libiberty/cplus-dem.c',
264                       'libiberty/cp-demangle.c',
265                       'libiberty/make-temp-file.c',
266                       'libiberty/mkstemps.c',
267                       'libiberty/safe-ctype.c',
268                       'libiberty/stpcpy.c',
269                       'libiberty/pex-common.c',
270                       'libiberty/pex-one.c',
271                       pex_host])
272
273#
274# From the demos. Use this to get the command to cut+paste to play.
275#
276def output_command_line():
277    # first, display strings, people like them
278    from waflib import Utils, Logs
279    from waflib.Context import Context
280    def exec_command(self, cmd, **kw):
281        subprocess = Utils.subprocess
282        kw['shell'] = isinstance(cmd, str)
283        if isinstance(cmd, str):
284            Logs.info('%s' % cmd)
285        else:
286            Logs.info('%s' % ' '.join(cmd)) # here is the change
287        Logs.debug('runner_env: kw=%s' % kw)
288        try:
289            if self.logger:
290                self.logger.info(cmd)
291                kw['stdout'] = kw['stderr'] = subprocess.PIPE
292                p = subprocess.Popen(cmd, **kw)
293                (out, err) = p.communicate()
294                if out:
295                    self.logger.debug('out: %s' % out.decode(sys.stdout.encoding or 'iso8859-1'))
296                if err:
297                    self.logger.error('err: %s' % err.decode(sys.stdout.encoding or 'iso8859-1'))
298                return p.returncode
299            else:
300                p = subprocess.Popen(cmd, **kw)
301                return p.wait()
302        except OSError:
303            return -1
304    Context.exec_command = exec_command
305
306    # Change the outputs for tasks too
307    from waflib.Task import Task
308    def display(self):
309        return '' # no output on empty strings
310
311    Task.__str__ = display
Note: See TracBrowser for help on using the repository browser.