source: rtems-tools/linkers/wscript @ 3f5e31f

4.104.115
Last change on this file since 3f5e31f was 31bf375, checked in by Chris Johns <chrisj@…>, on 09/05/14 at 08:18:11

Remove march/mcpu and add RTEMS BSP and cflags support.

  • Property mode set to 100644
File size: 13.3 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
169    #
170    # Build the symbols.
171    #
172    bld.program(target = 'rtems-syms',
173                source = ['rtems-syms.cpp'],
174                defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
175                includes = ['.'] + bld.includes,
176                cflags = bld.cflags + bld.warningflags,
177                cxxflags = bld.cxxflags + bld.warningflags,
178                linkflags = bld.linkflags,
179                use = modules)
180
181    #
182    # Build the RAP utility.
183    #
184    bld.program(target = 'rtems-rap',
185                source = ['rtems-rapper.cpp'],
186                defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
187                includes = ['.'] + bld.includes,
188                cflags = bld.cflags + bld.warningflags,
189                cxxflags = bld.cxxflags + bld.warningflags,
190                linkflags = bld.linkflags,
191                use = modules)
192
193def rebuild(ctx):
194    import waflib.Options
195    waflib.Options.commands.extend(['clean', 'build'])
196
197def tags(ctx):
198    ctx.exec_command('etags $(find . -name \*.[sSch])', shell = True)
199
200#
201# Libelf module.
202#
203def conf_libelf(conf):
204    pass
205
206def bld_fastlz(bld):
207    bld(target = 'fastlz',
208        features = 'c',
209        source = 'fastlz.c',
210        cflags = bld.cflags,
211        defines = ['FASTLZ_LEVEL=1'])
212
213def bld_libelf(bld):
214    libelf = 'elftoolchain/libelf/'
215
216    #
217    # Work around the ${SRC} having Windows slashes which the MSYS m4 does not
218    # understand.
219    #
220    if sys.platform == 'win32':
221        m4_rule = 'type ${SRC} | m4 -D SRCDIR=../' + libelf[:-1] + '> ${TGT}"'
222        includes = ['win32']
223    else:
224        m4_rule = 'm4 -D SRCDIR=../' + libelf[:-1] + ' ${SRC} > ${TGT}'
225        includes = []
226
227    bld(target = 'libelf_convert.c', source = libelf + 'libelf_convert.m4', rule = m4_rule)
228    bld(target = 'libelf_fsize.c',   source = libelf + 'libelf_fsize.m4',   rule = m4_rule)
229    bld(target = 'libelf_msize.c',   source = libelf + 'libelf_msize.m4',   rule = m4_rule)
230
231    host_source = []
232
233    if sys.platform == 'linux2':
234        common = 'elftoolchain/common/'
235        bld(target = common + 'native-elf-format.h',
236            source = common + 'native-elf-format',
237            name = 'native-elf-format',
238            rule   = './${SRC} > ${TGT}')
239        bld.add_group ()
240    elif sys.platform == 'win32':
241        host_source += [libelf + 'mmap_win32.c']
242
243    bld.stlib(target = 'elf',
244              features = 'c',
245              uses = ['native-elf-format'],
246              includes = [bld.bldnode.abspath(), 'elftoolchain/libelf', 'elftoolchain/common'] + includes,
247              cflags = bld.cflags,
248              source =[libelf + 'elf.c',
249                       libelf + 'elf_begin.c',
250                       libelf + 'elf_cntl.c',
251                       libelf + 'elf_end.c',
252                       libelf + 'elf_errmsg.c',
253                       libelf + 'elf_errno.c',
254                       libelf + 'elf_data.c',
255                       libelf + 'elf_fill.c',
256                       libelf + 'elf_flag.c',
257                       libelf + 'elf_getarhdr.c',
258                       libelf + 'elf_getarsym.c',
259                       libelf + 'elf_getbase.c',
260                       libelf + 'elf_getident.c',
261                       libelf + 'elf_hash.c',
262                       libelf + 'elf_kind.c',
263                       libelf + 'elf_memory.c',
264                       libelf + 'elf_next.c',
265                       libelf + 'elf_rand.c',
266                       libelf + 'elf_rawfile.c',
267                       libelf + 'elf_phnum.c',
268                       libelf + 'elf_shnum.c',
269                       libelf + 'elf_shstrndx.c',
270                       libelf + 'elf_scn.c',
271                       libelf + 'elf_strptr.c',
272                       libelf + 'elf_update.c',
273                       libelf + 'elf_version.c',
274                       libelf + 'gelf_cap.c',
275                       libelf + 'gelf_checksum.c',
276                       libelf + 'gelf_dyn.c',
277                       libelf + 'gelf_ehdr.c',
278                       libelf + 'gelf_getclass.c',
279                       libelf + 'gelf_fsize.c',
280                       libelf + 'gelf_move.c',
281                       libelf + 'gelf_phdr.c',
282                       libelf + 'gelf_rel.c',
283                       libelf + 'gelf_rela.c',
284                       libelf + 'gelf_shdr.c',
285                       libelf + 'gelf_sym.c',
286                       libelf + 'gelf_syminfo.c',
287                       libelf + 'gelf_symshndx.c',
288                       libelf + 'gelf_xlate.c',
289                       libelf + 'libelf_align.c',
290                       libelf + 'libelf_allocate.c',
291                       libelf + 'libelf_ar.c',
292                       libelf + 'libelf_ar_util.c',
293                       libelf + 'libelf_checksum.c',
294                       libelf + 'libelf_data.c',
295                       libelf + 'libelf_ehdr.c',
296                       libelf + 'libelf_extended.c',
297                       libelf + 'libelf_phdr.c',
298                       libelf + 'libelf_shdr.c',
299                       libelf + 'libelf_xlate.c',
300                       'libelf_convert.c',
301                       'libelf_fsize.c',
302                       'libelf_msize.c'] + host_source)
303
304#
305# Libiberty module.
306#
307def conf_libiberty(conf):
308    conf.check(header_name='alloca.h',    features = 'c', mandatory = False)
309    conf.check(header_name='fcntl.h',     features = 'c', mandatory = False)
310    conf.check(header_name='process.h',   features = 'c', mandatory = False)
311    conf.check(header_name='stdlib.h',    features = 'c')
312    conf.check(header_name='string.h',    features = 'c')
313    conf.check(header_name='strings.h',   features = 'c', mandatory = False)
314    conf.check(header_name='sys/file.h',  features = 'c', mandatory = False)
315    conf.check(header_name='sys/stat.h',  features = 'c', mandatory = False)
316    conf.check(header_name='sys/time.h',  features = 'c', mandatory = False)
317    conf.check(header_name='sys/types.h', features = 'c', mandatory = False)
318    conf.check(header_name='sys/wait.h',  features = 'c', mandatory = False)
319    conf.check(header_name='unistd.h',    features = 'c', mandatory = False)
320    conf.check(header_name='vfork.h',     features = 'c', mandatory = False)
321
322    conf.check_cc(function_name='getrusage',
323                  header_name="sys/time.h sys/resource.h",
324                  features = 'c', mandatory = False)
325
326    conf.write_config_header('libiberty/config.h')
327
328def bld_libiberty(bld):
329    if sys.platform == 'win32':
330        pex_host = 'libiberty/pex-win32.c'
331    else:
332        pex_host = 'libiberty/pex-unix.c'
333    bld.stlib(target = 'iberty',
334              features = 'c',
335              includes = ['libiberty'],
336              cflags = bld.cflags,
337              defines = ['HAVE_CONFIG_H=1'],
338              source =['libiberty/concat.c',
339                       'libiberty/cplus-dem.c',
340                       'libiberty/cp-demangle.c',
341                       'libiberty/make-temp-file.c',
342                       'libiberty/mkstemps.c',
343                       'libiberty/safe-ctype.c',
344                       'libiberty/stpcpy.c',
345                       'libiberty/pex-common.c',
346                       'libiberty/pex-one.c',
347                       pex_host])
348
349#
350# From the demos. Use this to get the command to cut+paste to play.
351#
352def output_command_line():
353    # first, display strings, people like them
354    from waflib import Utils, Logs
355    from waflib.Context import Context
356    def exec_command(self, cmd, **kw):
357        subprocess = Utils.subprocess
358        kw['shell'] = isinstance(cmd, str)
359        if isinstance(cmd, str):
360            Logs.info('%s' % cmd)
361        else:
362            Logs.info('%s' % ' '.join(cmd)) # here is the change
363        Logs.debug('runner_env: kw=%s' % kw)
364        try:
365            if self.logger:
366                self.logger.info(cmd)
367                kw['stdout'] = kw['stderr'] = subprocess.PIPE
368                p = subprocess.Popen(cmd, **kw)
369                (out, err) = p.communicate()
370                if out:
371                    self.logger.debug('out: %s' % out.decode(sys.stdout.encoding or 'iso8859-1'))
372                if err:
373                    self.logger.error('err: %s' % err.decode(sys.stdout.encoding or 'iso8859-1'))
374                return p.returncode
375            else:
376                p = subprocess.Popen(cmd, **kw)
377                return p.wait()
378        except OSError:
379            return -1
380    Context.exec_command = exec_command
381
382    # Change the outputs for tasks too
383    from waflib.Task import Task
384    def display(self):
385        return '' # no output on empty strings
386
387    Task.__str__ = display
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.