source: rtems-tools/linkers/wscript @ 993aa67

4.104.115
Last change on this file since 993aa67 was 993aa67, checked in by Chris Johns <chrisj@…>, on 09/15/12 at 07:58:00

Fix the waf script.

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