#! /usr/bin/env python
# encoding: utf-8

from waflib import Build, Utils
import os

# FIXME: there must be an easier way to install a directory recursively
# best option would be to add an install option to valadoc task itself
def signature_task(task):
    bld = task.generator.bld

    path = bld.path.find_or_declare('../_build_/doc/html')
    for x in path.ant_glob('**/*', remove=False):
        x.sig = Utils.h_file(x.abspath())

doc = bld.new_task_gen (
    features = 'valadoc',
    output_dir = '../doc/html',
    package_name = bld.env['PACKAGE_NAME'],
    package_version = bld.env['VERSION'],
    packages = 'gtk+-3.0 gdk-x11-3.0 libpeas-gtk-1.0 libpeas-1.0 config xtst gdk-3.0',
    vapi_dirs = '../vapi',
    force = True)

path = bld.path.find_dir ('../libdiodon')
doc.files = path.ant_glob (incl='**/*.vala')

output_dir = bld.path.find_or_declare('../doc/html')
output_dir.mkdir()

# install all html files into the according directory
nodes = output_dir.ant_glob(incl='**/*')
for node in nodes:
    # difference between basedir and given dir
    relfile = node.path_from(output_dir)
    pos = relfile.rfind(os.sep)
    subpath = ''
    if pos > -1:
        subpath = relfile[:pos]
    # add difference of path to install dir
    install_dir = '${PREFIX}/share/doc/diodon-dev/html/' + subpath
    bld.install_files(install_dir, node)

bld.post_mode = Build.POST_LAZY
bld.add_group()

bld.new_task_gen(
  name = 'signature_task',
  always = True,
  rule = signature_task)

