source: rtems-tools/linkers/wscript @ 825a10e

4.104.115
Last change on this file since 825a10e was eb825b1, checked in by Chris Johns <chrisj@…>, on 11/26/12 at 00:09:35

Add RAP format support.

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