#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2006 (ita)

VERSION='0.0.1'
APPNAME='d_test'

top = '.'
out = 'build'

def set_options(opt):
	opt.tool_options('compiler_d')

def configure(conf):
	conf.check_tool('compiler_d')

	if not conf.env.D_COMPILER:
		conf.fatal("either dmd or gdc is required (d compilers)")

	conf.env.LIB_PTHREAD = ['pthread']

def build(bld):
	bld.add_subdirs('src')

	# here is how to use the object-oriented notation
	obj = bld(features='d dstaticlib')
	obj.source = '''
	testlib/code.d
	'''
	obj.importpaths = '.'
	obj.name        = 'testlib'
	obj.target      = 'testlib'

	"""
	compiling with d, linking with gcc:
	* in the configuration, add conf.check_tool('gcc')
	* in the object creation, add 3 lines

	obj = bld('d')
	obj.source = '''
	testlib/code.d
	'''
	obj.features.append('cc')
	obj.features.append('cshlib')
	obj.name   = 'testlib'
	obj.target = 'testlib'
	"""

	obj = bld(features='d dprogram')
	obj.source = '''
	example.d
	'''
	obj.target       = 'd_test'
	obj.uselib_local = 'testlib'
	obj.uselib       = 'PTHREAD'
	obj.importpaths  = '.'


	# ---------------------------------------
	# to use in the development phase:
	# raise the syntax errors on the most dependent files first

	from Constants import RUN_ME
	from Task import Task, TaskBase

	def runnable_status(self):
		ret = Task.runnable_status(self)

		# do this processing once
		if ret != RUN_ME or getattr(self, 'deps_done', None):
			return ret

		# get the sibling d tasks
		for t in self.generator.tasks:
			if id(t) == id(self) or t.name != 'd':
				continue

			task_input_id = id(t.inputs[0])
			for node in self.generator.bld.node_deps[self.unique_id()]:
				if task_input_id == id(node):
					# if the input match, execute after the other
					self.set_run_after(t)

		self.deps_done = True
		return self.runnable_status()

	TaskBase.classes['d'].runnable_status = runnable_status

