summaryrefslogtreecommitdiff
path: root/linkers/wscript
blob: c6d1d31d1d254a292a1ae6428b8e00dd68dd4b1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#
# RTEMS Linker build script.
#
import sys

version_major = 1
version_minor = 0
version_revision = 0

#
# Waf system setup. Allow more than one build in the same tree.
#
top = '.'
out = 'build-' + sys.platform

def options(opt):
    opt.load("g++")
    opt.load("gcc")
    opt.add_option('--rtems-version',
                   default = '4.11',
                   dest='rtems_version',
                   help = 'Set the RTEMS version')
    opt.add_option('--c-opts',
                   default = '-O2',
                   dest='c_opts',
                   help = 'Set build options, default: -O2.')
    opt.add_option('--show-commands',
                   action = 'store_true',
                   default = False,
                   dest = 'show_commands',
                   help = 'Print the commands as strings.')

def configure(conf):
    try:
        conf.load("doxygen", tooldir = 'waf-tools')
    except:
        pass
    conf.load("g++")
    conf.load("gcc")
    conf_libiberty(conf)
    conf_libelf(conf)

    conf.check(header_name='sys/wait.h',  features = 'c', mandatory = False)
    conf.check_cc(function_name='kill', header_name="signal.h",
                  features = 'c', mandatory = False)
    conf.write_config_header('config.h')

    conf.env.C_OPTS = conf.options.c_opts.split(',')
    conf.env.RTEMS_VERSION = conf.options.rtems_version

    if conf.options.show_commands:
        show_commands = 'yes'
    else:
        show_commands = 'no'
    conf.env.SHOW_COMMANDS = show_commands

def build(bld):
    #
    # Build the doxygen documentation.
    #
    if bld.cmd == 'doxy':
        bld(features = 'doxygen',
            doxyfile = 'rtl-host.conf')
        return

    if bld.env.SHOW_COMMANDS == 'yes':
        output_command_line()

    #
    # The include paths.
    #
    bld.includes = ['elftoolchain/libelf', 'elftoolchain/common', 'libiberty']
    if sys.platform == 'win32':
        bld.includes += ['win32']

    #
    # Build flags.
    #
    bld.warningflags = ['-Wall', '-Wextra', '-pedantic']
    bld.optflags = bld.env.C_OPTS
    bld.cflags = ['-pipe', '-g'] + bld.optflags
    bld.cxxflags = ['-pipe', '-g'] + bld.optflags
    bld.linkflags = ['-g']

    #
    # Create each of the modules as object files each with their own
    # configurations.
    #
    bld_fastlz(bld)
    bld_libelf(bld)
    bld_libiberty(bld)

    #
    # RLD source.
    #
    rld_source = ['ConvertUTF.c',
                  'rld-config.cpp',
                  'rld-elf.cpp',
                  'rld-files.cpp',
                  'rld-cc.cpp',
                  'rld-compression.cpp',
                  'rld-outputter.cpp',
                  'rld-process.cpp',
                  'rld-resolver.cpp',
                  'rld-symbols.cpp',
                  'rld-rap.cpp',
                  'rld.cpp']

    #
    # RTEMS Utilities.
    #
    rtems_utils = ['rtems-utils.cpp']

    #
    # RTL static library
    #
    bld.stlib(target = 'rld',
              source = rld_source + rtems_utils,
              defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
              includes = ['.'] + bld.includes,
              cflags = bld.cflags + bld.warningflags,
              cxxflags = bld.cxxflags + bld.warningflags,
              linkflags = bld.linkflags)

    #
    # The list of modules.
    #
    modules = ['rld', 'fastlz', 'elf', 'iberty']

    #
    # Build the linker.
    #
    bld.program(target = 'rtems-ld',
                source = ['rtems-ld.cpp', 'pkgconfig.cpp'],
                defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
                includes = ['.'] + bld.includes,
                cflags = bld.cflags + bld.warningflags,
                cxxflags = bld.cxxflags + bld.warningflags,
                linkflags = bld.linkflags,
                use = modules)

    #
    # Build the ra linker.
    #
    bld.program(target = 'rtems-ra',
                source = ['rtems-ra.cpp', 'pkgconfig.cpp'],
                defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
                includes = ['.'] + bld.includes,
                cflags = bld.cflags + bld.warningflags,
                cxxflags = bld.cxxflags + bld.warningflags,
                linkflags = bld.linkflags,
                use = modules)

    #
    # Build the trace linker.
    #
    bld.program(target = 'rtems-tld',
                source = ['rtems-tld.cpp'],
                defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
                includes = ['.'] + bld.includes,
                cflags = bld.cflags + bld.warningflags,
                cxxflags = bld.cxxflags + bld.warningflags,
                linkflags = bld.linkflags,
                use = modules)

    #
    # Build the symbols.
    #
    bld.program(target = 'rtems-syms',
                source = ['rtems-syms.cpp'],
                defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
                includes = ['.'] + bld.includes,
                cflags = bld.cflags + bld.warningflags,
                cxxflags = bld.cxxflags + bld.warningflags,
                linkflags = bld.linkflags,
                use = modules)

    #
    # Build the RAP utility.
    #
    bld.program(target = 'rtems-rap',
                source = ['rtems-rapper.cpp'],
                defines = ['HAVE_CONFIG_H=1', 'RTEMS_VERSION=' + bld.env.RTEMS_VERSION],
                includes = ['.'] + bld.includes,
                cflags = bld.cflags + bld.warningflags,
                cxxflags = bld.cxxflags + bld.warningflags,
                linkflags = bld.linkflags,
                use = modules)

