S
S
Semyon Prikhodko2013-09-05 00:49:00
Python
Semyon Prikhodko, 2013-09-05 00:49:00

Waf: Node is created more than once

I decided to replace Make in my project with something more modern, preferably based on Python. There were few options: Scons and Waf. The first one, on a superficial examination, seemed somewhat chaotic, and, moreover, not very "Pythonic". I liked Waf more, it seemed more thoughtful, and decided to stop on it for now.

What I'm trying to do is:
1. compile boot32.cc (32-bit code passed to grub2)
2. convert boot32.o from elf32 to elf64 for future linking with the rest of the 64-bit code
3. compile all other 64-bit sources (*.cc) in the folder
4. run the linking script template through the C preprocessor
4. link the resulting object files into the kernel binary

I have the following wscript:

APPNAME = 'Toy OS'
VERSION = '0.4'

SUPPORTED_ARCHS = ['x86_64']
DEFAULT_ARCH = 'x86_64'

SUPPORTED_CXXS = ['clang++', 'g++']
DEFAULT_CXX = 'clang++'

SUPPORTED_OPTS = ['0', '1', '3']
DEFAULT_OPT = '3'

def options(opt):
    opt.load('compiler_cxx')

    grp = opt.get_option_group('configure options')
    grp.add_option('', '--arch', dest='arch', default=DEFAULT_ARCH,
                   help="target architecture [default: '%s']" % DEFAULT_ARCH)
    grp.add_option('', '--cxx', dest='CXX', default=DEFAULT_CXX,
                   help="C++ compiler command [default: '%s']" % DEFAULT_CXX)
    grp.add_option('', '--opt', dest='opt', default=DEFAULT_OPT,
                   help="code optimization level [default: '%s']" %DEFAULT_OPT)
    grp.add_option('-d', '--debug', dest='debug', default=False,
                   action='store_true', help='produce debug builds')


def configure(conf):
    conf.load('compiler_cxx')
    conf.find_program('cpp')
    conf.find_program('objcopy')

    options = vars(conf.options)
    cases = [('arch', 'target architecture', SUPPORTED_ARCHS),
             ('CXX', 'C++ compiler', SUPPORTED_CXXS),
             ('opt', 'code optimization level', SUPPORTED_OPTS)]
    for name, desc, supported, in cases:
        if options[name] not in supported:
            conf.fatal('Unsupported %s: %s' % (desc, options[name]))
        conf.env[name] = options[name]
    conf.env.debug = conf.options.debug

    flags = ['-std=c++0x', '-Wall', '-Wextra', '-O%s' % conf.env.opt,
             '-DARCH=%s' % conf.env.arch ]
    if conf.env.debug:
        flags += ['-DDEBUG']
    if conf.env.arch == 'x86_64':
        flags += ['-fno-stack-protector']
        conf.env.cxxflags_boot32 = flags + ['-m32']
        flags += ['-m64']
    conf.env.CXXFLAGS = flags

    conf.env.SHLIB_MARKER, conf.env.STLIB_MARKER = '', ''
    conf.env.LINKFLAGS = ['-nostdlib', '-Wl,--build-id=none',
                          '-Tsrc/%s/linker_script.lds' % conf.env.arch]


def build(bld):
    source, use = [], []
    if bld.env.arch == 'x86_64':
        boot32  = 'src/x86_64/boot32.cc'
        env, env.CXXFLAGS = bld.env.derive(), bld.env.cxxflags_boot32
        bld.objects(source=boot32, target=boot32+'.1.o', env=env)
        bld(rule='objcopy -O elf64-x86-64 ${SRC} ${TGT}',
            source=boot32+'.1.o', target=boot32+'.2.o')
        source += [boot32+'.2.o']

        bld.objects(source=bld.path.ant_glob('src/x86_64/*.cc', excl=boot32),
                    target='objs_x86_64')
        use += ['objs_x86_64']

    lds = 'src/%s/linker_script' % bld.env.arch
    bld(source=lds, target=lds+'.lds', rule='cpp -E -P ${SRC} > ${TGT}')

    bld.program(source=source, use=use, target='toy.bin')

At the output, everything is assembled without errors (sort of), but in verbose mode, waf writes:

* Node /home/ababo/Dropbox/toy/build/src/x86_64/boot32.cc.2.o is created more than once (full message on 'waf -v -v'). The task generators are:
1. 'src/x86_64/boot32.cc.2.o' in /home/ababo/Dropbox/toy
2. 'toy.bin' in /home/ababo/Dropbox/toy

Why does Waf think that does linking recreate boot32.cc.2.o? I have a suspicion that I am doing something wrong (in terms of Waf ideology). In this case, I will be glad if you explain. Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question