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

from waflib import Build, Utils
import os

bld.new_task_gen (
    features = "subst",
    source= "net.launchpad.Diodon.gschema.xml.in.in",
    target= "net.launchpad.Diodon.gschema.xml.in",
    GETTEXT_PACKAGE = bld.env['GETTEXT_PACKAGE'],
    ACTIVE_PLUGINS = bld.env['ACTIVE_PLUGINS'])

bld.new_task_gen (
    features = 'intltool_in',
    podir = '.', # no translations should get added to gschema file
    source = 'net.launchpad.Diodon.gschema.xml.in',
    install_path = '',  # do not install it
    flags = ["-x", "-q", "-u", "-c"])
  
task = bld.new_task_gen (
    features = 'glib2')    
task.add_settings_schemas ('net.launchpad.Diodon.gschema.xml')

bld.new_task_gen (
    features = 'intltool_in',
    podir = '../po',
    source = 'diodon.desktop.in',
    flags = ["-d", "-q", "-u", "-c"],
    install_path = "${DATADIR}/applications")
  
bld.new_task_gen (source='diodon.pc.in')

bld.install_files('${SYSCONFDIR}/xdg/autostart', 'diodon.desktop')
bld.install_files('${DATADIR}/diodon', 'preferences.ui')
bld.install_files('${MANDIR}/man1', 'diodon.1.gz')

bld.install_files('${DATADIR}/apport/package-hooks', 'apport/source_diodon.py')
bld.install_files('${SYSCONFDIR}/apport/crashdb.conf.d/', 'apport/diodon-crashdb.conf')

# install all icons files into the according directory
icons_path = bld.path.find_dir('../data/icons')
icons = icons_path.ant_glob(incl='**/*')
for icon in icons:
    # difference between basedir and given dir
    relfile = icon.path_from(icons_path)
    pos = relfile.rfind(os.sep)
    subpath = ''
    if pos > -1:
        subpath = relfile[:pos]
    # add difference of path to install dir
    install_dir = '${DATADIR}/icons/' + subpath
    bld.install_files(install_dir, icon)

