source: rtems-tools/linkers/wscript @ 26b46b1

4.104.115
Last change on this file since 26b46b1 was e78e2b0, checked in by Chris Johns <chrisj@…>, on 01/22/13 at 11:08:09

Documentation.

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