#! /usr/bin/env python
# encoding: utf-8
#
# 
#    Ejecter - Safely, easily remove external peripherals
#    Copyright 2008-2009, Federico Pelloni <federico.pelloni@gmail.com>
# 
#    
#    This file is part of Ejecter.
# 
#    Ejecter is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    
#    Ejecter is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#    
#    You should have received a copy of the GNU General Public License
#    along with Ejecter.  If not, see <http://www.gnu.org/licenses/>.
#   
# 

import os, os.path, gnome

# the following two variables are used by the target "waf dist"
VERSION='0.3.1'
APPNAME='ejecter'

# these variables are mandatory ('/' are converted automatically)
srcdir = '.'
blddir = 'build'

import Scripting
Scripting.g_excludes = ('tools', )


def set_options(opt):
    opt.tool_options('compiler_cc')
    opt.tool_options('gnu_dirs')
    opt.add_option('--debug', action = 'store_true', default = False, help = 'Enable debugging messages')


def configure(conf):
    
    conf.check_tool('compiler_cc cc vala intltool gnu_dirs')
    
    conf.check_cfg(package='glib-2.0', uselib_store='GLIB', atleast_version='2.16.0', 
                   mandatory=1, args='--cflags --libs')
    conf.check_cfg(package='gtk+-2.0', uselib_store='GTK', atleast_version='2.14.0', 
                   mandatory=1, args='--cflags --libs')
    conf.check_cfg(package='gio-2.0', uselib_store='GIO', mandatory=1, args='--cflags --libs')
    conf.check_cfg(package='gdu', uselib_store='GDU', mandatory=1, args='--cflags --libs')
    
    required_vala = (0, 7, 0)
    conf.check_message_1("Checking for vala version >= %d.%d.%d" % required_vala)
    if conf.env['VALAC_VERSION'] >= required_vala:
        conf.check_message_2("ok (%d.%d.%d)" % conf.env['VALAC_VERSION'], "GREEN")
    else:
        conf.check_message_2("not found", "RED")
        conf.fatal("Vala %d.%d.%d or higher is required to build Ejecter" % required_vala)
        return
    
    conf.define('PACKAGE', APPNAME)
    conf.define('VERSION', VERSION)
    conf.define('PACKAGE_NAME', APPNAME)
    conf.define('PACKAGE_VERSION', APPNAME + '-' + VERSION)
    conf.define('GETTEXT_PACKAGE', APPNAME)
    conf.define('LOCALE_DIR', conf.env['LOCALEDIR'])
    conf.define('PIXMAPS_DIR', os.path.join(conf.env['DATADIR'], APPNAME, 'pixmaps'))
    conf.define('ICONS_DIR', os.path.join(conf.env['DATADIR'], 'icons'))
    
    import Options
    conf.define('DEBUG', int(Options.options.debug))
    
    conf.write_config_header("config.h")
    


def build(bld):

    if bld.env['INTLTOOL']:
        bld.add_subdirs('po')

    bld.add_subdirs('src')

    bld.add_subdirs('icons')

    bld.install_files(os.path.join('${DATADIR}', APPNAME), 'COPYING')
    
    bld.add_post_fun(lambda ctx: gnome.postinstall_icons())
    

