source: rtems-tools/linkers/wscript @ 0b65a28

4.104.115
Last change on this file since 0b65a28 was 16e4346, checked in by Chris Johns <chrisj@…>, on 10/23/12 at 01:46:59

Add FastLZ support.

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