#!/usr/bin/env python
#

import os

def build(bld):
	bld.add_group ("libclinica")
	prog = bld(features = 'c cshlib glib2', valaflags=[ "-g" ])
	bld.set_group ("libclinica")

	# Symbolic name used to reference this object
	prog.name = 'clinica.shlib'

	# Name of the resulting program
	prog.target = 'clinica'
	prog.vnum = "0.2.1"

	# Load all vala files in the current directory
	prog.source = filter (lambda source_file : (source_file.endswith(".vala") or source_file.endswith (".c")), 
			      os.listdir ("libclinica"))

	# prog.vapi_path = '.'
	prog.gir = 'Clinica-0.2'
	prog.includes = '.'

	# libraries to link against
	prog.uselib = 'GOBJECT PEAS GTK+ GEE SQLITE PEASGTK'

	# Vala packages to use
	prog.packages = 'gtk+-3.0 Peas-1.0 PeasGtk-1.0 sqlite3 gee-1.0 config posix'
	prog.vapi = 'clinica-0.2'

	# Extra vapi dirs
	prog.vapi_dirs = '../vapi'

	# Enable threading
	prog.threading = True

	# Create the typelib once the gir file has been generated
	bld (rule = '${G_IR_COMPILER} --shared-library=libclinica.so --output=${TGT} ${SRC}',
	     source = 'Clinica-0.2.gir',
	     target = 'Clinica-0.2.typelib',
	     install_path = '${PREFIX}/lib/girepository-1.0')

	# Install the schema file
	bld.install_files ('${PREFIX}/share/glib-2.0/schemas',
			   '../org.phcteam.clinica.gschema.xml')
	bld.add_post_fun (compile_schemas)

def compile_schemas (bld):	
	# If this is the install compile the schema
	if bld.options.destdir != '':
		destdir = bld.options.destdir
	else:
		destdir = '/'
	if bld.is_install:
		command = '%s %s/glib-2.0/schemas' % (
				bld.env['GLIB_COMPILE_SCHEMAS'],
				os.path.join (destdir, bld.env['DATADIR'][1:]))
		bld.exec_command (command)
	    


