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

"""
Compile 'about.c' after all other c tasks have been compiled

$ waf configure clean build
"""

VERSION='1.0.1'
APPNAME='cc_test'

top = '.'
out = 'build'

def options(opt):
	opt.load('compiler_c')

def configure(conf):
	conf.load('compiler_c')

def build(bld):
	bld.program(
		source   = 'main.c about.c',
		target   = 'app',
		includes = '.',
		use      = 'my_static_lib')

	bld.stlib(
		source   = 'test_staticlib.c',
		target   = 'my_static_lib')

import os
from waflib import Task
def runnable_status(self):
	if self.inputs[0].name == 'about.c':
		h = 0
		for g in self.generator.bld.groups:
			for tg in g:
				if isinstance(tg, Task.TaskBase):
					continue
				h = hash((self.generator.bld.hash_env_vars(self.generator.env, ['LINKFLAGS']), h))
				for tsk in getattr(tg, 'compiled_tasks', []): # all .c or .cpp compilations
					if id(tsk) == id(self):
						# but not 'about.c' (skip other tasks too if necessary)
						continue
					if not tsk.hasrun:
						return Task.ASK_LATER
					h = hash((tsk.signature(), h))
		self.env.CCDEPS = h

		try:
			os.stat(self.generator.link_task.outputs[0].abspath())
		except:
			return Task.RUN_ME

	return Task.Task.runnable_status(self)

from waflib.Tools.c import c
c.runnable_status = runnable_status

