# Path: waflib/TaskGen.py
# def extension(*k):
# 	"""
# 	Decorator that registers a task generator method which will be invoked during
# 	the processing of source files for the extension given::
# 
# 		from waflib import Task
# 		class mytask(Task):
# 			run_str = 'cp ${SRC} ${TGT}'
# 		@extension('.moo')
# 		def create_maa_file(self, node):
# 			self.create_task('mytask', node, node.change_ext('.maa'))
# 		def build(bld):
# 			bld(source='foo.moo')
# 	"""
# 	def deco(func):
# 		setattr(task_gen, func.__name__, func)
# 		for x in k:
# 			task_gen.mappings[x] = func
# 		return func
# 	return deco
# 
# def feature(*k):
# 	"""
# 	Decorator that registers a task generator method that will be executed when the
# 	object attribute ``feature`` contains the corresponding key(s)::
# 
# 		from waflib.Task import feature
# 		@feature('myfeature')
# 		def myfunction(self):
# 			print('that is my feature!')
# 		def build(bld):
# 			bld(features='myfeature')
# 
# 	:param k: feature names
# 	:type k: list of string
# 	"""
# 	def deco(func):
# 		setattr(task_gen, func.__name__, func)
# 		for name in k:
# 			feats[name].update([func.__name__])
# 		return func
# 	return deco
# 
# def after_method(*k):
# 	"""
# 	Decorator that registers a task generator method which will be executed
# 	after the functions of given name(s)::
# 
# 		from waflib.TaskGen import feature, after
# 		@feature('myfeature')
# 		@after_method('fun2')
# 		def fun1(self):
# 			print('feature 1!')
# 		@feature('myfeature')
# 		def fun2(self):
# 			print('feature 2!')
# 		def build(bld):
# 			bld(features='myfeature')
# 
# 	:param k: method names
# 	:type k: list of string
# 	"""
# 	def deco(func):
# 		setattr(task_gen, func.__name__, func)
# 		for fun_name in k:
# 			task_gen.prec[fun_name].add(func.__name__)
# 		return func
# 	return deco
# 
# Path: waflib/Configure.py
# def conf(f):
# 	"""
# 	Decorator: attach new configuration functions to :py:class:`waflib.Build.BuildContext` and
# 	:py:class:`waflib.Configure.ConfigurationContext`. The methods bound will accept a parameter
# 	named 'mandatory' to disable the configuration errors::
# 
# 		def configure(conf):
# 			conf.find_program('abc', mandatory=False)
# 
# 	:param f: method to bind
# 	:type f: function
# 	"""
# 	def fun(*k, **kw):
# 		mandatory = kw.pop('mandatory', True)
# 		try:
# 			return f(*k, **kw)
# 		except Errors.ConfigurationError:
# 			if mandatory:
# 				raise
# 
# 	fun.__name__ = f.__name__
# 	setattr(ConfigurationContext, f.__name__, fun)
# 	setattr(Build.BuildContext, f.__name__, fun)
# 	return f
# 
# Path: waflib/Tools/c_preproc.py
# class PreprocError(Errors.WafError):
# class c_parser(object):
# FILE_CACHE_SIZE = 100000
# LINE_CACHE_SIZE = 100000
# POPFILE = '-'
# NUM   = 'i'
# OP    = 'O'
# IDENT = 'T'
# STR   = 's'
# CHAR  = 'c'
# def repl(m):
# def reduce_nums(val_1, val_2, val_op):
# def get_num(lst):
# def get_term(lst):
# def reduce_eval(lst):
# def stringize(lst):
# def paste_tokens(t1, t2):
# def reduce_tokens(lst, defs, ban=[]):
# def eval_macro(lst, defs):
# def extract_macro(txt):
# def extract_include(txt, defs):
# def parse_char(txt):
# def tokenize(s):
# def tokenize_private(s):
# def format_defines(lst):
# 	def __init__(self, nodepaths=None, defines=None):
# 	def cached_find_resource(self, node, filename):
# 	def tryfind(self, filename, kind='"', env=None):
# 	def filter_comments(self, node):
# 	def parse_lines(self, node):
# 	def addlines(self, node):
# 	def start(self, node, env):
# 	def define_name(self, line):
# def scan(task):


import re
from waflib import Task, Logs
from waflib.TaskGen import extension, feature, after_method
from waflib.Configure import conf
from waflib.Tools import c_preproc
	cmd = swigbin + ['-version']
	Logs.debug('swig: Running swig command %r', cmd)
	reg_swig = re.compile(r'SWIG Version\s(.*)', re.M)
	swig_out = conf.cmd_and_log(cmd)
	swigver_tuple = tuple([int(s) for s in reg_swig.findall(swig_out)[0].split('.')])

	# Compare swig version with the minimum required
	result = (minver is None) or (swigver_tuple >= minver)

	if result:
		# Define useful environment variables
		swigver = '.'.join([str(x) for x in swigver_tuple[:2]])
		conf.env['SWIG_VERSION'] = swigver

	# Feedback
	swigver_full = '.'.join(map(str, swigver_tuple[:3]))
	if minver is None:
		conf.msg('Checking for swig version', swigver_full)
	else:
		minver_str = '.'.join(map(str, minver))
		conf.msg('Checking for swig version >= %s' % (minver_str,), swigver_full, color=result and 'GREEN' or 'YELLOW')

	if not result:
		conf.fatal('The swig version is too old, expecting %r' % (minver,))

	return swigver_tuple

def configure(conf):
	conf.find_program('swig', var='SWIG')
	conf.env.SWIGPATH_ST = '-I%s'

