source: rtems-tools/linkers/wscript @ 810d0ad

4.104.115
Last change on this file since 810d0ad was 7461924, checked in by Chris Johns <chrisj@…>, on 09/17/12 at 00:13:55

Rename rld-gcc. Add -C option.

Add a -C (also --cc) option to allow the CC to be used when linking to be
provided by the user rather than using the path. This support allows user
who work with the full path to tools rather than the environment to make
use of the linker without them needing to play with environment table.

Rename rld-gcc.[h.cpp] to rld-cc.[h,cpp] because gcc may not be the
only compiler/linker used by the RTEMS project.

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