def rebuild(ctx):
    import waflib.Options
    waflib.Options.commands.extend(['clean', 'build'])

def tags(ctx):
    ctx.exec_command('etags $(find . -name \*.[sSch])', shell = True)

#
# Libelf module.
#
def conf_libelf(conf):
    pass

def bld_fastlz(bld):
    bld(target = 'fastlz',
        features = 'c',
        source = 'fastlz.c',
        cflags = bld.cflags,
        defines = ['FASTLZ_LEVEL=1'])

def bld_libelf(bld):
    libelf = 'elftoolchain/libelf/'

    #
    # Work around the ${SRC} having Windows slashes which the MSYS m4 does not
    # understand.
    #
    if sys.platform == 'win32':
        m4_rule = 'type ${SRC} | m4 -D SRCDIR=../' + libelf[:-1] + '> ${TGT}"'
        includes = ['win32']
    else:
        m4_rule = 'm4 -D SRCDIR=../' + libelf[:-1] + ' ${SRC} > ${TGT}'
        includes = []

    bld(target = 'libelf_convert.c', source = libelf + 'libelf_convert.m4', rule = m4_rule)
    bld(target = 'libelf_fsize.c',   source = libelf + 'libelf_fsize.m4',   rule = m4_rule)
    bld(target = 'libelf_msize.c',   source = libelf + 'libelf_msize.m4',   rule = m4_rule)

    host_source = []

    if sys.platform == 'linux2':
        common = 'elftoolchain/common/'
        bld(target = common + 'native-elf-format.h',
            source = common + 'native-elf-format',
            name = 'native-elf-format',
            rule   = './${SRC} > ${TGT}')
        bld.add_group ()
    elif sys.platform == 'win32':
        host_source += [libelf + 'mmap_win32.c']

    bld.stlib(target = 'elf',
              features = 'c',
              uses = ['native-elf-format'],
              includes = [bld.bldnode.abspath(), 'elftoolchain/libelf', 'elftoolchain/common'] + includes,
              cflags = bld.cflags,
              source =[libelf + 'elf.c',
                       libelf + 'elf_begin.c',
                       libelf + 'elf_cntl.c',
                       libelf + 'elf_end.c',
                       libelf + 'elf_errmsg.c',
                       libelf + 'elf_errno.c',
                       libelf + 'elf_data.c',
                       libelf + 'elf_fill.c',
                       libelf + 'elf_flag.c',
                       libelf + 'elf_getarhdr.c',
                       libelf + 'elf_getarsym.c',
                       libelf + 'elf_getbase.c',
                       libelf + 'elf_getident.c',
                       libelf + 'elf_hash.c',
                       libelf + 'elf_kind.c',
                       libelf + 'elf_memory.c',
                       libelf + 'elf_next.c',
                       libelf + 'elf_rand.c',
                       libelf + 'elf_rawfile.c',
                       libelf + 'elf_phnum.c',
                       libelf + 'elf_shnum.c',
                       libelf + 'elf_shstrndx.c',
                       libelf + 'elf_scn.c',
                       libelf + 'elf_strptr.c',
                       libelf + 'elf_update.c',
                       libelf + 'elf_version.c',
                       libelf + 'gelf_cap.c',
                       libelf + 'gelf_checksum.c',
                       libelf + 'gelf_dyn.c',
                       libelf + 'gelf_ehdr.c',
                       libelf + 'gelf_getclass.c',
                       libelf + 'gelf_fsize.c',
                       libelf + 'gelf_move.c',
                       libelf + 'gelf_phdr.c',
                       libelf + 'gelf_rel.c',
                       libelf + 'gelf_rela.c',
                       libelf + 'gelf_shdr.c',
                       libelf + 'gelf_sym.c',
                       libelf + 'gelf_syminfo.c',
                       libelf + 'gelf_symshndx.c',
                       libelf + 'gelf_xlate.c',
                       libelf + 'libelf_align.c',
                       libelf + 'libelf_allocate.c',
                       libelf + 'libelf_ar.c',
                       libelf + 'libelf_ar_util.c',
                       libelf + 'libelf_checksum.c',
                       libelf + 'libelf_data.c',
                       libelf + 'libelf_ehdr.c',
                       libelf + 'libelf_extended.c',
                       libelf + 'libelf_phdr.c',
                       libelf + 'libelf_shdr.c',
                       libelf + 'libelf_xlate.c',
                       'libelf_convert.c',
                       'libelf_fsize.c',
                       'libelf_msize.c'] + host_source)

