source: rtems-tools/linkers/wscript @ f31cded

4.104.115
Last change on this file since f31cded was b9f631e, checked in by Chris Johns <chrisj@…>, on 12/23/12 at 05:54:59

Add a memory dump utility.

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