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

VERSION='0.0.1'
APPNAME='groups'

top = '.'
out = 'build'

import Options

# implement build stages, groups have task generators,
# all tasks in a group are processed before processing the next

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

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

	debugEnv = conf.env.copy()
	debugEnv.set_variant('debug')
	conf.set_env_name('debug', debugEnv)

	conf.setenv('debug')
	conf.env.append_value('CXXFLAGS', ['-O0', '-g3'])

from TaskGen import feature
import Options

def build(bld):

	if Options.options.compile_targets:
		# Give for example "waf --targets=g3"
		# the build groups before the group of g3 will be processed
		# for example, g3 may use g1 for some purpose

		# do not enable on all targets for it has has O(n2) behaviour

		@feature('*')
		def force_previous_groups(self):

			my_id = id(self)

			bld = self.bld
			for g in bld.task_manager.groups:
				for t in g.tasks_gen:
					if id(t) == my_id:
						stop = id(g)
						break

			for g in bld.task_manager.groups:
				if id(g) == stop:
					break
				for t in g.tasks_gen:
					t.post()


	bld.add_group('test1')
	bld.add_group('test2')
	bld.add_group('test3')
	bld.add_group('test4')

	#print "tadaaam"

	bld.set_group('test3')
	bld(features='cc cprogram', source='main3.c', target='g3')

	bld.set_group('test1')
	bld(features='cc cprogram', source='main1.c', target='g1')

	bld.set_group('test2')
	obj2 = bld(features='cc cprogram', source='main2.c', target='g2')

	bld.set_group('test4')
	obj2.clone('debug')