#
# Libiberty module.
#
def conf_libiberty(conf):
    conf.check(header_name='alloca.h',    features = 'c', mandatory = False)
    conf.check(header_name='fcntl.h',     features = 'c', mandatory = False)
    conf.check(header_name='process.h',   features = 'c', mandatory = False)
    conf.check(header_name='stdlib.h',    features = 'c')
    conf.check(header_name='string.h',    features = 'c')
    conf.check(header_name='strings.h',   features = 'c', mandatory = False)
    conf.check(header_name='sys/file.h',  features = 'c', mandatory = False)
    conf.check(header_name='sys/stat.h',  features = 'c', mandatory = False)
    conf.check(header_name='sys/time.h',  features = 'c', mandatory = False)
    conf.check(header_name='sys/types.h', features = 'c', mandatory = False)
    conf.check(header_name='sys/wait.h',  features = 'c', mandatory = False)
    conf.check(header_name='unistd.h',    features = 'c', mandatory = False)
    conf.check(header_name='vfork.h',     features = 'c', mandatory = False)

    conf.check_cc(function_name='getrusage',
                  header_name="sys/time.h sys/resource.h",
                  features = 'c', mandatory = False)

    conf.write_config_header('libiberty/config.h')

def bld_libiberty(bld):
    if sys.platform == 'win32':
        pex_host = 'libiberty/pex-win32.c'
    else:
        pex_host = 'libiberty/pex-unix.c'
    bld.stlib(target = 'iberty',
              features = 'c',
              includes = ['libiberty'],
              cflags = bld.cflags,
              defines = ['HAVE_CONFIG_H=1'],
              source =['libiberty/concat.c',
                       'libiberty/cplus-dem.c',
                       'libiberty/cp-demangle.c',
                       'libiberty/make-temp-file.c',
                       'libiberty/mkstemps.c',
                       'libiberty/safe-ctype.c',
                       'libiberty/stpcpy.c',
                       'libiberty/pex-common.c',
                       'libiberty/pex-one.c',
                       pex_host])

#
# From the demos. Use this to get the command to cut+paste to play.
#
def output_command_line():
    # first, display strings, people like them
    from waflib import Utils, Logs
    from waflib.Context import Context
    def exec_command(self, cmd, **kw):
        subprocess = Utils.subprocess
        kw['shell'] = isinstance(cmd, str)
        if isinstance(cmd, str):
            Logs.info('%s' % cmd)
        else:
            Logs.info('%s' % ' '.join(cmd)) # here is the change
        Logs.debug('runner_env: kw=%s' % kw)
        try:
            if self.logger:
                self.logger.info(cmd)
                kw['stdout'] = kw['stderr'] = subprocess.PIPE
                p = subprocess.Popen(cmd, **kw)
                (out, err) = p.communicate()
                if out:
                    self.logger.debug('out: %s' % out.decode(sys.stdout.encoding or 'iso8859-1'))
                if err:
                    self.logger.error('err: %s' % err.decode(sys.stdout.encoding or 'iso8859-1'))
                return p.returncode
            else:
                p = subprocess.Popen(cmd, **kw)
                return p.wait()
        except OSError:
            return -1
    Context.exec_command = exec_command

    # Change the outputs for tasks too
    from waflib.Task import Task
    def display(self):
        return '' # no output on empty strings

    Task.__str__ = display

#
# The doxy command.
#
from waflib import Build
class doxy(Build.BuildContext):
    fun = 'build'
    cmd = 'doxy'