source: rtems-tools/linkers/wscript @ 9ba4e48

4.104.115
Last change on this file since 9ba4e48 was 6565f0c, checked in by Chris Johns <chrisj@…>, on 11/21/12 at 01:12:21

Enforce the header is created before using it on Linux.

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