#! /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

# the following two variables are used by the target "waf dist"
VERSION='0.2.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.add_option('--debug', action = 'store_true', default = False, help = 'Enable debugging messages')


def configure(conf):
    
    conf.check_tool('compiler_cc cc vala intltool')
    
    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.12.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='hal', uselib_store='HAL', mandatory=1, args='--cflags --libs')
    conf.check_cfg(package='dbus-glib-1', uselib_store='DBUSGLIB', atleast_version='0.60', 
                   mandatory=True, args='--cflags --libs')
    conf.check_cfg(package='', msg='Checking for gtk+ version >= 2.14', args='"gtk+-2.0 >= 2.14.0"',
                   errmsg='no', uselib_store='GTK214') 
    
    required_vala = (0, 3, 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', os.path.join(conf.env['PREFIX'], 'share', 'locale'))
    conf.define('PIXMAPS_DIR', os.path.join(conf.env['PREFIX'], 'share', APPNAME, 'pixmaps'))
    
    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('${PREFIX}/share/' + APPNAME, 'COPYING')
    

