source: rtems-tools/linkers/wscript @ f10123a

4.104.115
Last change on this file since f10123a was be8e188, checked in by Chris Johns <chrisj@…>, on 12/07/12 at 22:05:12

Add doxygen support.

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