
def configure(ctx):
    pass

def build(bld):
    from os.path import join

    sources = bld.path.ant_glob("**/*.cpp")
    sources += bld.path.ant_glob("**/*.s")

    lds = join(bld.env.ARCH_D, 'kernel.ld')

    bld.program(
        source = sources,
        name = 'kernel',
        includes = '.',
        target = bld.env.KERNEL_FILENAME,
        use = 'kutil',
        linkflags = "-T {}".format(lds),
    )

    from waflib.Task import Task
    class objdump(Task):
        color = 'PINK'
        def keyword(self):
            return "Dumping"
        def __str__(self):
            node = self.outputs[0]
            return node.path_from(node.ctx.launch_node())
        def run(self):
            from subprocess import check_output
            args = self.env.objdump + ["--source", "-D", self.inputs[0].abspath()]
            with file(self.outputs[0].abspath(), 'w') as output:
                output.write(check_output(args))

    out = bld.path.get_bld()

    dump = objdump(env=bld.env)
    dump.set_inputs([out.make_node(bld.env.KERNEL_FILENAME)])
    dump.set_outputs([out.make_node("kernel.dump")])
    bld.add_to_group(dump)

# vim: ft=python et