# Path: waflib/TaskGen.py
# def extension(*k):
# 	"""
# 	Decorator that registers a task generator method which will be invoked during
# 	the processing of source files for the extension given::
# 
# 		from waflib import Task
# 		class mytask(Task):
# 			run_str = 'cp ${SRC} ${TGT}'
# 		@extension('.moo')
# 		def create_maa_file(self, node):
# 			self.create_task('mytask', node, node.change_ext('.maa'))
# 		def build(bld):
# 			bld(source='foo.moo')
# 	"""
# 	def deco(func):
# 		setattr(task_gen, func.__name__, func)
# 		for x in k:
# 			task_gen.mappings[x] = func
# 		return func
# 	return deco
# 
# def feature(*k):
# 	"""
# 	Decorator that registers a task generator method that will be executed when the
# 	object attribute ``feature`` contains the corresponding key(s)::
# 
# 		from waflib.Task import feature
# 		@feature('myfeature')
# 		def myfunction(self):
# 			print('that is my feature!')
# 		def build(bld):
# 			bld(features='myfeature')
# 
# 	:param k: feature names
# 	:type k: list of string
# 	"""
# 	def deco(func):
# 		setattr(task_gen, func.__name__, func)
# 		for name in k:
# 			feats[name].update([func.__name__])
# 		return func
# 	return deco
# 
# def after_method(*k):
# 	"""
# 	Decorator that registers a task generator method which will be executed
# 	after the functions of given name(s)::
# 
# 		from waflib.TaskGen import feature, after
# 		@feature('myfeature')
# 		@after_method('fun2')
# 		def fun1(self):
# 			print('feature 1!')
# 		@feature('myfeature')
# 		def fun2(self):
# 			print('feature 2!')
# 		def build(bld):
# 			bld(features='myfeature')
# 
# 	:param k: method names
# 	:type k: list of string
# 	"""
# 	def deco(func):
# 		setattr(task_gen, func.__name__, func)
# 		for fun_name in k:
# 			task_gen.prec[fun_name].add(func.__name__)
# 		return func
# 	return deco
# 
# Path: waflib/Configure.py
# def conf(f):
# 	"""
# 	Decorator: attach new configuration functions to :py:class:`waflib.Build.BuildContext` and
# 	:py:class:`waflib.Configure.ConfigurationContext`. The methods bound will accept a parameter
# 	named 'mandatory' to disable the configuration errors::
# 
# 		def configure(conf):
# 			conf.find_program('abc', mandatory=False)
# 
# 	:param f: method to bind
# 	:type f: function
# 	"""
# 	def fun(*k, **kw):
# 		mandatory = kw.pop('mandatory', True)
# 		try:
# 			return f(*k, **kw)
# 		except Errors.ConfigurationError:
# 			if mandatory:
# 				raise
# 
# 	fun.__name__ = f.__name__
# 	setattr(ConfigurationContext, f.__name__, fun)
# 	setattr(Build.BuildContext, f.__name__, fun)
# 	return f
# 
# Path: waflib/Tools/c_preproc.py
# class PreprocError(Errors.WafError):
# class c_parser(object):
# FILE_CACHE_SIZE = 100000
# LINE_CACHE_SIZE = 100000
# POPFILE = '-'
# NUM   = 'i'
# OP    = 'O'
# IDENT = 'T'
# STR   = 's'
# CHAR  = 'c'
# def repl(m):
# def reduce_nums(val_1, val_2, val_op):
# def get_num(lst):
# def get_term(lst):
# def reduce_eval(lst):
# def stringize(lst):
# def paste_tokens(t1, t2):
# def reduce_tokens(lst, defs, ban=[]):
# def eval_macro(lst, defs):
# def extract_macro(txt):
# def extract_include(txt, defs):
# def parse_char(txt):
# def tokenize(s):
# def tokenize_private(s):
# def format_defines(lst):
# 	def __init__(self, nodepaths=None, defines=None):
# 	def cached_find_resource(self, node, filename):
# 	def tryfind(self, filename, kind='"', env=None):
# 	def filter_comments(self, node):
# 	def parse_lines(self, node):
# 	def addlines(self, node):
# 	def start(self, node, env):
# 	def define_name(self, line):
# def scan(task):


# Path: waflib/extras/swig.py
import re
from waflib import Task, Logs
from waflib.TaskGen import extension, feature, after_method
from waflib.Configure import conf
from waflib.Tools import c_preproc

	cmd = swigbin + ['-version']
	Logs.debug('swig: Running swig command %r', cmd)
	reg_swig = re.compile(r'SWIG Version\s(.*)', re.M)
	swig_out = conf.cmd_and_log(cmd)
	swigver_tuple = tuple([int(s) for s in reg_swig.findall(swig_out)[0].split('.')])

	# Compare swig version with the minimum required
	result = (minver is None) or (swigver_tuple >= minver)

	if result:
		# Define useful environment variables
		swigver = '.'.join([str(x) for x in swigver_tuple[:2]])
		conf.env['SWIG_VERSION'] = swigver

	# Feedback
	swigver_full = '.'.join(map(str, swigver_tuple[:3]))
	if minver is None:
		conf.msg('Checking for swig version', swigver_full)
	else:
		minver_str = '.'.join(map(str, minver))
		conf.msg('Checking for swig version >= %s' % (minver_str,), swigver_full, color=result and 'GREEN' or 'YELLOW')

	if not result:
		conf.fatal('The swig version is too old, expecting %r' % (minver,))

	return swigver_tuple

def configure(conf):
	conf.find_program('swig', var='SWIG')
	conf.env.SWIGPATH_ST = '-I%s'

	conf.env.SWIGDEF_ST = '-D%s'