Index: waflib/Tools/ar.py
===================================================================
--- waflib/Tools/ar.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/ar.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -9,3 +9,5 @@
 def configure(conf):
 	conf.find_program('ar',var='AR')
-	conf.env.ARFLAGS='rcs'
+	conf.add_os_flags('ARFLAGS')
+	if not conf.env.ARFLAGS:
+		conf.env.ARFLAGS=['rcs']
Index: waflib/Tools/asm.py
===================================================================
--- waflib/Tools/asm.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/asm.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -10,5 +10,5 @@
 class asm(Task.Task):
 	color='BLUE'
-	run_str='${AS} ${ASFLAGS} ${ASMPATH_ST:INCPATHS} ${AS_SRC_F}${SRC} ${AS_TGT_F}${TGT}'
+	run_str='${AS} ${ASFLAGS} ${ASMPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${AS_SRC_F}${SRC} ${AS_TGT_F}${TGT}'
 @extension('.s','.S','.asm','.ASM','.spp','.SPP')
 def asm_hook(self,node):
Index: waflib/Tools/c.py
===================================================================
--- waflib/Tools/c.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/c.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -8,7 +8,9 @@
 @TaskGen.extension('.c')
 def c_hook(self,node):
+	if not self.env.CC and self.env.CXX:
+		return self.create_compiled_task('cxx',node)
 	return self.create_compiled_task('c',node)
 class c(Task.Task):
-	run_str='${CC} ${ARCH_ST:ARCH} ${CFLAGS} ${CPPFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CC_SRC_F}${SRC} ${CC_TGT_F}${TGT}'
+	run_str='${CC} ${ARCH_ST:ARCH} ${CFLAGS} ${CPPFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CC_SRC_F}${SRC} ${CC_TGT_F}${TGT[0].abspath()}'
 	vars=['CCDEPS']
 	ext_in=['.h']
Index: waflib/Tools/c_aliases.py
===================================================================
--- waflib/Tools/c_aliases.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/c_aliases.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -30,7 +30,7 @@
 	if'java'in exts:
 		return'java'
-	if type in['program','shlib','stlib']:
+	if type in('program','shlib','stlib'):
 		for x in feats:
-			if x in['cxx','d','c']:
+			if x in('cxx','d','c'):
 				feats.append(x+type)
 	return feats
Index: waflib/Tools/c_config.py
===================================================================
--- waflib/Tools/c_config.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/c_config.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -44,13 +44,17 @@
 MACRO_TO_DEST_CPU={'__x86_64__':'x86_64','__amd64__':'x86_64','__i386__':'x86','__ia64__':'ia','__mips__':'mips','__sparc__':'sparc','__alpha__':'alpha','__aarch64__':'aarch64','__thumb__':'thumb','__arm__':'arm','__hppa__':'hppa','__powerpc__':'powerpc','__ppc__':'powerpc','__convex__':'convex','__m68k__':'m68k','__s390x__':'s390x','__s390__':'s390','__sh__':'sh',}
 @conf
-def parse_flags(self,line,uselib_store,env=None,force_static=False):
+def parse_flags(self,line,uselib_store,env=None,force_static=False,posix=None):
 	assert(isinstance(line,str))
 	env=env or self.env
-	app=env.append_value
-	appu=env.append_unique
-	lex=shlex.shlex(line,posix=False)
+	if posix is None:
+		posix=True
+		if'\\'in line:
+			posix=('\\ 'in line)or('\\\\'in line)
+	lex=shlex.shlex(line,posix=posix)
 	lex.whitespace_split=True
 	lex.commenters=''
 	lst=list(lex)
+	app=env.append_value
+	appu=env.append_unique
 	uselib=uselib_store
 	while lst:
@@ -61,5 +65,5 @@
 			if not ot:ot=lst.pop(0)
 			appu('INCLUDES_'+uselib,[ot])
-		elif st=='-include':
+		elif st=='-i':
 			tmp=[x,lst.pop(0)]
 			app('CFLAGS',tmp)
@@ -85,4 +89,10 @@
 		elif x.startswith('-F'):
 			appu('FRAMEWORKPATH_'+uselib,[x[2:]])
+		elif x=='-Wl,-rpath':
+			app('RPATH_'+uselib,lst.pop(0))
+		elif x.startswith('-Wl,-R'):
+			app('RPATH_'+uselib,x[6:])
+		elif x.startswith('-Wl,-rpath,'):
+			app('RPATH_'+uselib,x[11:])
 		elif x.startswith('-Wl'):
 			app('LINKFLAGS_'+uselib,[x])
@@ -92,5 +102,5 @@
 		elif x.startswith('-bundle'):
 			app('LINKFLAGS_'+uselib,[x])
-		elif x.startswith('-undefined'):
+		elif x.startswith('-undefined')or x.startswith('-Xlinker'):
 			arg=lst.pop(0)
 			app('LINKFLAGS_'+uselib,[x,arg])
@@ -102,9 +112,4 @@
 		elif x.endswith('.a')or x.endswith('.so')or x.endswith('.dylib')or x.endswith('.lib'):
 			appu('LINKFLAGS_'+uselib,[x])
-@conf
-def ret_msg(self,f,kw):
-	if isinstance(f,str):
-		return f
-	return f(kw)
 @conf
 def validate_cfg(self,kw):
@@ -133,12 +138,23 @@
 				kw['msg']='Checking for %r %s %s'%(kw['package'],cfg_ver[x],kw[y])
 			return
+	if not'define_name'in kw:
+		pkgname=kw.get('uselib_store',kw['package'].upper())
+		kw['define_name']=self.have_define(pkgname)
+	if not'uselib_store'in kw:
+		self.undefine(kw['define_name'])
 	if not'msg'in kw:
 		kw['msg']='Checking for %r'%(kw['package']or kw['path'])
 @conf
 def exec_cfg(self,kw):
+	path=Utils.to_list(kw['path'])
 	def define_it():
-		self.define(self.have_define(kw.get('uselib_store',kw['package'])),1,0)
+		pkgname=kw.get('uselib_store',kw['package'].upper())
+		if kw.get('global_define'):
+			self.define(self.have_define(kw['package']),1,False)
+		else:
+			self.env.append_unique('DEFINES_%s'%pkgname,"%s=1"%self.have_define(pkgname))
+		self.env[self.have_define(pkgname)]=1
 	if'atleast_pkgconfig_version'in kw:
-		cmd=[kw['path'],'--atleast-pkgconfig-version=%s'%kw['atleast_pkgconfig_version']]
+		cmd=path+['--atleast-pkgconfig-version=%s'%kw['atleast_pkgconfig_version']]
 		self.cmd_and_log(cmd)
 		if not'okmsg'in kw:
@@ -148,5 +164,5 @@
 		y=x.replace('-','_')
 		if y in kw:
-			self.cmd_and_log([kw['path'],'--%s=%s'%(x,kw[y]),kw['package']])
+			self.cmd_and_log(path+['--%s=%s'%(x,kw[y]),kw['package']])
 			if not'okmsg'in kw:
 				kw['okmsg']='yes'
@@ -154,8 +170,8 @@
 			break
 	if'modversion'in kw:
-		version=self.cmd_and_log([kw['path'],'--modversion',kw['modversion']]).strip()
+		version=self.cmd_and_log(path+['--modversion',kw['modversion']]).strip()
 		self.define('%s_VERSION'%Utils.quote_define_name(kw.get('uselib_store',kw['modversion'])),version)
 		return version
-	lst=[kw['path']]
+	lst=[]+path
 	defi=kw.get('define_variable',None)
 	if not defi:
@@ -163,5 +179,5 @@
 	for key,val in defi.items():
 		lst.append('--define-variable=%s=%s'%(key,val))
-	static=False
+	static=kw.get('force_static',False)
 	if'args'in kw:
 		args=Utils.to_list(kw['args'])
@@ -185,5 +201,5 @@
 		kw['okmsg']='yes'
 	define_it()
-	self.parse_flags(ret,kw.get('uselib_store',kw['package'].upper()),kw.get('env',self.env),force_static=static)
+	self.parse_flags(ret,kw.get('uselib_store',kw['package'].upper()),kw.get('env',self.env),force_static=static,posix=kw.get('posix',None))
 	return ret
 @conf
@@ -195,5 +211,5 @@
 	self.validate_cfg(kw)
 	if'msg'in kw:
-		self.start_msg(kw['msg'])
+		self.start_msg(kw['msg'],**kw)
 	ret=None
 	try:
@@ -201,5 +217,5 @@
 	except self.errors.WafError:
 		if'errmsg'in kw:
-			self.end_msg(kw['errmsg'],'YELLOW')
+			self.end_msg(kw['errmsg'],'YELLOW',**kw)
 		if Logs.verbose>1:
 			raise
@@ -207,10 +223,23 @@
 			self.fatal('The configuration failed')
 	else:
+		if not ret:
+			ret=True
 		kw['success']=ret
 		if'okmsg'in kw:
-			self.end_msg(self.ret_msg(kw['okmsg'],kw))
+			self.end_msg(self.ret_msg(kw['okmsg'],kw),**kw)
 	return ret
+def build_fun(bld):
+	if bld.kw['compile_filename']:
+		node=bld.srcnode.make_node(bld.kw['compile_filename'])
+		node.write(bld.kw['code'])
+	o=bld(features=bld.kw['features'],source=bld.kw['compile_filename'],target='testprog')
+	for k,v in bld.kw.items():
+		setattr(o,k,v)
+	if not bld.kw.get('quiet',None):
+		bld.conf.to_log("==>\n%s\n<=="%bld.kw['code'])
 @conf
 def validate_c(self,kw):
+	if not'build_fun'in kw:
+		kw['build_fun']=build_fun
 	if not'env'in kw:
 		kw['env']=self.env.derive()
@@ -307,5 +336,5 @@
 		if not'errmsg'in kw:
 			kw['errmsg']='no'
-	for(flagsname,flagstype)in[('cxxflags','compiler'),('cflags','compiler'),('linkflags','linker')]:
+	for(flagsname,flagstype)in(('cxxflags','compiler'),('cflags','compiler'),('linkflags','linker')):
 		if flagsname in kw:
 			if not'msg'in kw:
@@ -369,10 +398,10 @@
 def check(self,*k,**kw):
 	self.validate_c(kw)
-	self.start_msg(kw['msg'])
+	self.start_msg(kw['msg'],**kw)
 	ret=None
 	try:
-		ret=self.run_c_code(*k,**kw)
+		ret=self.run_build(*k,**kw)
 	except self.errors.ConfigurationError:
-		self.end_msg(kw['errmsg'],'YELLOW')
+		self.end_msg(kw['errmsg'],'YELLOW',**kw)
 		if Logs.verbose>1:
 			raise
@@ -383,8 +412,8 @@
 	ret=self.post_check(*k,**kw)
 	if not ret:
-		self.end_msg(kw['errmsg'],'YELLOW')
+		self.end_msg(kw['errmsg'],'YELLOW',**kw)
 		self.fatal('The configuration failed %r'%ret)
 	else:
-		self.end_msg(self.ret_msg(kw['okmsg'],kw))
+		self.end_msg(self.ret_msg(kw['okmsg'],kw),**kw)
 	return ret
 class test_exec(Task.Task):
@@ -409,62 +438,4 @@
 def test_exec_fun(self):
 	self.create_task('test_exec',self.link_task.outputs[0])
-CACHE_RESULTS=1
-COMPILE_ERRORS=2
-@conf
-def run_c_code(self,*k,**kw):
-	lst=[str(v)for(p,v)in kw.items()if p!='env']
-	h=Utils.h_list(lst)
-	dir=self.bldnode.abspath()+os.sep+(not Utils.is_win32 and'.'or'')+'conf_check_'+Utils.to_hex(h)
-	try:
-		os.makedirs(dir)
-	except OSError:
-		pass
-	try:
-		os.stat(dir)
-	except OSError:
-		self.fatal('cannot use the configuration test folder %r'%dir)
-	cachemode=getattr(Options.options,'confcache',None)
-	if cachemode==CACHE_RESULTS:
-		try:
-			proj=ConfigSet.ConfigSet(os.path.join(dir,'cache_run_c_code'))
-		except OSError:
-			pass
-		else:
-			ret=proj['cache_run_c_code']
-			if isinstance(ret,str)and ret.startswith('Test does not build'):
-				self.fatal(ret)
-			return ret
-	bdir=os.path.join(dir,'testbuild')
-	if not os.path.exists(bdir):
-		os.makedirs(bdir)
-	self.test_bld=bld=Build.BuildContext(top_dir=dir,out_dir=bdir)
-	bld.init_dirs()
-	bld.progress_bar=0
-	bld.targets='*'
-	if kw['compile_filename']:
-		node=bld.srcnode.make_node(kw['compile_filename'])
-		node.write(kw['code'])
-	bld.logger=self.logger
-	bld.all_envs.update(self.all_envs)
-	bld.env=kw['env']
-	o=bld(features=kw['features'],source=kw['compile_filename'],target='testprog')
-	for k,v in kw.items():
-		setattr(o,k,v)
-	self.to_log("==>\n%s\n<=="%kw['code'])
-	bld.targets='*'
-	ret=-1
-	try:
-		try:
-			bld.compile()
-		except Errors.WafError:
-			ret='Test does not build: %s'%Utils.ex_stack()
-			self.fatal(ret)
-		else:
-			ret=getattr(bld,'retval',0)
-	finally:
-		proj=ConfigSet.ConfigSet()
-		proj['cache_run_c_code']=ret
-		proj.store(os.path.join(dir,'cache_run_c_code'))
-	return ret
 @conf
 def check_cxx(self,*k,**kw):
@@ -530,7 +501,5 @@
 	return(self.env.HAVE_PAT or'HAVE_%s')%Utils.quote_define_name(key)
 @conf
-def write_config_header(self,configfile='',guard='',top=False,env=None,defines=True,headers=False,remove=True,define_prefix=''):
-	if env:
-		Logs.warn('Cannot pass env to write_config_header')
+def write_config_header(self,configfile='',guard='',top=False,defines=True,headers=False,remove=True,define_prefix=''):
 	if not configfile:configfile=WAF_CONFIG_H
 	waf_guard=guard or'W_%s_WAF'%Utils.quote_define_name(configfile)
@@ -555,10 +524,14 @@
 			lst.append('#include <%s>'%x)
 	if defines:
-		for x in self.env[DEFKEYS]:
-			if self.is_defined(x):
-				val=self.get_define(x)
-				lst.append('#define %s %s'%(define_prefix+x,val))
-			else:
-				lst.append('/* #undef %s */'%(define_prefix+x))
+		tbl={}
+		for k in self.env['DEFINES']:
+			a,_,b=k.partition('=')
+			tbl[a]=b
+		for k in self.env[DEFKEYS]:
+			try:
+				txt='#define %s%s %s'%(define_prefix,k,tbl[k])
+			except KeyError:
+				txt='/* #undef %s%s */'%(define_prefix,k)
+			lst.append(txt)
 	return"\n".join(lst)
 @conf
@@ -585,5 +558,5 @@
 	conf.load('cxx')
 @conf
-def get_cc_version(conf,cc,gcc=False,icc=False):
+def get_cc_version(conf,cc,gcc=False,icc=False,clang=False):
 	cmd=cc+['-dM','-E','-']
 	env=conf.env.env or None
@@ -603,6 +576,10 @@
 	if icc and out.find('__INTEL_COMPILER')<0:
 		conf.fatal('Not icc/icpc')
+	if clang and out.find('__clang__')<0:
+		conf.fatal('Not clang/clang++')
+	if not clang and out.find('__clang__')>=0:
+		conf.fatal('Could not find g++, if renamed try eg: CXX=g++48 waf configure')
 	k={}
-	if icc or gcc:
+	if icc or gcc or clang:
 		out=out.splitlines()
 		for line in out:
@@ -646,7 +623,13 @@
 		else:
 			if isD('__clang__'):
-				conf.env['CC_VERSION']=(k['__clang_major__'],k['__clang_minor__'],k['__clang_patchlevel__'])
+				try:
+					conf.env['CC_VERSION']=(k['__clang_major__'],k['__clang_minor__'],k['__clang_patchlevel__'])
+				except KeyError:
+					conf.env['CC_VERSION']=(k['__GNUC__'],k['__GNUC_MINOR__'],k['__GNUC_PATCHLEVEL__'])
 			else:
-				conf.env['CC_VERSION']=(k['__GNUC__'],k['__GNUC_MINOR__'],k['__GNUC_PATCHLEVEL__'])
+				try:
+					conf.env['CC_VERSION']=(k['__GNUC__'],k['__GNUC_MINOR__'],k['__GNUC_PATCHLEVEL__'])
+				except KeyError:
+					conf.env['CC_VERSION']=(k['__GNUC__'],k['__GNUC_MINOR__'],0)
 	return k
 @conf
@@ -688,5 +671,5 @@
 def add_as_needed(self):
 	if self.env.DEST_BINFMT=='elf'and'gcc'in(self.env.CXX_NAME,self.env.CC_NAME):
-		self.env.append_unique('LINKFLAGS','--as-needed')
+		self.env.append_unique('LINKFLAGS','-Wl,--as-needed')
 class cfgtask(Task.TaskBase):
 	def display(self):
@@ -709,10 +692,8 @@
 @conf
 def multicheck(self,*k,**kw):
-	self.start_msg(kw.get('msg','Executing %d configuration tests'%len(k)))
+	self.start_msg(kw.get('msg','Executing %d configuration tests'%len(k)),**kw)
 	class par(object):
 		def __init__(self):
 			self.keep=False
-			self.cache_global=Options.cache_global
-			self.nocache=Options.options.nocache
 			self.returned_tasks=[]
 			self.task_sigs={}
@@ -742,5 +723,5 @@
 	for x in tasks:
 		if x.hasrun!=Task.SUCCESS:
-			self.end_msg(kw.get('errmsg','no'),color='YELLOW')
+			self.end_msg(kw.get('errmsg','no'),color='YELLOW',**kw)
 			self.fatal(kw.get('fatalmsg',None)or'One of the tests has failed, see the config.log for more information')
-	self.end_msg('ok')
+	self.end_msg('ok',**kw)
Index: waflib/Tools/c_preproc.py
===================================================================
--- waflib/Tools/c_preproc.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/c_preproc.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -16,5 +16,5 @@
 use_trigraphs=0
 strict_quotes=0
-g_optrans={'not':'!','and':'&&','bitand':'&','and_eq':'&=','or':'||','bitor':'|','or_eq':'|=','xor':'^','xor_eq':'^=','compl':'~',}
+g_optrans={'not':'!','not_eq':'!','and':'&&','and_eq':'&=','or':'||','or_eq':'|=','xor':'^','xor_eq':'^=','bitand':'&','bitor':'|','compl':'~',}
 re_lines=re.compile('^[ \t]*(#|%:)[ \t]*(ifdef|ifndef|if|else|elif|endif|include|import|define|undef|pragma)[ \t]*(.*)\r*$',re.IGNORECASE|re.MULTILINE)
 re_mac=re.compile("^[a-zA-Z_]\w*")
@@ -72,15 +72,15 @@
 	elif d=='/':c=a/b
 	elif d=='^':c=a^b
-	elif d=='|':c=a|b
-	elif d=='||':c=int(a or b)
-	elif d=='&':c=a&b
-	elif d=='&&':c=int(a and b)
 	elif d=='==':c=int(a==b)
-	elif d=='!=':c=int(a!=b)
+	elif d=='|'or d=='bitor':c=a|b
+	elif d=='||'or d=='or':c=int(a or b)
+	elif d=='&'or d=='bitand':c=a&b
+	elif d=='&&'or d=='and':c=int(a and b)
+	elif d=='!='or d=='not_eq':c=int(a!=b)
+	elif d=='^'or d=='xor':c=int(a^b)
 	elif d=='<=':c=int(a<=b)
 	elif d=='<':c=int(a<b)
 	elif d=='>':c=int(a>b)
 	elif d=='>=':c=int(a>=b)
-	elif d=='^':c=int(a^b)
 	elif d=='<<':c=a<<b
 	elif d=='>>':c=a>>b
@@ -382,5 +382,6 @@
 	else:
 		if toks[0][1]=='<'and toks[-1][1]=='>':
-			return stringize(toks).lstrip('<').rstrip('>')
+			ret='<',stringize(toks).lstrip('<').rstrip('>')
+			return ret
 	raise PreprocError("could not parse include %s."%txt)
 def parse_char(txt):
@@ -411,5 +412,7 @@
 			if v:
 				if name==IDENT:
-					try:v=g_optrans[v];name=OP
+					try:
+						g_optrans[v];
+						name=OP
 					except KeyError:
 						if v.lower()=="true":
@@ -473,4 +476,7 @@
 			return ret
 	def tryfind(self,filename):
+		if filename.endswith('.moc'):
+			self.names.append(filename)
+			return None
 		self.curfile=filename
 		found=self.cached_find_resource(self.currentnode_stack[-1],filename)
@@ -481,6 +487,5 @@
 		if found and not found in self.ban_includes:
 			self.nodes.append(found)
-			if filename[-4:]!='.moc':
-				self.addlines(found)
+			self.addlines(found)
 		else:
 			if not filename in self.names:
@@ -520,6 +525,5 @@
 			self.parse_cache=bld.parse_cache
 		except AttributeError:
-			bld.parse_cache={}
-			self.parse_cache=bld.parse_cache
+			self.parse_cache=bld.parse_cache={}
 		self.current_file=node
 		self.addlines(node)
Index: waflib/Tools/ccroot.py
===================================================================
--- waflib/Tools/ccroot.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/ccroot.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -76,5 +76,7 @@
 					name=name+'-'+nums[0]
 				elif self.env.DEST_OS=='openbsd':
-					pattern='%s.%s.%s'%(pattern,nums[0],nums[1])
+					pattern='%s.%s'%(pattern,nums[0])
+					if len(nums)>=2:
+						pattern+='.%s'%nums[1]
 			tmp=folder+os.sep+pattern%name
 			target=self.generator.path.find_or_declare(tmp)
@@ -82,4 +84,5 @@
 class stlink_task(link_task):
 	run_str='${AR} ${ARFLAGS} ${AR_TGT_F}${TGT} ${AR_SRC_F}${SRC}'
+	chmod=Utils.O644
 def rm_tgt(cls):
 	old=cls.run
@@ -112,5 +115,5 @@
 		inst_to=self.link_task.__class__.inst_to
 	if inst_to:
-		self.install_task=self.bld.install_files(inst_to,self.link_task.outputs[:],env=self.env,chmod=self.link_task.chmod)
+		self.install_task=self.bld.install_files(inst_to,self.link_task.outputs[:],env=self.env,chmod=self.link_task.chmod,task=self.link_task)
 @taskgen_method
 def use_rec(self,name,**kw):
@@ -140,4 +143,6 @@
 	p=self.tmp_use_prec
 	for x in self.to_list(getattr(y,'use',[])):
+		if self.env["STLIB_"+x]:
+			continue
 		try:
 			p[x].append(name)
@@ -191,9 +196,9 @@
 		var=y.tmp_use_var
 		if var and link_task:
-			if var=='LIB'or y.tmp_use_stlib:
+			if var=='LIB'or y.tmp_use_stlib or x in names:
 				self.env.append_value(var,[y.target[y.target.rfind(os.sep)+1:]])
 				self.link_task.dep_nodes.extend(y.link_task.outputs)
 				tmp_path=y.link_task.outputs[0].parent.path_from(self.bld.bldnode)
-				self.env.append_value(var+'PATH',[tmp_path])
+				self.env.append_unique(var+'PATH',[tmp_path])
 		else:
 			if y.tmp_use_objects:
@@ -206,9 +211,9 @@
 		try:
 			y=self.bld.get_tgen_by_name(x)
-		except Exception:
+		except Errors.WafError:
 			if not self.env['STLIB_'+x]and not x in self.uselib:
 				self.uselib.append(x)
 		else:
-			for k in self.to_list(getattr(y,'uselib',[])):
+			for k in self.to_list(getattr(y,'use',[])):
 				if not self.env['STLIB_'+k]and not k in self.uselib:
 					self.uselib.append(k)
@@ -239,14 +244,15 @@
 	_vars=self.get_uselib_vars()
 	env=self.env
-	for x in _vars:
-		y=x.lower()
-		env.append_unique(x,self.to_list(getattr(self,y,[])))
-	for x in self.features:
-		for var in _vars:
-			compvar='%s_%s'%(var,x)
-			env.append_value(var,env[compvar])
-	for x in self.to_list(getattr(self,'uselib',[])):
-		for v in _vars:
-			env.append_value(v,env[v+'_'+x])
+	app=env.append_value
+	feature_uselib=self.features+self.to_list(getattr(self,'uselib',[]))
+	for var in _vars:
+		y=var.lower()
+		val=getattr(self,y,[])
+		if val:
+			app(var,self.to_list(val))
+		for x in feature_uselib:
+			val=env['%s_%s'%(var,x)]
+			if val:
+				app(var,val)
 @feature('cshlib','cxxshlib','fcshlib')
 @after_method('apply_link')
@@ -272,12 +278,17 @@
 		else:
 			self.link_task.inputs.append(node)
-	try:
-		inst_to=self.install_path
-	except AttributeError:
-		inst_to=self.link_task.__class__.inst_to
-	if not inst_to:
-		return
-	self.implib_install_task=self.bld.install_as('${LIBDIR}/%s'%implib.name,implib,self.env)
-re_vnum=re.compile('^([1-9]\\d*|0)[.]([1-9]\\d*|0)[.]([1-9]\\d*|0)$')
+	if getattr(self,'install_task',None):
+		try:
+			inst_to=self.install_path_implib
+		except AttributeError:
+			try:
+				inst_to=self.install_path
+			except AttributeError:
+				inst_to='${IMPLIBDIR}'
+				self.install_task.dest='${BINDIR}'
+				if not self.env.IMPLIBDIR:
+					self.env.IMPLIBDIR=self.env.LIBDIR
+		self.implib_install_task=self.bld.install_files(inst_to,implib,env=self.env,chmod=self.link_task.chmod,task=self.link_task)
+re_vnum=re.compile('^([1-9]\\d*|0)([.]([1-9]\\d*|0)[.]([1-9]\\d*|0))?$')
 @feature('cshlib','cxxshlib','dshlib','fcshlib','vnum')
 @after_method('apply_link','propagate_uselib_vars')
@@ -301,5 +312,8 @@
 		self.env.append_value('LINKFLAGS',v.split())
 	if self.env.DEST_OS!='openbsd':
-		self.create_task('vnum',node,[node.parent.find_or_declare(name2),node.parent.find_or_declare(name3)])
+		outs=[node.parent.find_or_declare(name3)]
+		if name2!=name3:
+			outs.append(node.parent.find_or_declare(name2))
+		self.create_task('vnum',node,outs)
 	if getattr(self,'install_task',None):
 		self.install_task.hasrun=Task.SKIP_ME
@@ -312,7 +326,10 @@
 		else:
 			t1=bld.install_as(path+os.sep+name3,node,env=self.env,chmod=self.link_task.chmod)
-			t2=bld.symlink_as(path+os.sep+name2,name3)
 			t3=bld.symlink_as(path+os.sep+libname,name3)
-			self.vnum_install_task=(t1,t2,t3)
+			if name2!=name3:
+				t2=bld.symlink_as(path+os.sep+name2,name3)
+				self.vnum_install_task=(t1,t2,t3)
+			else:
+				self.vnum_install_task=(t1,t3)
 	if'-dynamiclib'in self.env['LINKFLAGS']:
 		try:
@@ -328,4 +345,6 @@
 	quient=True
 	ext_in=['.bin']
+	def keyword(self):
+		return'Symlinking'
 	def run(self):
 		for x in self.outputs:
Index: waflib/Tools/clang.py
===================================================================
--- waflib/Tools/clang.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
+++ waflib/Tools/clang.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -0,0 +1,20 @@
+#! /usr/bin/env python
+# encoding: utf-8
+# WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
+
+import os,sys
+from waflib.Tools import ccroot,ar,gcc
+from waflib.Configure import conf
+@conf
+def find_clang(conf):
+	cc=conf.find_program('clang',var='CC')
+	conf.get_cc_version(cc,clang=True)
+	conf.env.CC_NAME='clang'
+def configure(conf):
+	conf.find_clang()
+	conf.find_ar()
+	conf.gcc_common_flags()
+	conf.gcc_modifier_platform()
+	conf.cc_load_tools()
+	conf.cc_add_flags()
+	conf.link_add_flags()
Index: waflib/Tools/clangxx.py
===================================================================
--- waflib/Tools/clangxx.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
+++ waflib/Tools/clangxx.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -0,0 +1,20 @@
+#! /usr/bin/env python
+# encoding: utf-8
+# WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
+
+import os,sys
+from waflib.Tools import ccroot,ar,gxx
+from waflib.Configure import conf
+@conf
+def find_clangxx(conf):
+	cxx=conf.find_program('clang++',var='CXX')
+	conf.get_cc_version(cxx,clang=True)
+	conf.env.CXX_NAME='clang'
+def configure(conf):
+	conf.find_clangxx()
+	conf.find_ar()
+	conf.gxx_common_flags()
+	conf.gxx_modifier_platform()
+	conf.cxx_load_tools()
+	conf.cxx_add_flags()
+	conf.link_add_flags()
Index: waflib/Tools/compiler_c.py
===================================================================
--- waflib/Tools/compiler_c.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/compiler_c.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -3,15 +3,19 @@
 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
 
-import os,sys,imp,types
+import os,sys,imp,types,re
 from waflib.Tools import ccroot
 from waflib import Utils,Configure
 from waflib.Logs import debug
-c_compiler={'win32':['msvc','gcc'],'cygwin':['gcc'],'darwin':['gcc'],'aix':['xlc','gcc'],'linux':['gcc','icc'],'sunos':['suncc','gcc'],'irix':['gcc','irixcc'],'hpux':['gcc'],'gnu':['gcc'],'java':['gcc','msvc','icc'],'default':['gcc'],}
+c_compiler={'win32':['msvc','gcc','clang'],'cygwin':['gcc'],'darwin':['clang','gcc'],'aix':['xlc','gcc','clang'],'linux':['gcc','clang','icc'],'sunos':['suncc','gcc'],'irix':['gcc','irixcc'],'hpux':['gcc'],'gnu':['gcc','clang'],'java':['gcc','msvc','clang','icc'],'default':['gcc','clang'],}
+def default_compilers():
+	build_platform=Utils.unversioned_sys_platform()
+	possible_compiler_list=c_compiler.get(build_platform,c_compiler['default'])
+	return' '.join(possible_compiler_list)
 def configure(conf):
-	try:test_for_compiler=conf.options.check_c_compiler
+	try:test_for_compiler=conf.options.check_c_compiler or default_compilers()
 	except AttributeError:conf.fatal("Add options(opt): opt.load('compiler_c')")
-	for compiler in test_for_compiler.split():
+	for compiler in re.split('[ ,]+',test_for_compiler):
 		conf.env.stash()
-		conf.start_msg('Checking for %r (c compiler)'%compiler)
+		conf.start_msg('Checking for %r (C compiler)'%compiler)
 		try:
 			conf.load(compiler)
@@ -27,13 +31,10 @@
 			conf.end_msg(False)
 	else:
-		conf.fatal('could not configure a c compiler!')
+		conf.fatal('could not configure a C compiler!')
 def options(opt):
+	test_for_compiler=default_compilers()
 	opt.load_special_tools('c_*.py',ban=['c_dumbpreproc.py'])
-	global c_compiler
-	build_platform=Utils.unversioned_sys_platform()
-	possible_compiler_list=c_compiler[build_platform in c_compiler and build_platform or'default']
-	test_for_compiler=' '.join(possible_compiler_list)
-	cc_compiler_opts=opt.add_option_group("C Compiler Options")
-	cc_compiler_opts.add_option('--check-c-compiler',default="%s"%test_for_compiler,help='On this platform (%s) the following C-Compiler will be checked by default: "%s"'%(build_platform,test_for_compiler),dest="check_c_compiler")
+	cc_compiler_opts=opt.add_option_group('Configuration options')
+	cc_compiler_opts.add_option('--check-c-compiler',default=None,help='list of C compilers to try [%s]'%test_for_compiler,dest="check_c_compiler")
 	for x in test_for_compiler.split():
 		opt.load('%s'%x)
Index: waflib/Tools/compiler_cxx.py
===================================================================
--- waflib/Tools/compiler_cxx.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/compiler_cxx.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -3,15 +3,19 @@
 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
 
-import os,sys,imp,types
+import os,sys,imp,types,re
 from waflib.Tools import ccroot
 from waflib import Utils,Configure
 from waflib.Logs import debug
-cxx_compiler={'win32':['msvc','g++'],'cygwin':['g++'],'darwin':['g++'],'aix':['xlc++','g++'],'linux':['g++','icpc'],'sunos':['sunc++','g++'],'irix':['g++'],'hpux':['g++'],'gnu':['g++'],'java':['g++','msvc','icpc'],'default':['g++']}
+cxx_compiler={'win32':['msvc','g++','clang++'],'cygwin':['g++'],'darwin':['clang++','g++'],'aix':['xlc++','g++','clang++'],'linux':['g++','clang++','icpc'],'sunos':['sunc++','g++'],'irix':['g++'],'hpux':['g++'],'gnu':['g++','clang++'],'java':['g++','msvc','clang++','icpc'],'default':['g++','clang++']}
+def default_compilers():
+	build_platform=Utils.unversioned_sys_platform()
+	possible_compiler_list=cxx_compiler.get(build_platform,cxx_compiler['default'])
+	return' '.join(possible_compiler_list)
 def configure(conf):
-	try:test_for_compiler=conf.options.check_cxx_compiler
+	try:test_for_compiler=conf.options.check_cxx_compiler or default_compilers()
 	except AttributeError:conf.fatal("Add options(opt): opt.load('compiler_cxx')")
-	for compiler in test_for_compiler.split():
+	for compiler in re.split('[ ,]+',test_for_compiler):
 		conf.env.stash()
-		conf.start_msg('Checking for %r (c++ compiler)'%compiler)
+		conf.start_msg('Checking for %r (C++ compiler)'%compiler)
 		try:
 			conf.load(compiler)
@@ -27,13 +31,10 @@
 			conf.end_msg(False)
 	else:
-		conf.fatal('could not configure a c++ compiler!')
+		conf.fatal('could not configure a C++ compiler!')
 def options(opt):
+	test_for_compiler=default_compilers()
 	opt.load_special_tools('cxx_*.py')
-	global cxx_compiler
-	build_platform=Utils.unversioned_sys_platform()
-	possible_compiler_list=cxx_compiler[build_platform in cxx_compiler and build_platform or'default']
-	test_for_compiler=' '.join(possible_compiler_list)
-	cxx_compiler_opts=opt.add_option_group('C++ Compiler Options')
-	cxx_compiler_opts.add_option('--check-cxx-compiler',default="%s"%test_for_compiler,help='On this platform (%s) the following C++ Compiler will be checked by default: "%s"'%(build_platform,test_for_compiler),dest="check_cxx_compiler")
+	cxx_compiler_opts=opt.add_option_group('Configuration options')
+	cxx_compiler_opts.add_option('--check-cxx-compiler',default=None,help='list of C++ compilers to try [%s]'%test_for_compiler,dest="check_cxx_compiler")
 	for x in test_for_compiler.split():
 		opt.load('%s'%x)
Index: waflib/Tools/compiler_d.py
===================================================================
--- waflib/Tools/compiler_d.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/compiler_d.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -3,10 +3,17 @@
 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
 
-import os,sys,imp,types
+import os,sys,imp,types,re
 from waflib import Utils,Configure,Options,Logs
+d_compiler={'default':['gdc','dmd','ldc2']}
+def default_compilers():
+	build_platform=Utils.unversioned_sys_platform()
+	possible_compiler_list=d_compiler.get(build_platform,d_compiler['default'])
+	return' '.join(possible_compiler_list)
 def configure(conf):
-	for compiler in conf.options.dcheck.split(','):
+	try:test_for_compiler=conf.options.check_d_compiler or default_compilers()
+	except AttributeError:conf.fatal("Add options(opt): opt.load('compiler_d')")
+	for compiler in re.split('[ ,]+',test_for_compiler):
 		conf.env.stash()
-		conf.start_msg('Checking for %r (d compiler)'%compiler)
+		conf.start_msg('Checking for %r (D compiler)'%compiler)
 		try:
 			conf.load(compiler)
@@ -22,8 +29,9 @@
 			conf.end_msg(False)
 	else:
-		conf.fatal('no suitable d compiler was found')
+		conf.fatal('could not configure a D compiler!')
 def options(opt):
-	d_compiler_opts=opt.add_option_group('D Compiler Options')
-	d_compiler_opts.add_option('--check-d-compiler',default='gdc,dmd,ldc2',action='store',help='check for the compiler [Default:gdc,dmd,ldc2]',dest='dcheck')
-	for d_compiler in['gdc','dmd','ldc2']:
-		opt.load('%s'%d_compiler)
+	test_for_compiler=default_compilers()
+	d_compiler_opts=opt.add_option_group('Configuration options')
+	d_compiler_opts.add_option('--check-d-compiler',default=None,help='list of D compilers to try [%s]'%test_for_compiler,dest='check_d_compiler')
+	for x in test_for_compiler.split():
+		opt.load('%s'%x)
Index: waflib/Tools/compiler_fc.py
===================================================================
--- waflib/Tools/compiler_fc.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/compiler_fc.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -3,19 +3,18 @@
 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
 
-import os,sys,imp,types
+import os,sys,imp,types,re
 from waflib import Utils,Configure,Options,Logs,Errors
 from waflib.Tools import fc
 fc_compiler={'win32':['gfortran','ifort'],'darwin':['gfortran','g95','ifort'],'linux':['gfortran','g95','ifort'],'java':['gfortran','g95','ifort'],'default':['gfortran'],'aix':['gfortran']}
-def __list_possible_compiler(platform):
-	try:
-		return fc_compiler[platform]
-	except KeyError:
-		return fc_compiler["default"]
+def default_compilers():
+	build_platform=Utils.unversioned_sys_platform()
+	possible_compiler_list=fc_compiler.get(build_platform,fc_compiler['default'])
+	return' '.join(possible_compiler_list)
 def configure(conf):
-	try:test_for_compiler=conf.options.check_fc
+	try:test_for_compiler=conf.options.check_fortran_compiler or default_compilers()
 	except AttributeError:conf.fatal("Add options(opt): opt.load('compiler_fc')")
-	for compiler in test_for_compiler.split():
+	for compiler in re.split('[ ,]+',test_for_compiler):
 		conf.env.stash()
-		conf.start_msg('Checking for %r (fortran compiler)'%compiler)
+		conf.start_msg('Checking for %r (Fortran compiler)'%compiler)
 		try:
 			conf.load(compiler)
@@ -31,13 +30,10 @@
 			conf.end_msg(False)
 	else:
-		conf.fatal('could not configure a fortran compiler!')
+		conf.fatal('could not configure a Fortran compiler!')
 def options(opt):
+	test_for_compiler=default_compilers()
 	opt.load_special_tools('fc_*.py')
-	build_platform=Utils.unversioned_sys_platform()
-	detected_platform=Options.platform
-	possible_compiler_list=__list_possible_compiler(detected_platform)
-	test_for_compiler=' '.join(possible_compiler_list)
-	fortran_compiler_opts=opt.add_option_group("Fortran Compiler Options")
-	fortran_compiler_opts.add_option('--check-fortran-compiler',default="%s"%test_for_compiler,help='On this platform (%s) the following Fortran Compiler will be checked by default: "%s"'%(detected_platform,test_for_compiler),dest="check_fc")
-	for compiler in test_for_compiler.split():
-		opt.load('%s'%compiler)
+	fortran_compiler_opts=opt.add_option_group('Configuration options')
+	fortran_compiler_opts.add_option('--check-fortran-compiler',default=None,help='list of Fortran compiler to try [%s]'%test_for_compiler,dest="check_fortran_compiler")
+	for x in test_for_compiler.split():
+		opt.load('%s'%x)
Index: waflib/Tools/cxx.py
===================================================================
--- waflib/Tools/cxx.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/cxx.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -12,5 +12,5 @@
 	TaskGen.task_gen.mappings['.c']=TaskGen.task_gen.mappings['.cpp']
 class cxx(Task.Task):
-	run_str='${CXX} ${ARCH_ST:ARCH} ${CXXFLAGS} ${CPPFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CXX_SRC_F}${SRC} ${CXX_TGT_F}${TGT}'
+	run_str='${CXX} ${ARCH_ST:ARCH} ${CXXFLAGS} ${CPPFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CXX_SRC_F}${SRC} ${CXX_TGT_F}${TGT[0].abspath()}'
 	vars=['CXXDEPS']
 	ext_in=['.h']
Index: waflib/Tools/dmd.py
===================================================================
--- waflib/Tools/dmd.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/dmd.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -9,7 +9,7 @@
 def find_dmd(conf):
 	conf.find_program(['dmd','dmd2','ldc'],var='D')
-	out=conf.cmd_and_log([conf.env.D,'--help'])
+	out=conf.cmd_and_log(conf.env.D+['--help'])
 	if out.find("D Compiler v")==-1:
-		out=conf.cmd_and_log([conf.env.D,'-version'])
+		out=conf.cmd_and_log(conf.env.D+['-version'])
 		if out.find("based on DMD v1.")==-1:
 			conf.fatal("detected compiler is not dmd/ldc")
@@ -41,5 +41,5 @@
 	conf.find_dmd()
 	if sys.platform=='win32':
-		out=conf.cmd_and_log([conf.env.D,'--help'])
+		out=conf.cmd_and_log(conf.env.D+['--help'])
 		if out.find("D Compiler v2.")>-1:
 			conf.fatal('dmd2 on Windows is not supported, use gdc or ldc2 instead')
Index: waflib/Tools/fc.py
===================================================================
--- waflib/Tools/fc.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/fc.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -90,6 +90,4 @@
 	inst_to='${LIBDIR}'
 class fcprogram_test(fcprogram):
-	def can_retrieve_cache(self):
-		return False
 	def runnable_status(self):
 		ret=super(fcprogram_test,self).runnable_status()
Index: waflib/Tools/fc_config.py
===================================================================
--- waflib/Tools/fc_config.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/fc_config.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -3,8 +3,8 @@
 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
 
-import re,shutil,os,sys,string,shlex
+import re,os,sys,shlex
 from waflib.Configure import conf
-from waflib.TaskGen import feature,after_method,before_method
-from waflib import Build,Utils
+from waflib.TaskGen import feature,before_method
+from waflib import Utils
 FC_FRAGMENT='        program main\n        end     program main\n'
 FC_FRAGMENT2='        PROGRAM MAIN\n        END\n'
@@ -116,5 +116,5 @@
 def check_fortran_verbose_flag(self,*k,**kw):
 	self.start_msg('fortran link verbose flag')
-	for x in['-v','--verbose','-verbose','-V']:
+	for x in('-v','--verbose','-verbose','-V'):
 		try:
 			self.check_cc(features='fc fcprogram_test',fragment=FC_FRAGMENT2,compile_filename='test.f',linkflags=[x],mandatory=True)
@@ -149,4 +149,23 @@
 SPACE_OPTS=re.compile('^-[LRuYz]$')
 NOSPACE_OPTS=re.compile('^-[RL]')
+def _parse_flink_token(lexer,token,tmp_flags):
+	if _match_ignore(token):
+		pass
+	elif token.startswith('-lkernel32')and sys.platform=='cygwin':
+		tmp_flags.append(token)
+	elif SPACE_OPTS.match(token):
+		t=lexer.get_token()
+		if t.startswith('P,'):
+			t=t[2:]
+		for opt in t.split(os.pathsep):
+			tmp_flags.append('-L%s'%opt)
+	elif NOSPACE_OPTS.match(token):
+		tmp_flags.append(token)
+	elif POSIX_LIB_FLAGS.match(token):
+		tmp_flags.append(token)
+	else:
+		pass
+	t=lexer.get_token()
+	return t
 def _parse_flink_line(line,final_flags):
 	lexer=shlex.shlex(line,posix=True)
@@ -155,24 +174,5 @@
 	tmp_flags=[]
 	while t:
-		def parse(token):
-			if _match_ignore(token):
-				pass
-			elif token.startswith('-lkernel32')and sys.platform=='cygwin':
-				tmp_flags.append(token)
-			elif SPACE_OPTS.match(token):
-				t=lexer.get_token()
-				if t.startswith('P,'):
-					t=t[2:]
-				for opt in t.split(os.pathsep):
-					tmp_flags.append('-L%s'%opt)
-			elif NOSPACE_OPTS.match(token):
-				tmp_flags.append(token)
-			elif POSIX_LIB_FLAGS.match(token):
-				tmp_flags.append(token)
-			else:
-				pass
-			t=lexer.get_token()
-			return t
-		t=parse(t)
+		t=_parse_flink_token(lexer,t,tmp_flags)
 	final_flags.extend(tmp_flags)
 	return final_flags
@@ -241,7 +241,7 @@
 	bld(features='c fcprogram',source='main.c',target='app',use='test')
 def mangling_schemes():
-	for u in['_','']:
-		for du in['','_']:
-			for c in["lower","upper"]:
+	for u in('_',''):
+		for du in('','_'):
+			for c in("lower","upper"):
 				yield(u,du,c)
 def mangle_name(u,du,c,name):
@@ -275,5 +275,5 @@
 @conf
 def detect_openmp(self):
-	for x in['-fopenmp','-openmp','-mp','-xopenmp','-omp','-qsmp=omp']:
+	for x in('-fopenmp','-openmp','-mp','-xopenmp','-omp','-qsmp=omp'):
 		try:
 			self.check_fc(msg='Checking for OpenMP flag %s'%x,fragment='program main\n  call omp_get_num_threads()\nend program main',fcflags=x,linkflags=x,uselib_store='OPENMP')
Index: waflib/Tools/flex.py
===================================================================
--- waflib/Tools/flex.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/flex.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -29,4 +29,4 @@
 	conf.find_program('flex',var='FLEX')
 	conf.env.FLEXFLAGS=['-t']
-	if re.search(r"\\msys\\[0-9.]+\\bin\\flex.exe$",conf.env.FLEX):
+	if re.search(r"\\msys\\[0-9.]+\\bin\\flex.exe$",conf.env.FLEX[0]):
 		conf.env.FLEX_MSYS=True
Index: waflib/Tools/g95.py
===================================================================
--- waflib/Tools/g95.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/g95.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -10,5 +10,4 @@
 def find_g95(conf):
 	fc=conf.find_program('g95',var='FC')
-	fc=conf.cmd_to_list(fc)
 	conf.get_g95_version(fc)
 	conf.env.FC_NAME='G95'
Index: waflib/Tools/gcc.py
===================================================================
--- waflib/Tools/gcc.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/gcc.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -3,4 +3,6 @@
 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
 
+import os,sys
+from waflib import Configure,Options,Utils
 from waflib.Tools import ccroot,ar
 from waflib.Configure import conf
@@ -8,8 +10,6 @@
 def find_gcc(conf):
 	cc=conf.find_program(['gcc','cc'],var='CC')
-	cc=conf.cmd_to_list(cc)
 	conf.get_cc_version(cc,gcc=True)
 	conf.env.CC_NAME='gcc'
-	conf.env.CC=cc
 @conf
 def gcc_common_flags(conf):
Index: waflib/Tools/gdc.py
===================================================================
--- waflib/Tools/gdc.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/gdc.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -9,6 +9,6 @@
 def find_gdc(conf):
 	conf.find_program('gdc',var='D')
-	out=conf.cmd_and_log([conf.env.D,'--version'])
-	if out.find("gdc ")==-1:
+	out=conf.cmd_and_log(conf.env.D+['--version'])
+	if out.find("gdc")==-1:
 		conf.fatal("detected compiler is not gdc")
 @conf
Index: waflib/Tools/gfortran.py
===================================================================
--- waflib/Tools/gfortran.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/gfortran.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -10,5 +10,4 @@
 def find_gfortran(conf):
 	fc=conf.find_program(['gfortran','g77'],var='FC')
-	fc=conf.cmd_to_list(fc)
 	conf.get_gfortran_version(fc)
 	conf.env.FC_NAME='GFORTRAN'
Index: waflib/Tools/glib2.py
===================================================================
--- waflib/Tools/glib2.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/glib2.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -4,6 +4,7 @@
 
 import os
-from waflib import Task,Utils,Options,Errors,Logs
-from waflib.TaskGen import taskgen_method,before_method,after_method,feature
+from waflib import Context,Task,Utils,Options,Errors,Logs
+from waflib.TaskGen import taskgen_method,before_method,after_method,feature,extension
+from waflib.Configure import conf
 @taskgen_method
 def add_marshal_file(self,filename,prefix):
@@ -99,12 +100,4 @@
 		filename_list=[filename_list]
 	self.settings_enum_files=filename_list
-def r_change_ext(self,ext):
-	name=self.name
-	k=name.rfind('.')
-	if k>=0:
-		name=name[:k]+ext
-	else:
-		name=name+ext
-	return self.parent.find_or_declare([name])
 @feature('glib2')
 def process_settings(self):
@@ -137,5 +130,5 @@
 		schema_task.set_inputs(source_list)
 		schema_task.env['GLIB_COMPILE_SCHEMAS_OPTIONS']=[("--schema-file="+k.abspath())for k in source_list]
-		target_node=r_change_ext(schema_node,'.xml.valid')
+		target_node=schema_node.change_ext('.xml.valid')
 		schema_task.set_outputs(target_node)
 		schema_task.env['GLIB_VALIDATE_SCHEMA_OUTPUT']=target_node.abspath()
@@ -156,8 +149,67 @@
 	run_str='rm -f ${GLIB_VALIDATE_SCHEMA_OUTPUT} && ${GLIB_COMPILE_SCHEMAS} --dry-run ${GLIB_COMPILE_SCHEMAS_OPTIONS} && touch ${GLIB_VALIDATE_SCHEMA_OUTPUT}'
 	color='PINK'
-def configure(conf):
+@extension('.gresource.xml')
+def process_gresource_source(self,node):
+	if not self.env['GLIB_COMPILE_RESOURCES']:
+		raise Errors.WafError("Unable to process GResource file - glib-compile-resources was not found during configure")
+	if'gresource'in self.features:
+		return
+	h_node=node.change_ext('_xml.h')
+	c_node=node.change_ext('_xml.c')
+	self.create_task('glib_gresource_source',node,[h_node,c_node])
+	self.source.append(c_node)
+@feature('gresource')
+def process_gresource_bundle(self):
+	for i in self.to_list(self.source):
+		node=self.path.find_resource(i)
+		task=self.create_task('glib_gresource_bundle',node,node.change_ext(''))
+		inst_to=getattr(self,'install_path',None)
+		if inst_to:
+			self.bld.install_files(inst_to,task.outputs)
+class glib_gresource_base(Task.Task):
+	color='BLUE'
+	base_cmd='${GLIB_COMPILE_RESOURCES} --sourcedir=${SRC[0].parent.srcpath()} --sourcedir=${SRC[0].bld_dir()}'
+	def scan(self):
+		bld=self.generator.bld
+		kw={}
+		try:
+			if not kw.get('cwd',None):
+				kw['cwd']=bld.cwd
+		except AttributeError:
+			bld.cwd=kw['cwd']=bld.variant_dir
+		kw['quiet']=Context.BOTH
+		cmd=Utils.subst_vars('${GLIB_COMPILE_RESOURCES} --sourcedir=%s --sourcedir=%s --generate-dependencies %s'%(self.inputs[0].parent.srcpath(),self.inputs[0].bld_dir(),self.inputs[0].bldpath()),self.env)
+		output=bld.cmd_and_log(cmd,**kw)
+		nodes=[]
+		names=[]
+		for dep in output.splitlines():
+			if dep:
+				node=bld.bldnode.find_node(dep)
+				if node:
+					nodes.append(node)
+				else:
+					names.append(dep)
+		return(nodes,names)
+class glib_gresource_source(glib_gresource_base):
+	vars=['GLIB_COMPILE_RESOURCES']
+	fun_h=Task.compile_fun_shell(glib_gresource_base.base_cmd+' --target=${TGT[0].abspath()} --generate-header ${SRC}')
+	fun_c=Task.compile_fun_shell(glib_gresource_base.base_cmd+' --target=${TGT[1].abspath()} --generate-source ${SRC}')
+	ext_out=['.h']
+	def run(self):
+		return self.fun_h[0](self)or self.fun_c[0](self)
+class glib_gresource_bundle(glib_gresource_base):
+	run_str=glib_gresource_base.base_cmd+' --target=${TGT} ${SRC}'
+	shell=True
+@conf
+def find_glib_genmarshal(conf):
 	conf.find_program('glib-genmarshal',var='GLIB_GENMARSHAL')
-	conf.find_perl_program('glib-mkenums',var='GLIB_MKENUMS')
-	conf.find_program('glib-compile-schemas',var='GLIB_COMPILE_SCHEMAS',mandatory=False)
+@conf
+def find_glib_mkenums(conf):
+	if not conf.env.PERL:
+		conf.find_program('perl',var='PERL')
+	conf.find_program('glib-mkenums',interpreter='PERL',var='GLIB_MKENUMS')
+@conf
+def find_glib_compile_schemas(conf):
+	conf.find_program('glib-compile-schemas',var='GLIB_COMPILE_SCHEMAS')
 	def getstr(varname):
 		return getattr(Options.options,varname,getattr(conf.env,varname,''))
@@ -170,4 +222,13 @@
 		gsettingsschemadir=os.path.join(datadir,'glib-2.0','schemas')
 	conf.env['GSETTINGSSCHEMADIR']=gsettingsschemadir
+@conf
+def find_glib_compile_resources(conf):
+	conf.find_program('glib-compile-resources',var='GLIB_COMPILE_RESOURCES')
+def configure(conf):
+	conf.find_glib_genmarshal()
+	conf.find_glib_mkenums()
+	conf.find_glib_compile_schemas(mandatory=False)
+	conf.find_glib_compile_resources(mandatory=False)
 def options(opt):
-	opt.add_option('--gsettingsschemadir',help='GSettings schema location [Default: ${datadir}/glib-2.0/schemas]',default='',dest='GSETTINGSSCHEMADIR')
+	gr=opt.add_option_group('Installation directories')
+	gr.add_option('--gsettingsschemadir',help='GSettings schema location [DATADIR/glib-2.0/schemas]',default='',dest='GSETTINGSSCHEMADIR')
Index: waflib/Tools/gnu_dirs.py
===================================================================
--- waflib/Tools/gnu_dirs.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/gnu_dirs.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -3,27 +3,28 @@
 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
 
-import os
+import os,re
 from waflib import Utils,Options,Context
-_options=[x.split(', ')for x in'''
-bindir, user executables, ${EXEC_PREFIX}/bin
-sbindir, system admin executables, ${EXEC_PREFIX}/sbin
-libexecdir, program executables, ${EXEC_PREFIX}/libexec
-sysconfdir, read-only single-machine data, ${PREFIX}/etc
-sharedstatedir, modifiable architecture-independent data, ${PREFIX}/com
-localstatedir, modifiable single-machine data, ${PREFIX}/var
-libdir, object code libraries, ${EXEC_PREFIX}/lib
-includedir, C header files, ${PREFIX}/include
-oldincludedir, C header files for non-gcc, /usr/include
-datarootdir, read-only arch.-independent data root, ${PREFIX}/share
-datadir, read-only architecture-independent data, ${DATAROOTDIR}
-infodir, info documentation, ${DATAROOTDIR}/info
+gnuopts='''
+bindir, user commands, ${EXEC_PREFIX}/bin
+sbindir, system binaries, ${EXEC_PREFIX}/sbin
+libexecdir, program-specific binaries, ${EXEC_PREFIX}/libexec
+sysconfdir, host-specific configuration, ${PREFIX}/etc
+sharedstatedir, architecture-independent variable data, ${PREFIX}/com
+localstatedir, variable data, ${PREFIX}/var
+libdir, object code libraries, ${EXEC_PREFIX}/lib%s
+includedir, header files, ${PREFIX}/include
+oldincludedir, header files for non-GCC compilers, /usr/include
+datarootdir, architecture-independent data root, ${PREFIX}/share
+datadir, architecture-independent data, ${DATAROOTDIR}
+infodir, GNU "info" documentation, ${DATAROOTDIR}/info
 localedir, locale-dependent data, ${DATAROOTDIR}/locale
-mandir, man documentation, ${DATAROOTDIR}/man
+mandir, manual pages, ${DATAROOTDIR}/man
 docdir, documentation root, ${DATAROOTDIR}/doc/${PACKAGE}
-htmldir, html documentation, ${DOCDIR}
-dvidir, dvi documentation, ${DOCDIR}
-pdfdir, pdf documentation, ${DOCDIR}
-psdir, ps documentation, ${DOCDIR}
-'''.split('\n')if x]
+htmldir, HTML documentation, ${DOCDIR}
+dvidir, DVI documentation, ${DOCDIR}
+pdfdir, PDF documentation, ${DOCDIR}
+psdir, PostScript documentation, ${DOCDIR}
+'''%Utils.lib64()
+_options=[x.split(', ')for x in gnuopts.splitlines()if x]
 def configure(conf):
 	def get_param(varname,default):
@@ -46,8 +47,8 @@
 					complete=False
 	if not complete:
-		lst=[name for name,_,_ in _options if not env[name.upper()]]
+		lst=[x for x,_,_ in _options if not env[x.upper()]]
 		raise conf.errors.WafError('Variable substitution failure %r'%lst)
 def options(opt):
-	inst_dir=opt.add_option_group('Installation directories','By default, "waf install" will put the files in\
+	inst_dir=opt.add_option_group('Installation prefix','By default, "waf install" will put the files in\
  "/usr/local/bin", "/usr/local/lib" etc. An installation prefix other\
  than "/usr/local" can be given using "--prefix", for example "--prefix=$HOME"')
@@ -57,9 +58,9 @@
 			opt.parser.remove_option(k)
 			inst_dir.add_option(option)
-	inst_dir.add_option('--exec-prefix',help='installation prefix [Default: ${PREFIX}]',default='',dest='EXEC_PREFIX')
-	dirs_options=opt.add_option_group('Pre-defined installation directories','')
+	inst_dir.add_option('--exec-prefix',help='installation prefix for binaries [PREFIX]',default='',dest='EXEC_PREFIX')
+	dirs_options=opt.add_option_group('Installation directories')
 	for name,help,default in _options:
 		option_name='--'+name
 		str_default=default
-		str_help='%s [Default: %s]'%(help,str_default)
+		str_help='%s [%s]'%(help,re.sub(r'\$\{([^}]+)\}',r'\1',str_default))
 		dirs_options.add_option(option_name,help=str_help,default='',dest=name.upper())
Index: waflib/Tools/gxx.py
===================================================================
--- waflib/Tools/gxx.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/gxx.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -3,4 +3,6 @@
 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
 
+import os,sys
+from waflib import Configure,Options,Utils
 from waflib.Tools import ccroot,ar
 from waflib.Configure import conf
@@ -8,8 +10,6 @@
 def find_gxx(conf):
 	cxx=conf.find_program(['g++','c++'],var='CXX')
-	cxx=conf.cmd_to_list(cxx)
 	conf.get_cc_version(cxx,gcc=True)
 	conf.env.CXX_NAME='gcc'
-	conf.env.CXX=cxx
 @conf
 def gxx_common_flags(conf):
Index: waflib/Tools/icc.py
===================================================================
--- waflib/Tools/icc.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/icc.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -10,15 +10,7 @@
 	if sys.platform=='cygwin':
 		conf.fatal('The Intel compiler does not work on Cygwin')
-	v=conf.env
-	cc=None
-	if v['CC']:cc=v['CC']
-	elif'CC'in conf.environ:cc=conf.environ['CC']
-	if not cc:cc=conf.find_program('icc',var='CC')
-	if not cc:cc=conf.find_program('ICL',var='CC')
-	if not cc:conf.fatal('Intel C Compiler (icc) was not found')
-	cc=conf.cmd_to_list(cc)
+	cc=conf.find_program(['icc','ICL'],var='CC')
 	conf.get_cc_version(cc,icc=True)
-	v['CC']=cc
-	v['CC_NAME']='icc'
+	conf.env.CC_NAME='icc'
 def configure(conf):
 	conf.find_icc()
Index: waflib/Tools/icpc.py
===================================================================
--- waflib/Tools/icpc.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/icpc.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -10,14 +10,7 @@
 	if sys.platform=='cygwin':
 		conf.fatal('The Intel compiler does not work on Cygwin')
-	v=conf.env
-	cxx=None
-	if v['CXX']:cxx=v['CXX']
-	elif'CXX'in conf.environ:cxx=conf.environ['CXX']
-	if not cxx:cxx=conf.find_program('icpc',var='CXX')
-	if not cxx:conf.fatal('Intel C++ Compiler (icpc) was not found')
-	cxx=conf.cmd_to_list(cxx)
+	cxx=conf.find_program('icpc',var='CXX')
 	conf.get_cc_version(cxx,icc=True)
-	v['CXX']=cxx
-	v['CXX_NAME']='icc'
+	conf.env.CXX_NAME='icc'
 def configure(conf):
 	conf.find_icpc()
Index: waflib/Tools/ifort.py
===================================================================
--- waflib/Tools/ifort.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/ifort.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -10,5 +10,4 @@
 def find_ifort(conf):
 	fc=conf.find_program('ifort',var='FC')
-	fc=conf.cmd_to_list(fc)
 	conf.get_ifort_version(fc)
 	conf.env.FC_NAME='IFORT'
@@ -30,6 +29,9 @@
 @conf
 def get_ifort_version(conf,fc):
-	version_re=re.compile(r"ifort\s*\(IFORT\)\s*(?P<major>\d*)\.(?P<minor>\d*)",re.I).search
-	cmd=fc+['--version']
+	version_re=re.compile(r"Intel[\sa-zA-Z()0-9,-]*Version\s*(?P<major>\d*)\.(?P<minor>\d*)",re.I).search
+	if Utils.is_win32:
+		cmd=fc
+	else:
+		cmd=fc+['-logo']
 	out,err=fc_config.getoutput(conf,cmd,stdin=False)
 	if out:
Index: waflib/Tools/intltool.py
===================================================================
--- waflib/Tools/intltool.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/intltool.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -4,8 +4,17 @@
 
 import os,re
-from waflib import Configure,TaskGen,Task,Utils,Runner,Options,Build,Logs
+from waflib import Configure,Context,TaskGen,Task,Utils,Runner,Options,Build,Logs
 import waflib.Tools.ccroot
-from waflib.TaskGen import feature,before_method
+from waflib.TaskGen import feature,before_method,taskgen_method
 from waflib.Logs import error
+from waflib.Configure import conf
+_style_flags={'ba':'-b','desktop':'-d','keys':'-k','quoted':'--quoted-style','quotedxml':'--quotedxml-style','rfc822deb':'-r','schemas':'-s','xml':'-x',}
+@taskgen_method
+def ensure_localedir(self):
+	if not self.env.LOCALEDIR:
+		if self.env.DATAROOTDIR:
+			self.env.LOCALEDIR=os.path.join(self.env.DATAROOTDIR,'locale')
+		else:
+			self.env.LOCALEDIR=os.path.join(self.env.PREFIX,'share','locale')
 @before_method('process_source')
 @feature('intltool_in')
@@ -13,19 +22,27 @@
 	try:self.meths.remove('process_source')
 	except ValueError:pass
-	if not self.env.LOCALEDIR:
-		self.env.LOCALEDIR=self.env.PREFIX+'/share/locale'
+	self.ensure_localedir()
+	podir=getattr(self,'podir','.')
+	podirnode=self.path.find_dir(podir)
+	if not podirnode:
+		error("could not find the podir %r"%podir)
+		return
+	cache=getattr(self,'intlcache','.intlcache')
+	self.env.INTLCACHE=[os.path.join(str(self.path.get_bld()),podir,cache)]
+	self.env.INTLPODIR=podirnode.bldpath()
+	self.env.append_value('INTLFLAGS',getattr(self,'flags',self.env.INTLFLAGS_DEFAULT))
+	if'-c'in self.env.INTLFLAGS:
+		self.bld.fatal('Redundant -c flag in intltool task %r'%self)
+	style=getattr(self,'style',None)
+	if style:
+		try:
+			style_flag=_style_flags[style]
+		except KeyError:
+			self.bld.fatal('intltool_in style "%s" is not valid'%style)
+		self.env.append_unique('INTLFLAGS',[style_flag])
 	for i in self.to_list(self.source):
 		node=self.path.find_resource(i)
-		podir=getattr(self,'podir','po')
-		podirnode=self.path.find_dir(podir)
-		if not podirnode:
-			error("could not find the podir %r"%podir)
-			continue
-		cache=getattr(self,'intlcache','.intlcache')
-		self.env['INTLCACHE']=os.path.join(self.path.bldpath(),podir,cache)
-		self.env['INTLPODIR']=podirnode.bldpath()
-		self.env['INTLFLAGS']=getattr(self,'flags',['-q','-u','-c'])
 		task=self.create_task('intltool',node,node.change_ext(''))
-		inst=getattr(self,'install_path','${LOCALEDIR}')
+		inst=getattr(self,'install_path',None)
 		if inst:
 			self.bld.install_files(inst,task.outputs)
@@ -34,8 +51,7 @@
 	try:self.meths.remove('process_source')
 	except ValueError:pass
-	if not self.env.LOCALEDIR:
-		self.env.LOCALEDIR=self.env.PREFIX+'/share/locale'
-	appname=getattr(self,'appname','set_your_app_name')
-	podir=getattr(self,'podir','')
+	self.ensure_localedir()
+	appname=getattr(self,'appname',getattr(Context.g_module,Context.APPNAME,'set_your_app_name'))
+	podir=getattr(self,'podir','.')
 	inst=getattr(self,'install_path','${LOCALEDIR}')
 	linguas=self.path.find_node(os.path.join(podir,'LINGUAS'))
@@ -63,15 +79,19 @@
 	color='BLUE'
 class intltool(Task.Task):
-	run_str='${INTLTOOL} ${INTLFLAGS} ${INTLCACHE} ${INTLPODIR} ${SRC} ${TGT}'
+	run_str='${INTLTOOL} ${INTLFLAGS} ${INTLCACHE_ST:INTLCACHE} ${INTLPODIR} ${SRC} ${TGT}'
 	color='BLUE'
+@conf
+def find_msgfmt(conf):
+	conf.find_program('msgfmt',var='MSGFMT')
+@conf
+def find_intltool_merge(conf):
+	if not conf.env.PERL:
+		conf.find_program('perl',var='PERL')
+	conf.env.INTLCACHE_ST='--cache=%s'
+	conf.env.INTLFLAGS_DEFAULT=['-q','-u']
+	conf.find_program('intltool-merge',interpreter='PERL',var='INTLTOOL')
 def configure(conf):
-	conf.find_program('msgfmt',var='MSGFMT')
-	conf.find_perl_program('intltool-merge',var='INTLTOOL')
-	prefix=conf.env.PREFIX
-	datadir=conf.env.DATADIR
-	if not datadir:
-		datadir=os.path.join(prefix,'share')
-	conf.define('LOCALEDIR',os.path.join(datadir,'locale').replace('\\','\\\\'))
-	conf.define('DATADIR',datadir.replace('\\','\\\\'))
+	conf.find_msgfmt()
+	conf.find_intltool_merge()
 	if conf.env.CC or conf.env.CXX:
 		conf.check(header_name='locale.h')
Index: waflib/Tools/irixcc.py
===================================================================
--- waflib/Tools/irixcc.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/irixcc.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -15,5 +15,4 @@
 	if not cc:cc=conf.find_program('cc',var='CC')
 	if not cc:conf.fatal('irixcc was not found')
-	cc=conf.cmd_to_list(cc)
 	try:
 		conf.cmd_and_log(cc+['-version'])
Index: waflib/Tools/javaw.py
===================================================================
--- waflib/Tools/javaw.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/javaw.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -158,5 +158,4 @@
 class javac(Task.Task):
 	color='BLUE'
-	nocache=True
 	vars=['CLASSPATH','JAVACFLAGS','JAVAC','OUTDIR']
 	def runnable_status(self):
@@ -254,5 +253,4 @@
 	for x in'javac java jar javadoc'.split():
 		self.find_program(x,var=x.upper(),path_list=java_path)
-		self.env[x.upper()]=self.cmd_to_list(self.env[x.upper()])
 	if'CLASSPATH'in self.environ:
 		v['CLASSPATH']=self.environ['CLASSPATH']
Index: waflib/Tools/kde4.py
===================================================================
--- waflib/Tools/kde4.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/kde4.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -20,5 +20,5 @@
 def configure(self):
 	kdeconfig=self.find_program('kde4-config')
-	prefix=self.cmd_and_log('%s --prefix'%kdeconfig).strip()
+	prefix=self.cmd_and_log(kdeconfig+['--prefix']).strip()
 	fname='%s/share/apps/cmake/modules/KDELibsDependencies.cmake'%prefix
 	try:os.stat(fname)
@@ -29,5 +29,5 @@
 	try:
 		txt=Utils.readf(fname)
-	except(OSError,IOError):
+	except EnvironmentError:
 		self.fatal('could not read %s'%fname)
 	txt=txt.replace('\\\n','\n')
Index: waflib/Tools/ldc2.py
===================================================================
--- waflib/Tools/ldc2.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/ldc2.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -9,5 +9,5 @@
 def find_ldc2(conf):
 	conf.find_program(['ldc2'],var='D')
-	out=conf.cmd_and_log([conf.env.D,'-version'])
+	out=conf.cmd_and_log(conf.env.D+['-version'])
 	if out.find("based on DMD v2.")==-1:
 		conf.fatal("detected compiler is not ldc2")
Index: waflib/Tools/msvc.py
===================================================================
--- waflib/Tools/msvc.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/msvc.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -60,5 +60,9 @@
 def get_msvc_version(conf,compiler,version,target,vcvars):
 	debug('msvc: get_msvc_version: %r %r %r',compiler,version,target)
-	batfile=conf.bldnode.make_node('waf-print-msvc.bat')
+	try:
+		conf.msvc_cnt+=1
+	except AttributeError:
+		conf.msvc_cnt=1
+	batfile=conf.bldnode.make_node('waf-print-msvc-%d.bat'%conf.msvc_cnt)
 	batfile.write("""@echo off
 set INCLUDE=
@@ -69,5 +73,5 @@
 echo LIB=%%LIB%%;%%LIBPATH%%
 """%(vcvars,target))
-	sout=conf.cmd_and_log(['cmd','/E:on','/V:on','/C',batfile.abspath()])
+	sout=conf.cmd_and_log(['cmd.exe','/E:on','/V:on','/C',batfile.abspath()])
 	lines=sout.splitlines()
 	if not lines[0]:
@@ -88,5 +92,4 @@
 	compiler_name,linker_name,lib_name=_get_prog_names(conf,compiler)
 	cxx=conf.find_program(compiler_name,path_list=MSVC_PATH)
-	cxx=conf.cmd_to_list(cxx)
 	if'CL'in env:
 		del(env['CL'])
@@ -176,5 +179,5 @@
 	version_pattern=re.compile('^(\d\d?\.\d\d?)(Exp)?$')
 	detected_versions=[]
-	for vcver,vcvar in[('VCExpress','Exp'),('VisualStudio','')]:
+	for vcver,vcvar in(('VCExpress','Exp'),('VisualStudio','')):
 		try:
 			prefix='SOFTWARE\\Wow6432node\\Microsoft\\'+vcver
@@ -373,5 +376,5 @@
 					patch_url='http://software.intel.com/en-us/forums/topic/328487'
 					compilervars_arch=os.path.join(path,'bin','compilervars_arch.bat')
-					for vscomntool in['VS110COMNTOOLS','VS100COMNTOOLS']:
+					for vscomntool in('VS110COMNTOOLS','VS100COMNTOOLS'):
 						if vscomntool in os.environ:
 							vs_express_path=os.environ[vscomntool]+r'..\IDE\VSWinExpress.exe'
@@ -529,5 +532,4 @@
 	elif'CXX'in conf.environ:cxx=conf.environ['CXX']
 	cxx=conf.find_program(compiler_name,var='CXX',path_list=path)
-	cxx=conf.cmd_to_list(cxx)
 	env=dict(conf.environ)
 	if path:env.update(PATH=';'.join(path))
@@ -619,8 +621,6 @@
 				pdbnode=self.link_task.outputs[0].change_ext('.pdb')
 				self.link_task.outputs.append(pdbnode)
-				try:
-					self.install_task.source.append(pdbnode)
-				except AttributeError:
-					pass
+				if getattr(self,'install_task',None):
+					self.pdb_install_task=self.bld.install_files(self.install_task.dest,pdbnode,env=self.env)
 				break
 @feature('cprogram','cshlib','cxxprogram','cxxshlib')
@@ -652,11 +652,9 @@
 		mode='2'
 	debug('msvc: embedding manifest in mode %r'%mode)
-	lst=[]
-	lst.append(env['MT'])
+	lst=[]+mtool
 	lst.extend(Utils.to_list(env['MTFLAGS']))
 	lst.extend(['-manifest',manifest])
 	lst.append('-outputresource:%s;%s'%(outfile,mode))
-	lst=[lst]
-	return self.exec_command(*lst)
+	return self.exec_command(lst)
 def quote_response_command(self,flag):
 	if flag.find(' ')>-1:
@@ -726,4 +724,6 @@
 	derived_class.exec_command_msvc=exec_command_msvc
 	derived_class.exec_mf=exec_mf
+	if hasattr(cls,'hcode'):
+		derived_class.hcode=cls.hcode
 	return derived_class
 for k in'c cxx cprogram cxxprogram cshlib cxxshlib cstlib cxxstlib'.split():
Index: waflib/Tools/perl.py
===================================================================
--- waflib/Tools/perl.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/perl.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -37,5 +37,5 @@
 		return False
 	self.env['PERL']=perl
-	version=self.cmd_and_log([perl,"-e",'printf \"%vd\", $^V'])
+	version=self.cmd_and_log(self.env.PERL+["-e",'printf \"%vd\", $^V'])
 	if not version:
 		res=False
@@ -49,5 +49,5 @@
 @conf
 def check_perl_module(self,module):
-	cmd=[self.env['PERL'],'-e','use %s'%module]
+	cmd=self.env.PERL+['-e','use %s'%module]
 	self.start_msg('perl module %s'%module)
 	try:
@@ -64,16 +64,20 @@
 	if not perl:
 		self.fatal('find perl first')
-	def read_out(cmd):
-		return Utils.to_list(self.cmd_and_log(perl+cmd))
-	env['LINKFLAGS_PERLEXT']=read_out(" -MConfig -e'print $Config{lddlflags}'")
-	env['INCLUDES_PERLEXT']=read_out(" -MConfig -e'print \"$Config{archlib}/CORE\"'")
-	env['CFLAGS_PERLEXT']=read_out(" -MConfig -e'print \"$Config{ccflags} $Config{cccdlflags}\"'")
-	env['XSUBPP']=read_out(" -MConfig -e'print \"$Config{privlib}/ExtUtils/xsubpp$Config{exe_ext}\"'")
-	env['EXTUTILS_TYPEMAP']=read_out(" -MConfig -e'print \"$Config{privlib}/ExtUtils/typemap\"'")
+	def cmd_perl_config(s):
+		return perl+['-MConfig','-e','print \"%s\"'%s]
+	def cfg_str(cfg):
+		return self.cmd_and_log(cmd_perl_config(cfg))
+	def cfg_lst(cfg):
+		return Utils.to_list(cfg_str(cfg))
+	env['LINKFLAGS_PERLEXT']=cfg_lst('$Config{lddlflags}')
+	env['INCLUDES_PERLEXT']=cfg_lst('$Config{archlib}/CORE')
+	env['CFLAGS_PERLEXT']=cfg_lst('$Config{ccflags} $Config{cccdlflags}')
+	env['XSUBPP']=cfg_lst('$Config{privlib}/ExtUtils/xsubpp$Config{exe_ext}')
+	env['EXTUTILS_TYPEMAP']=cfg_lst('$Config{privlib}/ExtUtils/typemap')
 	if not getattr(Options.options,'perlarchdir',None):
-		env['ARCHDIR_PERL']=self.cmd_and_log(perl+" -MConfig -e'print $Config{sitearch}'")
+		env['ARCHDIR_PERL']=cfg_str('$Config{sitearch}')
 	else:
 		env['ARCHDIR_PERL']=getattr(Options.options,'perlarchdir')
-	env['perlext_PATTERN']='%s.'+self.cmd_and_log(perl+" -MConfig -e'print $Config{dlext}'")
+	env['perlext_PATTERN']='%s.'+cfg_str('$Config{dlext}')
 def options(opt):
 	opt.add_option('--with-perl-binary',type='string',dest='perlbinary',help='Specify alternate perl binary',default=None)
Index: waflib/Tools/python.py
===================================================================
--- waflib/Tools/python.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/python.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -4,5 +4,5 @@
 
 import os,sys
-from waflib import Utils,Options,Errors,Logs
+from waflib import Utils,Options,Errors,Logs,Task,Node
 from waflib.TaskGen import extension,before_method,after_method,feature
 from waflib.Configure import conf
@@ -27,62 +27,64 @@
 INST='''
 import sys, py_compile
-py_compile.compile(sys.argv[1], sys.argv[2], sys.argv[3])
+py_compile.compile(sys.argv[1], sys.argv[2], sys.argv[3], True)
 '''
 DISTUTILS_IMP=['from distutils.sysconfig import get_config_var, get_python_lib']
+@before_method('process_source')
+@feature('py')
+def feature_py(self):
+	self.install_path=getattr(self,'install_path','${PYTHONDIR}')
+	install_from=getattr(self,'install_from',None)
+	if install_from and not isinstance(install_from,Node.Node):
+		install_from=self.path.find_dir(install_from)
+	self.install_from=install_from
+	ver=self.env.PYTHON_VERSION
+	if not ver:
+		self.bld.fatal('Installing python files requires PYTHON_VERSION, try conf.check_python_version')
+	if int(ver.replace('.',''))>31:
+		self.install_32=True
 @extension('.py')
 def process_py(self,node):
-	try:
-		if not self.bld.is_install:
-			return
-	except AttributeError:
-		return
-	try:
-		if not self.install_path:
-			return
-	except AttributeError:
-		self.install_path='${PYTHONDIR}'
-	def inst_py(ctx):
-		install_from=getattr(self,'install_from',None)
-		if install_from:
-			install_from=self.path.find_dir(install_from)
-		install_pyfile(self,node,install_from)
-	self.bld.add_post_fun(inst_py)
-def install_pyfile(self,node,install_from=None):
-	from_node=install_from or node.parent
-	tsk=self.bld.install_as(self.install_path+'/'+node.path_from(from_node),node,postpone=False)
-	path=tsk.get_install_path()
-	if self.bld.is_install<0:
-		Logs.info("+ removing byte compiled python files")
-		for x in'co':
-			try:
-				os.remove(path+x)
-			except OSError:
-				pass
-	if self.bld.is_install>0:
-		try:
-			st1=os.stat(path)
-		except OSError:
-			Logs.error('The python file is missing, this should not happen')
-		for x in['c','o']:
-			do_inst=self.env['PY'+x.upper()]
-			try:
-				st2=os.stat(path+x)
-			except OSError:
-				pass
-			else:
-				if st1.st_mtime<=st2.st_mtime:
-					do_inst=False
-			if do_inst:
-				lst=(x=='o')and[self.env['PYFLAGS_OPT']]or[]
-				(a,b,c)=(path,path+x,tsk.get_install_path(destdir=False)+x)
-				argv=self.env['PYTHON']+lst+['-c',INST,a,b,c]
-				Logs.info('+ byte compiling %r'%(path+x))
-				env=self.env.env or None
-				ret=Utils.subprocess.Popen(argv,env=env).wait()
-				if ret:
-					raise Errors.WafError('py%s compilation failed %r'%(x,path))
-@feature('py')
-def feature_py(self):
-	pass
+	assert(node.get_bld_sig())
+	assert(getattr(self,'install_path')),'add features="py"'
+	if self.install_path:
+		if self.install_from:
+			self.bld.install_files(self.install_path,[node],cwd=self.install_from,relative_trick=True)
+		else:
+			self.bld.install_files(self.install_path,[node],relative_trick=True)
+	lst=[]
+	if self.env.PYC:
+		lst.append('pyc')
+	if self.env.PYO:
+		lst.append('pyo')
+	if self.install_path:
+		if self.install_from:
+			pyd=Utils.subst_vars("%s/%s"%(self.install_path,node.path_from(self.install_from)),self.env)
+		else:
+			pyd=Utils.subst_vars("%s/%s"%(self.install_path,node.path_from(self.path)),self.env)
+	else:
+		pyd=node.abspath()
+	for ext in lst:
+		if self.env.PYTAG:
+			name=node.name[:-3]
+			pyobj=node.parent.get_bld().make_node('__pycache__').make_node("%s.%s.%s"%(name,self.env.PYTAG,ext))
+			pyobj.parent.mkdir()
+		else:
+			pyobj=node.change_ext(".%s"%ext)
+		tsk=self.create_task(ext,node,pyobj)
+		tsk.pyd=pyd
+		if self.install_path:
+			self.bld.install_files(os.path.dirname(pyd),pyobj,cwd=node.parent.get_bld(),relative_trick=True)
+class pyc(Task.Task):
+	color='PINK'
+	def run(self):
+		cmd=[Utils.subst_vars('${PYTHON}',self.env),'-c',INST,self.inputs[0].abspath(),self.outputs[0].abspath(),self.pyd]
+		ret=self.generator.bld.exec_command(cmd)
+		return ret
+class pyo(Task.Task):
+	color='PINK'
+	def run(self):
+		cmd=[Utils.subst_vars('${PYTHON}',self.env),Utils.subst_vars('${PYFLAGS_OPT}',self.env),'-c',INST,self.inputs[0].abspath(),self.outputs[0].abspath(),self.pyd]
+		ret=self.generator.bld.exec_command(cmd)
+		return ret
 @feature('pyext')
 @before_method('propagate_uselib_vars','apply_link')
@@ -132,5 +134,5 @@
 	self.to_log(out)
 	return_values=[]
-	for s in out.split('\n'):
+	for s in out.splitlines():
 		s=s.strip()
 		if not s:
@@ -145,14 +147,44 @@
 	return return_values
 @conf
-def check_python_headers(conf):
+def python_cross_compile(self,features='pyembed pyext'):
+	features=Utils.to_list(features)
+	if not('PYTHON_LDFLAGS'in self.environ or'PYTHON_PYEXT_LDFLAGS'in self.environ or'PYTHON_PYEMBED_LDFLAGS'in self.environ):
+		return False
+	for x in'PYTHON_VERSION PYTAG pyext_PATTERN'.split():
+		if not x in self.environ:
+			self.fatal('Please set %s in the os environment'%x)
+		else:
+			self.env[x]=self.environ[x]
+	xx=self.env.CXX_NAME and'cxx'or'c'
+	if'pyext'in features:
+		flags=self.environ.get('PYTHON_PYEXT_LDFLAGS',self.environ.get('PYTHON_LDFLAGS',None))
+		if flags is None:
+			self.fatal('No flags provided through PYTHON_PYEXT_LDFLAGS as required')
+		else:
+			self.parse_flags(flags,'PYEXT')
+		self.check(header_name='Python.h',define_name='HAVE_PYEXT',msg='Testing pyext configuration',features='%s %sshlib pyext'%(xx,xx),fragment=FRAG,errmsg='Could not build python extensions')
+	if'pyembed'in features:
+		flags=self.environ.get('PYTHON_PYEMBED_LDFLAGS',self.environ.get('PYTHON_LDFLAGS',None))
+		if flags is None:
+			self.fatal('No flags provided through PYTHON_PYEMBED_LDFLAGS as required')
+		else:
+			self.parse_flags(flags,'PYEMBED')
+		self.check(header_name='Python.h',define_name='HAVE_PYEMBED',msg='Testing pyembed configuration',fragment=FRAG,errmsg='Could not build a python embedded interpreter',features='%s %sprogram pyembed'%(xx,xx))
+	return True
+@conf
+def check_python_headers(conf,features='pyembed pyext'):
+	features=Utils.to_list(features)
+	assert('pyembed'in features)or('pyext'in features),"check_python_headers features must include 'pyembed' and/or 'pyext'"
 	env=conf.env
 	if not env['CC_NAME']and not env['CXX_NAME']:
 		conf.fatal('load a compiler first (gcc, g++, ..)')
+	if conf.python_cross_compile(features):
+		return
 	if not env['PYTHON_VERSION']:
 		conf.check_python_version()
-	pybin=conf.env.PYTHON
+	pybin=env.PYTHON
 	if not pybin:
 		conf.fatal('Could not find the python executable')
-	v='prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS'.split()
+	v='prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS LDVERSION'.split()
 	try:
 		lst=conf.get_python_variables(["get_config_var('%s') or ''"%x for x in v])
@@ -160,10 +192,27 @@
 		conf.fatal("Python development headers not found (-v for details).")
 	vals=['%s = %r'%(x,y)for(x,y)in zip(v,lst)]
-	conf.to_log("Configuration returned from %r:\n%r\n"%(pybin,'\n'.join(vals)))
+	conf.to_log("Configuration returned from %r:\n%s\n"%(pybin,'\n'.join(vals)))
 	dct=dict(zip(v,lst))
 	x='MACOSX_DEPLOYMENT_TARGET'
 	if dct[x]:
-		conf.env[x]=conf.environ[x]=dct[x]
+		env[x]=conf.environ[x]=dct[x]
 	env['pyext_PATTERN']='%s'+dct['SO']
+	num='.'.join(env['PYTHON_VERSION'].split('.')[:2])
+	conf.find_program([''.join(pybin)+'-config','python%s-config'%num,'python-config-%s'%num,'python%sm-config'%num],var='PYTHON_CONFIG',msg="python-config",mandatory=False)
+	if env.PYTHON_CONFIG:
+		all_flags=[['--cflags','--libs','--ldflags']]
+		if sys.hexversion<0x2070000:
+			all_flags=[[k]for k in all_flags[0]]
+		xx=env.CXX_NAME and'cxx'or'c'
+		if'pyembed'in features:
+			for flags in all_flags:
+				conf.check_cfg(msg='Asking python-config for pyembed %r flags'%' '.join(flags),path=env.PYTHON_CONFIG,package='',uselib_store='PYEMBED',args=flags)
+			conf.check(header_name='Python.h',define_name='HAVE_PYEMBED',msg='Getting pyembed flags from python-config',fragment=FRAG,errmsg='Could not build a python embedded interpreter',features='%s %sprogram pyembed'%(xx,xx))
+		if'pyext'in features:
+			for flags in all_flags:
+				conf.check_cfg(msg='Asking python-config for pyext %r flags'%' '.join(flags),path=env.PYTHON_CONFIG,package='',uselib_store='PYEXT',args=flags)
+			conf.check(header_name='Python.h',define_name='HAVE_PYEXT',msg='Getting pyext flags from python-config',features='%s %sshlib pyext'%(xx,xx),fragment=FRAG,errmsg='Could not build python extensions')
+		conf.define('HAVE_PYTHON_H',1)
+		return
 	all_flags=dct['LDFLAGS']+' '+dct['CFLAGS']
 	conf.parse_flags(all_flags,'PYEMBED')
@@ -171,5 +220,7 @@
 	conf.parse_flags(all_flags,'PYEXT')
 	result=None
-	for name in('python'+env['PYTHON_VERSION'],'python'+env['PYTHON_VERSION']+'m','python'+env['PYTHON_VERSION'].replace('.','')):
+	if not dct["LDVERSION"]:
+		dct["LDVERSION"]=env['PYTHON_VERSION']
+	for name in('python'+dct['LDVERSION'],'python'+env['PYTHON_VERSION']+'m','python'+env['PYTHON_VERSION'].replace('.','')):
 		if not result and env['LIBPATH_PYEMBED']:
 			path=env['LIBPATH_PYEMBED']
@@ -195,23 +246,10 @@
 	else:
 		conf.to_log("\n\n### LIB NOT FOUND\n")
-	if(Utils.is_win32 or sys.platform.startswith('os2')or dct['Py_ENABLE_SHARED']):
+	if Utils.is_win32 or dct['Py_ENABLE_SHARED']:
 		env['LIBPATH_PYEXT']=env['LIBPATH_PYEMBED']
 		env['LIB_PYEXT']=env['LIB_PYEMBED']
-	num='.'.join(env['PYTHON_VERSION'].split('.')[:2])
-	conf.find_program([''.join(pybin)+'-config','python%s-config'%num,'python-config-%s'%num,'python%sm-config'%num],var='PYTHON_CONFIG',mandatory=False)
-	includes=[]
-	if conf.env.PYTHON_CONFIG:
-		for incstr in conf.cmd_and_log([conf.env.PYTHON_CONFIG,'--includes']).strip().split():
-			if(incstr.startswith('-I')or incstr.startswith('/I')):
-				incstr=incstr[2:]
-			if incstr not in includes:
-				includes.append(incstr)
-		conf.to_log("Include path for Python extensions (found via python-config --includes): %r\n"%(includes,))
-		env['INCLUDES_PYEXT']=includes
-		env['INCLUDES_PYEMBED']=includes
-	else:
-		conf.to_log("Include path for Python extensions ""(found via distutils module): %r\n"%(dct['INCLUDEPY'],))
-		env['INCLUDES_PYEXT']=[dct['INCLUDEPY']]
-		env['INCLUDES_PYEMBED']=[dct['INCLUDEPY']]
+	conf.to_log("Include path for Python extensions (found via distutils module): %r\n"%(dct['INCLUDEPY'],))
+	env['INCLUDES_PYEXT']=[dct['INCLUDEPY']]
+	env['INCLUDES_PYEMBED']=[dct['INCLUDEPY']]
 	if env['CC_NAME']=='gcc':
 		env.append_value('CFLAGS_PYEMBED',['-fno-strict-aliasing'])
@@ -227,15 +265,5 @@
 		env.append_value('CXXFLAGS_PYEXT',dist_compiler.compile_options)
 		env.append_value('LINKFLAGS_PYEXT',dist_compiler.ldflags_shared)
-	try:
-		conf.check(header_name='Python.h',define_name='HAVE_PYTHON_H',uselib='PYEMBED',fragment=FRAG,errmsg=':-(')
-	except conf.errors.ConfigurationError:
-		xx=conf.env.CXX_NAME and'cxx'or'c'
-		flags=['--cflags','--libs','--ldflags']
-		for f in flags:
-			conf.check_cfg(msg='Asking python-config for pyembed %s flags'%f,path=conf.env.PYTHON_CONFIG,package='',uselib_store='PYEMBED',args=[f])
-		conf.check(header_name='Python.h',define_name='HAVE_PYTHON_H',msg='Getting pyembed flags from python-config',fragment=FRAG,errmsg='Could not build a python embedded interpreter',features='%s %sprogram pyembed'%(xx,xx))
-		for f in flags:
-			conf.check_cfg(msg='Asking python-config for pyext %s flags'%f,path=conf.env.PYTHON_CONFIG,package='',uselib_store='PYEXT',args=[f])
-		conf.check(header_name='Python.h',define_name='HAVE_PYTHON_H',msg='Getting pyext flags from python-config',features='%s %sshlib pyext'%(xx,xx),fragment=FRAG,errmsg='Could not build python extensions')
+	conf.check(header_name='Python.h',define_name='HAVE_PYTHON_H',uselib='PYEMBED',fragment=FRAG,errmsg='Distutils not installed? Broken python installation? Get python-config now!')
 @conf
 def check_python_version(conf,minver=None):
@@ -253,12 +281,14 @@
 		pyver='.'.join([str(x)for x in pyver_tuple[:2]])
 		conf.env['PYTHON_VERSION']=pyver
-		if'PYTHONDIR'in conf.environ:
+		if'PYTHONDIR'in conf.env:
+			pydir=conf.env['PYTHONDIR']
+		elif'PYTHONDIR'in conf.environ:
 			pydir=conf.environ['PYTHONDIR']
 		else:
 			if Utils.is_win32:
-				(python_LIBDEST,pydir)=conf.get_python_variables(["get_config_var('LIBDEST') or ''","get_python_lib(standard_lib=0, prefix=%r) or ''"%conf.env['PREFIX']])
+				(python_LIBDEST,pydir)=conf.get_python_variables(["get_config_var('LIBDEST') or ''","get_python_lib(standard_lib=0) or ''"])
 			else:
 				python_LIBDEST=None
-				(pydir,)=conf.get_python_variables(["get_python_lib(standard_lib=0, prefix=%r) or ''"%conf.env['PREFIX']])
+				(pydir,)=conf.get_python_variables(["get_python_lib(standard_lib=0) or ''"])
 			if python_LIBDEST is None:
 				if conf.env['LIBDIR']:
@@ -266,8 +296,10 @@
 				else:
 					python_LIBDEST=os.path.join(conf.env['PREFIX'],"lib","python"+pyver)
-		if'PYTHONARCHDIR'in conf.environ:
+		if'PYTHONARCHDIR'in conf.env:
+			pyarchdir=conf.env['PYTHONARCHDIR']
+		elif'PYTHONARCHDIR'in conf.environ:
 			pyarchdir=conf.environ['PYTHONARCHDIR']
 		else:
-			(pyarchdir,)=conf.get_python_variables(["get_python_lib(plat_specific=1, standard_lib=0, prefix=%r) or ''"%conf.env['PREFIX']])
+			(pyarchdir,)=conf.get_python_variables(["get_python_lib(plat_specific=1, standard_lib=0) or ''"])
 			if not pyarchdir:
 				pyarchdir=pydir
@@ -289,11 +321,11 @@
 version = getattr(current_module, '__version__', None)
 if version is not None:
-    print(str(version))
+	print(str(version))
 else:
-    print('unknown version')
+	print('unknown version')
 '''
 @conf
 def check_python_module(conf,module_name,condition=''):
-	msg='Python module %s'%module_name
+	msg="Checking for python module '%s'"%module_name
 	if condition:
 		msg='%s (%s)'%(msg,condition)
@@ -325,19 +357,24 @@
 			conf.end_msg(ret)
 def configure(conf):
-	try:
-		conf.find_program('python',var='PYTHON')
-	except conf.errors.ConfigurationError:
-		Logs.warn("could not find a python executable, setting to sys.executable '%s'"%sys.executable)
-		conf.env.PYTHON=sys.executable
-	if conf.env.PYTHON!=sys.executable:
-		Logs.warn("python executable %r differs from system %r"%(conf.env.PYTHON,sys.executable))
-	conf.env.PYTHON=conf.cmd_to_list(conf.env.PYTHON)
 	v=conf.env
-	v['PYCMD']='"import sys, py_compile;py_compile.compile(sys.argv[1], sys.argv[2])"'
+	v['PYTHON']=Options.options.python or os.environ.get('PYTHON',sys.executable)
+	if Options.options.pythondir:
+		v['PYTHONDIR']=Options.options.pythondir
+	if Options.options.pythonarchdir:
+		v['PYTHONARCHDIR']=Options.options.pythonarchdir
+	conf.find_program('python',var='PYTHON')
 	v['PYFLAGS']=''
 	v['PYFLAGS_OPT']='-O'
 	v['PYC']=getattr(Options.options,'pyc',1)
 	v['PYO']=getattr(Options.options,'pyo',1)
+	try:
+		v.PYTAG=conf.cmd_and_log(conf.env.PYTHON+['-c',"import imp;print(imp.get_tag())"]).strip()
+	except Errors.WafError:
+		pass
 def options(opt):
-	opt.add_option('--nopyc',action='store_false',default=1,help='Do not install bytecode compiled .pyc files (configuration) [Default:install]',dest='pyc')
-	opt.add_option('--nopyo',action='store_false',default=1,help='Do not install optimised compiled .pyo files (configuration) [Default:install]',dest='pyo')
+	pyopt=opt.add_option_group("Python Options")
+	pyopt.add_option('--nopyc',dest='pyc',action='store_false',default=1,help='Do not install bytecode compiled .pyc files (configuration) [Default:install]')
+	pyopt.add_option('--nopyo',dest='pyo',action='store_false',default=1,help='Do not install optimised compiled .pyo files (configuration) [Default:install]')
+	pyopt.add_option('--python',dest="python",help='python binary to be used [Default: %s]'%sys.executable)
+	pyopt.add_option('--pythondir',dest='pythondir',help='Installation path for python modules (py, platform-independent .py and .pyc files)')
+	pyopt.add_option('--pythonarchdir',dest='pythonarchdir',help='Installation path for python extension (pyext, platform-dependent .so or .dylib files)')
Index: waflib/Tools/qt4.py
===================================================================
--- waflib/Tools/qt4.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/qt4.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -12,6 +12,6 @@
 	has_xml=True
 import os,sys
-from waflib.Tools import c_preproc,cxx
-from waflib import Task,Utils,Options,Errors
+from waflib.Tools import cxx
+from waflib import Task,Utils,Options,Errors,Context
 from waflib.TaskGen import feature,after_method,extension
 from waflib.Configure import conf
@@ -26,15 +26,4 @@
 		Task.Task.__init__(self,*k,**kw)
 		self.moc_done=0
-	def scan(self):
-		(nodes,names)=c_preproc.scan(self)
-		lst=[]
-		for x in nodes:
-			if x.name.endswith('.moc'):
-				s=x.path_from(self.inputs[0].parent.get_bld())
-				if s not in names:
-					names.append(s)
-			else:
-				lst.append(x)
-		return(lst,names)
 	def runnable_status(self):
 		if self.moc_done:
@@ -57,8 +46,18 @@
 			tsk.set_inputs(h_node)
 			tsk.set_outputs(m_node)
+			if self.generator:
+				self.generator.tasks.append(tsk)
 			gen=self.generator.bld.producer
 			gen.outstanding.insert(0,tsk)
 			gen.total+=1
 			return tsk
+	def moc_h_ext(self):
+		try:
+			ext=Options.options.qt_header_ext.split()
+		except AttributeError:
+			pass
+		if not ext:
+			ext=MOC_H
+		return ext
 	def add_moc_tasks(self):
 		node=self.inputs[0]
@@ -70,25 +69,17 @@
 		else:
 			delattr(self,'cache_sig')
+		include_nodes=[node.parent]+self.generator.includes_nodes
 		moctasks=[]
-		mocfiles=[]
-		try:
-			tmp_lst=bld.raw_deps[self.uid()]
-			bld.raw_deps[self.uid()]=[]
-		except KeyError:
-			tmp_lst=[]
-		for d in tmp_lst:
+		mocfiles=set([])
+		for d in bld.raw_deps.get(self.uid(),[]):
 			if not d.endswith('.moc'):
 				continue
 			if d in mocfiles:
-				Logs.error("paranoia owns")
 				continue
-			mocfiles.append(d)
+			mocfiles.add(d)
 			h_node=None
-			try:ext=Options.options.qt_header_ext.split()
-			except AttributeError:pass
-			if not ext:ext=MOC_H
 			base2=d[:-4]
-			for x in[node.parent]+self.generator.includes_nodes:
-				for e in ext:
+			for x in include_nodes:
+				for e in self.moc_h_ext():
 					h_node=x.find_node(base2+e)
 					if h_node:
@@ -100,26 +91,17 @@
 				for k in EXT_QT4:
 					if base2.endswith(k):
-						for x in[node.parent]+self.generator.includes_nodes:
+						for x in include_nodes:
 							h_node=x.find_node(base2)
 							if h_node:
 								break
-					if h_node:
-						m_node=h_node.change_ext(k+'.moc')
-						break
+						if h_node:
+							m_node=h_node.change_ext(k+'.moc')
+							break
 			if not h_node:
-				raise Errors.WafError('no header found for %r which is a moc file'%d)
-			bld.node_deps[(self.inputs[0].parent.abspath(),m_node.name)]=h_node
+				raise Errors.WafError('No source found for %r which is a moc file'%d)
 			task=self.create_moc_task(h_node,m_node)
 			moctasks.append(task)
-		tmp_lst=bld.raw_deps[self.uid()]=mocfiles
-		lst=bld.node_deps.get(self.uid(),())
-		for d in lst:
-			name=d.name
-			if name.endswith('.moc'):
-				task=self.create_moc_task(bld.node_deps[(self.inputs[0].parent.abspath(),name)],d)
-				moctasks.append(task)
 		self.run_after.update(set(moctasks))
 		self.moc_done=1
-	run=Task.classes['cxx'].__dict__['run']
 class trans_update(Task.Task):
 	run_str='${QT_LUPDATE} ${SRC} -ts ${TGT}'
@@ -141,5 +123,5 @@
 def create_rcc_task(self,node):
 	rcnode=node.change_ext('_rc.cpp')
-	rcctask=self.create_task('rcc',node,rcnode)
+	self.create_task('rcc',node,rcnode)
 	cpptask=self.create_task('cxx',rcnode,rcnode.change_ext('.o'))
 	try:
@@ -180,5 +162,5 @@
 		if len(flag)<2:continue
 		f=flag[0:2]
-		if f in['-D','-I','/D','/I']:
+		if f in('-D','-I','/D','/I'):
 			if(f[0]=='/'):
 				lst.append('-'+flag[1:])
@@ -191,8 +173,9 @@
 class rcc(Task.Task):
 	color='BLUE'
-	run_str='${QT_RCC} -name ${SRC[0].name} ${SRC[0].abspath()} ${RCC_ST} -o ${TGT}'
+	run_str='${QT_RCC} -name ${tsk.rcname()} ${SRC[0].abspath()} ${RCC_ST} -o ${TGT}'
 	ext_out=['.h']
+	def rcname(self):
+		return os.path.splitext(self.inputs[0].name)[0]
 	def scan(self):
-		node=self.inputs[0]
 		if not has_xml:
 			Logs.error('no xml support was found, the rcc dependencies will be incomplete!')
@@ -217,4 +200,8 @@
 	color='BLUE'
 	run_str='${QT_MOC} ${MOC_FLAGS} ${MOCCPPPATH_ST:INCPATHS} ${MOCDEFINES_ST:DEFINES} ${SRC} ${MOC_ST} ${TGT}'
+	def keyword(self):
+		return"Creating"
+	def __str__(self):
+		return self.outputs[0].path_from(self.generator.bld.launch_node())
 class ui4(Task.Task):
 	color='BLUE'
@@ -268,5 +255,5 @@
 	cand=None
 	prev_ver=['4','0','0']
-	for qmk in['qmake-qt4','qmake4','qmake']:
+	for qmk in('qmake-qt4','qmake4','qmake'):
 		try:
 			qmake=self.find_program(qmk,path_list=paths)
@@ -275,5 +262,5 @@
 		else:
 			try:
-				version=self.cmd_and_log([qmake,'-query','QT_VERSION']).strip()
+				version=self.cmd_and_log(qmake+['-query','QT_VERSION']).strip()
 			except self.errors.WafError:
 				pass
@@ -288,5 +275,5 @@
 	else:
 		self.fatal('Could not find qmake for qt4')
-	qtbin=self.cmd_and_log([self.env.QMAKE,'-query','QT_INSTALL_BINS']).strip()+os.sep
+	qtbin=self.cmd_and_log(self.env.QMAKE+['-query','QT_INSTALL_BINS']).strip()+os.sep
 	def find_bin(lst,var):
 		if var in env:
@@ -302,16 +289,15 @@
 	find_bin(['uic-qt3','uic3'],'QT_UIC3')
 	find_bin(['uic-qt4','uic'],'QT_UIC')
-	if not env['QT_UIC']:
+	if not env.QT_UIC:
 		self.fatal('cannot find the uic compiler for qt4')
-	try:
-		uicver=self.cmd_and_log(env['QT_UIC']+" -version 2>&1").strip()
-	except self.errors.ConfigurationError:
-		self.fatal('this uic compiler is for qt3, add uic for qt4 to your path')
+	self.start_msg('Checking for uic version')
+	uicver=self.cmd_and_log(env.QT_UIC+["-version"],output=Context.BOTH)
+	uicver=''.join(uicver).strip()
 	uicver=uicver.replace('Qt User Interface Compiler ','').replace('User Interface Compiler for Qt','')
-	self.msg('Checking for uic version','%s'%uicver)
+	self.end_msg(uicver)
 	if uicver.find(' 3.')!=-1:
 		self.fatal('this uic compiler is for qt3, add uic for qt4 to your path')
 	find_bin(['moc-qt4','moc'],'QT_MOC')
-	find_bin(['rcc'],'QT_RCC')
+	find_bin(['rcc-qt4','rcc'],'QT_RCC')
 	find_bin(['lrelease-qt4','lrelease'],'QT_LRELEASE')
 	find_bin(['lupdate-qt4','lupdate'],'QT_LUPDATE')
@@ -328,10 +314,10 @@
 	if not qtlibs:
 		try:
-			qtlibs=self.cmd_and_log([self.env.QMAKE,'-query','QT_INSTALL_LIBS']).strip()
+			qtlibs=self.cmd_and_log(self.env.QMAKE+['-query','QT_INSTALL_LIBS']).strip()
 		except Errors.WafError:
-			qtdir=self.cmd_and_log([self.env.QMAKE,'-query','QT_INSTALL_PREFIX']).strip()+os.sep
+			qtdir=self.cmd_and_log(self.env.QMAKE+['-query','QT_INSTALL_PREFIX']).strip()+os.sep
 			qtlibs=os.path.join(qtdir,'lib')
 	self.msg('Found the Qt4 libraries in',qtlibs)
-	qtincludes=os.environ.get("QT4_INCLUDES",None)or self.cmd_and_log([self.env.QMAKE,'-query','QT_INSTALL_HEADERS']).strip()
+	qtincludes=os.environ.get("QT4_INCLUDES",None)or self.cmd_and_log(self.env.QMAKE+['-query','QT_INSTALL_HEADERS']).strip()
 	env=self.env
 	if not'PKG_CONFIG_PATH'in os.environ:
Index: waflib/Tools/qt5.py
===================================================================
--- waflib/Tools/qt5.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
+++ waflib/Tools/qt5.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -0,0 +1,488 @@
+#! /usr/bin/env python
+# encoding: utf-8
+# WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
+
+try:
+	from xml.sax import make_parser
+	from xml.sax.handler import ContentHandler
+except ImportError:
+	has_xml=False
+	ContentHandler=object
+else:
+	has_xml=True
+import os,sys
+from waflib.Tools import cxx
+from waflib import Task,Utils,Options,Errors,Context
+from waflib.TaskGen import feature,after_method,extension
+from waflib.Configure import conf
+from waflib import Logs
+MOC_H=['.h','.hpp','.hxx','.hh']
+EXT_RCC=['.qrc']
+EXT_UI=['.ui']
+EXT_QT5=['.cpp','.cc','.cxx','.C']
+QT5_LIBS='''
+qtmain
+Qt5Bluetooth
+Qt5CLucene
+Qt5Concurrent
+Qt5Core
+Qt5DBus
+Qt5Declarative
+Qt5DesignerComponents
+Qt5Designer
+Qt5Gui
+Qt5Help
+Qt5MultimediaQuick_p
+Qt5Multimedia
+Qt5MultimediaWidgets
+Qt5Network
+Qt5Nfc
+Qt5OpenGL
+Qt5Positioning
+Qt5PrintSupport
+Qt5Qml
+Qt5QuickParticles
+Qt5Quick
+Qt5QuickTest
+Qt5Script
+Qt5ScriptTools
+Qt5Sensors
+Qt5SerialPort
+Qt5Sql
+Qt5Svg
+Qt5Test
+Qt5WebKit
+Qt5WebKitWidgets
+Qt5Widgets
+Qt5WinExtras
+Qt5X11Extras
+Qt5XmlPatterns
+Qt5Xml'''
+class qxx(Task.classes['cxx']):
+	def __init__(self,*k,**kw):
+		Task.Task.__init__(self,*k,**kw)
+		self.moc_done=0
+	def runnable_status(self):
+		if self.moc_done:
+			return Task.Task.runnable_status(self)
+		else:
+			for t in self.run_after:
+				if not t.hasrun:
+					return Task.ASK_LATER
+			self.add_moc_tasks()
+			return Task.Task.runnable_status(self)
+	def create_moc_task(self,h_node,m_node):
+		try:
+			moc_cache=self.generator.bld.moc_cache
+		except AttributeError:
+			moc_cache=self.generator.bld.moc_cache={}
+		try:
+			return moc_cache[h_node]
+		except KeyError:
+			tsk=moc_cache[h_node]=Task.classes['moc'](env=self.env,generator=self.generator)
+			tsk.set_inputs(h_node)
+			tsk.set_outputs(m_node)
+			if self.generator:
+				self.generator.tasks.append(tsk)
+			gen=self.generator.bld.producer
+			gen.outstanding.insert(0,tsk)
+			gen.total+=1
+			return tsk
+		else:
+			delattr(self,'cache_sig')
+	def moc_h_ext(self):
+		try:
+			ext=Options.options.qt_header_ext.split()
+		except AttributeError:
+			pass
+		if not ext:
+			ext=MOC_H
+		return ext
+	def add_moc_tasks(self):
+		node=self.inputs[0]
+		bld=self.generator.bld
+		try:
+			self.signature()
+		except KeyError:
+			pass
+		else:
+			delattr(self,'cache_sig')
+		include_nodes=[node.parent]+self.generator.includes_nodes
+		moctasks=[]
+		mocfiles=set([])
+		for d in bld.raw_deps.get(self.uid(),[]):
+			if not d.endswith('.moc'):
+				continue
+			if d in mocfiles:
+				continue
+			mocfiles.add(d)
+			h_node=None
+			base2=d[:-4]
+			for x in include_nodes:
+				for e in self.moc_h_ext():
+					h_node=x.find_node(base2+e)
+					if h_node:
+						break
+				if h_node:
+					m_node=h_node.change_ext('.moc')
+					break
+			else:
+				for k in EXT_QT5:
+					if base2.endswith(k):
+						for x in include_nodes:
+							h_node=x.find_node(base2)
+							if h_node:
+								break
+						if h_node:
+							m_node=h_node.change_ext(k+'.moc')
+							break
+			if not h_node:
+				raise Errors.WafError('No source found for %r which is a moc file'%d)
+			task=self.create_moc_task(h_node,m_node)
+			moctasks.append(task)
+		self.run_after.update(set(moctasks))
+		self.moc_done=1
+class trans_update(Task.Task):
+	run_str='${QT_LUPDATE} ${SRC} -ts ${TGT}'
+	color='BLUE'
+Task.update_outputs(trans_update)
+class XMLHandler(ContentHandler):
+	def __init__(self):
+		self.buf=[]
+		self.files=[]
+	def startElement(self,name,attrs):
+		if name=='file':
+			self.buf=[]
+	def endElement(self,name):
+		if name=='file':
+			self.files.append(str(''.join(self.buf)))
+	def characters(self,cars):
+		self.buf.append(cars)
+@extension(*EXT_RCC)
+def create_rcc_task(self,node):
+	rcnode=node.change_ext('_rc.cpp')
+	self.create_task('rcc',node,rcnode)
+	cpptask=self.create_task('cxx',rcnode,rcnode.change_ext('.o'))
+	try:
+		self.compiled_tasks.append(cpptask)
+	except AttributeError:
+		self.compiled_tasks=[cpptask]
+	return cpptask
+@extension(*EXT_UI)
+def create_uic_task(self,node):
+	uictask=self.create_task('ui5',node)
+	uictask.outputs=[self.path.find_or_declare(self.env['ui_PATTERN']%node.name[:-3])]
+@extension('.ts')
+def add_lang(self,node):
+	self.lang=self.to_list(getattr(self,'lang',[]))+[node]
+@feature('qt5')
+@after_method('apply_link')
+def apply_qt5(self):
+	if getattr(self,'lang',None):
+		qmtasks=[]
+		for x in self.to_list(self.lang):
+			if isinstance(x,str):
+				x=self.path.find_resource(x+'.ts')
+			qmtasks.append(self.create_task('ts2qm',x,x.change_ext('.qm')))
+		if getattr(self,'update',None)and Options.options.trans_qt5:
+			cxxnodes=[a.inputs[0]for a in self.compiled_tasks]+[a.inputs[0]for a in self.tasks if getattr(a,'inputs',None)and a.inputs[0].name.endswith('.ui')]
+			for x in qmtasks:
+				self.create_task('trans_update',cxxnodes,x.inputs)
+		if getattr(self,'langname',None):
+			qmnodes=[x.outputs[0]for x in qmtasks]
+			rcnode=self.langname
+			if isinstance(rcnode,str):
+				rcnode=self.path.find_or_declare(rcnode+'.qrc')
+			t=self.create_task('qm2rcc',qmnodes,rcnode)
+			k=create_rcc_task(self,t.outputs[0])
+			self.link_task.inputs.append(k.outputs[0])
+	lst=[]
+	for flag in self.to_list(self.env['CXXFLAGS']):
+		if len(flag)<2:continue
+		f=flag[0:2]
+		if f in('-D','-I','/D','/I'):
+			if(f[0]=='/'):
+				lst.append('-'+flag[1:])
+			else:
+				lst.append(flag)
+	self.env.append_value('MOC_FLAGS',lst)
+@extension(*EXT_QT5)
+def cxx_hook(self,node):
+	return self.create_compiled_task('qxx',node)
+class rcc(Task.Task):
+	color='BLUE'
+	run_str='${QT_RCC} -name ${tsk.rcname()} ${SRC[0].abspath()} ${RCC_ST} -o ${TGT}'
+	ext_out=['.h']
+	def rcname(self):
+		return os.path.splitext(self.inputs[0].name)[0]
+	def scan(self):
+		if not has_xml:
+			Logs.error('no xml support was found, the rcc dependencies will be incomplete!')
+			return([],[])
+		parser=make_parser()
+		curHandler=XMLHandler()
+		parser.setContentHandler(curHandler)
+		fi=open(self.inputs[0].abspath(),'r')
+		try:
+			parser.parse(fi)
+		finally:
+			fi.close()
+		nodes=[]
+		names=[]
+		root=self.inputs[0].parent
+		for x in curHandler.files:
+			nd=root.find_resource(x)
+			if nd:nodes.append(nd)
+			else:names.append(x)
+		return(nodes,names)
+class moc(Task.Task):
+	color='BLUE'
+	run_str='${QT_MOC} ${MOC_FLAGS} ${MOCCPPPATH_ST:INCPATHS} ${MOCDEFINES_ST:DEFINES} ${SRC} ${MOC_ST} ${TGT}'
+class ui5(Task.Task):
+	color='BLUE'
+	run_str='${QT_UIC} ${SRC} -o ${TGT}'
+	ext_out=['.h']
+class ts2qm(Task.Task):
+	color='BLUE'
+	run_str='${QT_LRELEASE} ${QT_LRELEASE_FLAGS} ${SRC} -qm ${TGT}'
+class qm2rcc(Task.Task):
+	color='BLUE'
+	after='ts2qm'
+	def run(self):
+		txt='\n'.join(['<file>%s</file>'%k.path_from(self.outputs[0].parent)for k in self.inputs])
+		code='<!DOCTYPE RCC><RCC version="1.0">\n<qresource>\n%s\n</qresource>\n</RCC>'%txt
+		self.outputs[0].write(code)
+def configure(self):
+	self.find_qt5_binaries()
+	self.set_qt5_libs_to_check()
+	self.set_qt5_defines()
+	self.find_qt5_libraries()
+	self.add_qt5_rpath()
+	self.simplify_qt5_libs()
+@conf
+def find_qt5_binaries(self):
+	env=self.env
+	opt=Options.options
+	qtdir=getattr(opt,'qtdir','')
+	qtbin=getattr(opt,'qtbin','')
+	paths=[]
+	if qtdir:
+		qtbin=os.path.join(qtdir,'bin')
+	if not qtdir:
+		qtdir=os.environ.get('QT5_ROOT','')
+		qtbin=os.environ.get('QT5_BIN',None)or os.path.join(qtdir,'bin')
+	if qtbin:
+		paths=[qtbin]
+	if not qtdir:
+		paths=os.environ.get('PATH','').split(os.pathsep)
+		paths.append('/usr/share/qt5/bin/')
+		try:
+			lst=Utils.listdir('/usr/local/Trolltech/')
+		except OSError:
+			pass
+		else:
+			if lst:
+				lst.sort()
+				lst.reverse()
+				qtdir='/usr/local/Trolltech/%s/'%lst[0]
+				qtbin=os.path.join(qtdir,'bin')
+				paths.append(qtbin)
+	cand=None
+	prev_ver=['5','0','0']
+	for qmk in('qmake-qt5','qmake5','qmake'):
+		try:
+			qmake=self.find_program(qmk,path_list=paths)
+		except self.errors.ConfigurationError:
+			pass
+		else:
+			try:
+				version=self.cmd_and_log(qmake+['-query','QT_VERSION']).strip()
+			except self.errors.WafError:
+				pass
+			else:
+				if version:
+					new_ver=version.split('.')
+					if new_ver>prev_ver:
+						cand=qmake
+						prev_ver=new_ver
+	if not cand:
+		try:
+			self.find_program('qtchooser')
+		except self.errors.ConfigurationError:
+			pass
+		else:
+			cmd=self.env.QTCHOOSER+['-qt=5','-run-tool=qmake']
+			try:
+				version=self.cmd_and_log(cmd+['-query','QT_VERSION'])
+			except self.errors.WafError:
+				pass
+			else:
+				cand=cmd
+	if cand:
+		self.env.QMAKE=cand
+	else:
+		self.fatal('Could not find qmake for qt5')
+	self.env.QT_INSTALL_BINS=qtbin=self.cmd_and_log(self.env.QMAKE+['-query','QT_INSTALL_BINS']).strip()+os.sep
+	paths.insert(0,qtbin)
+	def find_bin(lst,var):
+		if var in env:
+			return
+		for f in lst:
+			try:
+				ret=self.find_program(f,path_list=paths)
+			except self.errors.ConfigurationError:
+				pass
+			else:
+				env[var]=ret
+				break
+	find_bin(['uic-qt5','uic'],'QT_UIC')
+	if not env.QT_UIC:
+		self.fatal('cannot find the uic compiler for qt5')
+	self.start_msg('Checking for uic version')
+	uicver=self.cmd_and_log(env.QT_UIC+['-version'],output=Context.BOTH)
+	uicver=''.join(uicver).strip()
+	uicver=uicver.replace('Qt User Interface Compiler ','').replace('User Interface Compiler for Qt','')
+	self.end_msg(uicver)
+	if uicver.find(' 3.')!=-1 or uicver.find(' 4.')!=-1:
+		self.fatal('this uic compiler is for qt3 or qt5, add uic for qt5 to your path')
+	find_bin(['moc-qt5','moc'],'QT_MOC')
+	find_bin(['rcc-qt5','rcc'],'QT_RCC')
+	find_bin(['lrelease-qt5','lrelease'],'QT_LRELEASE')
+	find_bin(['lupdate-qt5','lupdate'],'QT_LUPDATE')
+	env['UIC_ST']='%s -o %s'
+	env['MOC_ST']='-o'
+	env['ui_PATTERN']='ui_%s.h'
+	env['QT_LRELEASE_FLAGS']=['-silent']
+	env.MOCCPPPATH_ST='-I%s'
+	env.MOCDEFINES_ST='-D%s'
+@conf
+def find_qt5_libraries(self):
+	qtlibs=getattr(Options.options,'qtlibs',None)or os.environ.get("QT5_LIBDIR",None)
+	if not qtlibs:
+		try:
+			qtlibs=self.cmd_and_log(self.env.QMAKE+['-query','QT_INSTALL_LIBS']).strip()
+		except Errors.WafError:
+			qtdir=self.cmd_and_log(self.env.QMAKE+['-query','QT_INSTALL_PREFIX']).strip()+os.sep
+			qtlibs=os.path.join(qtdir,'lib')
+	self.msg('Found the Qt5 libraries in',qtlibs)
+	qtincludes=os.environ.get("QT5_INCLUDES",None)or self.cmd_and_log(self.env.QMAKE+['-query','QT_INSTALL_HEADERS']).strip()
+	env=self.env
+	if not'PKG_CONFIG_PATH'in os.environ:
+		os.environ['PKG_CONFIG_PATH']='%s:%s/pkgconfig:/usr/lib/qt5/lib/pkgconfig:/opt/qt5/lib/pkgconfig:/usr/lib/qt5/lib:/opt/qt5/lib'%(qtlibs,qtlibs)
+	try:
+		if os.environ.get("QT5_XCOMPILE",None):
+			raise self.errors.ConfigurationError()
+		self.check_cfg(atleast_pkgconfig_version='0.1')
+	except self.errors.ConfigurationError:
+		for i in self.qt5_vars:
+			uselib=i.upper()
+			if Utils.unversioned_sys_platform()=="darwin":
+				frameworkName=i+".framework"
+				qtDynamicLib=os.path.join(qtlibs,frameworkName,i)
+				if os.path.exists(qtDynamicLib):
+					env.append_unique('FRAMEWORK_'+uselib,i)
+					self.msg('Checking for %s'%i,qtDynamicLib,'GREEN')
+				else:
+					self.msg('Checking for %s'%i,False,'YELLOW')
+				env.append_unique('INCLUDES_'+uselib,os.path.join(qtlibs,frameworkName,'Headers'))
+			elif env.DEST_OS!="win32":
+				qtDynamicLib=os.path.join(qtlibs,"lib"+i+".so")
+				qtStaticLib=os.path.join(qtlibs,"lib"+i+".a")
+				if os.path.exists(qtDynamicLib):
+					env.append_unique('LIB_'+uselib,i)
+					self.msg('Checking for %s'%i,qtDynamicLib,'GREEN')
+				elif os.path.exists(qtStaticLib):
+					env.append_unique('LIB_'+uselib,i)
+					self.msg('Checking for %s'%i,qtStaticLib,'GREEN')
+				else:
+					self.msg('Checking for %s'%i,False,'YELLOW')
+				env.append_unique('LIBPATH_'+uselib,qtlibs)
+				env.append_unique('INCLUDES_'+uselib,qtincludes)
+				env.append_unique('INCLUDES_'+uselib,os.path.join(qtincludes,i))
+			else:
+				for k in("lib%s.a","lib%s5.a","%s.lib","%s5.lib"):
+					lib=os.path.join(qtlibs,k%i)
+					if os.path.exists(lib):
+						env.append_unique('LIB_'+uselib,i+k[k.find("%s")+2:k.find('.')])
+						self.msg('Checking for %s'%i,lib,'GREEN')
+						break
+				else:
+					self.msg('Checking for %s'%i,False,'YELLOW')
+				env.append_unique('LIBPATH_'+uselib,qtlibs)
+				env.append_unique('INCLUDES_'+uselib,qtincludes)
+				env.append_unique('INCLUDES_'+uselib,os.path.join(qtincludes,i))
+				uselib=i.upper()+"_debug"
+				for k in("lib%sd.a","lib%sd5.a","%sd.lib","%sd5.lib"):
+					lib=os.path.join(qtlibs,k%i)
+					if os.path.exists(lib):
+						env.append_unique('LIB_'+uselib,i+k[k.find("%s")+2:k.find('.')])
+						self.msg('Checking for %s'%i,lib,'GREEN')
+						break
+				else:
+					self.msg('Checking for %s'%i,False,'YELLOW')
+				env.append_unique('LIBPATH_'+uselib,qtlibs)
+				env.append_unique('INCLUDES_'+uselib,qtincludes)
+				env.append_unique('INCLUDES_'+uselib,os.path.join(qtincludes,i))
+	else:
+		for i in self.qt5_vars_debug+self.qt5_vars:
+			self.check_cfg(package=i,args='--cflags --libs',mandatory=False)
+@conf
+def simplify_qt5_libs(self):
+	env=self.env
+	def process_lib(vars_,coreval):
+		for d in vars_:
+			var=d.upper()
+			if var=='QTCORE':
+				continue
+			value=env['LIBPATH_'+var]
+			if value:
+				core=env[coreval]
+				accu=[]
+				for lib in value:
+					if lib in core:
+						continue
+					accu.append(lib)
+				env['LIBPATH_'+var]=accu
+	process_lib(self.qt5_vars,'LIBPATH_QTCORE')
+	process_lib(self.qt5_vars_debug,'LIBPATH_QTCORE_DEBUG')
+@conf
+def add_qt5_rpath(self):
+	env=self.env
+	if getattr(Options.options,'want_rpath',False):
+		def process_rpath(vars_,coreval):
+			for d in vars_:
+				var=d.upper()
+				value=env['LIBPATH_'+var]
+				if value:
+					core=env[coreval]
+					accu=[]
+					for lib in value:
+						if var!='QTCORE':
+							if lib in core:
+								continue
+						accu.append('-Wl,--rpath='+lib)
+					env['RPATH_'+var]=accu
+		process_rpath(self.qt5_vars,'LIBPATH_QTCORE')
+		process_rpath(self.qt5_vars_debug,'LIBPATH_QTCORE_DEBUG')
+@conf
+def set_qt5_libs_to_check(self):
+	if not hasattr(self,'qt5_vars'):
+		self.qt5_vars=QT5_LIBS
+	self.qt5_vars=Utils.to_list(self.qt5_vars)
+	if not hasattr(self,'qt5_vars_debug'):
+		self.qt5_vars_debug=[a+'_debug'for a in self.qt5_vars]
+	self.qt5_vars_debug=Utils.to_list(self.qt5_vars_debug)
+@conf
+def set_qt5_defines(self):
+	if sys.platform!='win32':
+		return
+	for x in self.qt5_vars:
+		y=x[2:].upper()
+		self.env.append_unique('DEFINES_%s'%x.upper(),'QT_%s_LIB'%y)
+		self.env.append_unique('DEFINES_%s_DEBUG'%x.upper(),'QT_%s_LIB'%y)
+def options(opt):
+	opt.add_option('--want-rpath',action='store_true',default=False,dest='want_rpath',help='enable the rpath for qt libraries')
+	opt.add_option('--header-ext',type='string',default='',help='header extension for moc files',dest='qt_header_ext')
+	for i in'qtdir qtbin qtlibs'.split():
+		opt.add_option('--'+i,type='string',default='',dest=i)
+	opt.add_option('--translate',action="store_true",help="collect translation strings",dest="trans_qt5",default=False)
Index: waflib/Tools/ruby.py
===================================================================
--- waflib/Tools/ruby.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/ruby.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -28,5 +28,5 @@
 	ruby=self.env.RUBY
 	try:
-		version=self.cmd_and_log([ruby,'-e','puts defined?(VERSION) ? VERSION : RUBY_VERSION']).strip()
+		version=self.cmd_and_log(ruby+['-e','puts defined?(VERSION) ? VERSION : RUBY_VERSION']).strip()
 	except Exception:
 		self.fatal('could not determine ruby version')
@@ -52,7 +52,7 @@
 	version=tuple(map(int,self.env.RUBY_VERSION.split(".")))
 	def read_out(cmd):
-		return Utils.to_list(self.cmd_and_log([self.env.RUBY,'-rrbconfig','-e',cmd]))
+		return Utils.to_list(self.cmd_and_log(self.env.RUBY+['-rrbconfig','-e',cmd]))
 	def read_config(key):
-		return read_out('puts Config::CONFIG[%r]'%key)
+		return read_out('puts RbConfig::CONFIG[%r]'%key)
 	ruby=self.env['RUBY']
 	archdir=read_config('archdir')
@@ -88,5 +88,5 @@
 	self.start_msg('Ruby module %s'%module_name)
 	try:
-		self.cmd_and_log([self.env['RUBY'],'-e','require \'%s\';puts 1'%module_name])
+		self.cmd_and_log(self.env.RUBY+['-e','require \'%s\';puts 1'%module_name])
 	except Exception:
 		self.end_msg(False)
Index: waflib/Tools/suncc.py
===================================================================
--- waflib/Tools/suncc.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/suncc.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -3,5 +3,4 @@
 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
 
-import os
 from waflib import Utils
 from waflib.Tools import ccroot,ar
@@ -10,16 +9,10 @@
 def find_scc(conf):
 	v=conf.env
-	cc=None
-	if v['CC']:cc=v['CC']
-	elif'CC'in conf.environ:cc=conf.environ['CC']
-	if not cc:cc=conf.find_program('cc',var='CC')
-	if not cc:conf.fatal('Could not find a Sun C compiler')
-	cc=conf.cmd_to_list(cc)
+	cc=conf.find_program('cc',var='CC')
 	try:
 		conf.cmd_and_log(cc+['-flags'])
 	except Exception:
 		conf.fatal('%r is not a Sun compiler'%cc)
-	v['CC']=cc
-	v['CC_NAME']='sun'
+	v.CC_NAME='sun'
 	conf.get_suncc_version(cc)
 @conf
Index: waflib/Tools/suncxx.py
===================================================================
--- waflib/Tools/suncxx.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/suncxx.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -3,5 +3,4 @@
 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
 
-import os
 from waflib import Utils
 from waflib.Tools import ccroot,ar
@@ -10,17 +9,10 @@
 def find_sxx(conf):
 	v=conf.env
-	cc=None
-	if v['CXX']:cc=v['CXX']
-	elif'CXX'in conf.environ:cc=conf.environ['CXX']
-	if not cc:cc=conf.find_program('CC',var='CXX')
-	if not cc:cc=conf.find_program('c++',var='CXX')
-	if not cc:conf.fatal('Could not find a Sun C++ compiler')
-	cc=conf.cmd_to_list(cc)
+	cc=conf.find_program(['CC','c++'],var='CXX')
 	try:
 		conf.cmd_and_log(cc+['-flags'])
 	except Exception:
 		conf.fatal('%r is not a Sun compiler'%cc)
-	v['CXX']=cc
-	v['CXX_NAME']='sun'
+	v.CXX_NAME='sun'
 	conf.get_suncc_version(cc)
 @conf
Index: waflib/Tools/tex.py
===================================================================
--- waflib/Tools/tex.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/tex.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -4,5 +4,5 @@
 
 import os,re
-from waflib import Utils,Task,Errors,Logs
+from waflib import Utils,Task,Errors,Logs,Node
 from waflib.TaskGen import feature,before_method
 re_bibunit=re.compile(r'\\(?P<type>putbib)\[(?P<file>[^\[\]]*)\]',re.M)
@@ -15,5 +15,5 @@
 		path=match.group('file')
 		if path:
-			for k in['','.bib']:
+			for k in('','.bib'):
 				Logs.debug('tex: trying %s%s'%(path,k))
 				fi=node.parent.find_resource(path+k)
@@ -24,8 +24,9 @@
 	Logs.debug("tex: found the following bibunit files: %s"%nodes)
 	return nodes
-exts_deps_tex=['','.ltx','.tex','.bib','.pdf','.png','.eps','.ps']
+exts_deps_tex=['','.ltx','.tex','.bib','.pdf','.png','.eps','.ps','.sty']
 exts_tex=['.ltx','.tex']
-re_tex=re.compile(r'\\(?P<type>include|bibliography|putbib|includegraphics|input|import|bringin|lstinputlisting)(\[[^\[\]]*\])?{(?P<file>[^{}]*)}',re.M)
+re_tex=re.compile(r'\\(?P<type>usepackage|RequirePackage|include|bibliography([^\[\]{}]*)|putbib|includegraphics|input|import|bringin|lstinputlisting)(\[[^\[\]]*\])?{(?P<file>[^{}]*)}',re.M)
 g_bibtex_re=re.compile('bibdata',re.M)
+g_glossaries_re=re.compile('\\@newglossary',re.M)
 class tex(Task.Task):
 	bibtex_fun,_=Task.compile_fun('${BIBTEX} ${BIBTEXFLAGS} ${SRCFILE}',shell=False)
@@ -37,6 +38,11 @@
 	Execute the program **makeindex**
 	"""
+	makeglossaries_fun,_=Task.compile_fun('${MAKEGLOSSARIES} ${SRCFILE}',shell=False)
+	makeglossaries_fun.__doc__="""
+	Execute the program **makeglossaries**
+	"""
 	def exec_command(self,cmd,**kw):
 		bld=self.generator.bld
+		Logs.info('runner: %r'%cmd)
 		try:
 			if not kw.get('cwd',None):
@@ -72,4 +78,11 @@
 			global re_tex
 			for match in re_tex.finditer(code):
+				multibib=match.group('type')
+				if multibib and multibib.startswith('bibliography'):
+					multibib=multibib[len('bibliography'):]
+					if multibib.startswith('style'):
+						continue
+				else:
+					multibib=None
 				for path in match.group('file').split(','):
 					if path:
@@ -77,6 +90,9 @@
 						found=None
 						for k in exts_deps_tex:
-							Logs.debug('tex: trying %s%s'%(path,k))
-							found=node.parent.find_resource(path+k)
+							for up in self.texinputs_nodes:
+								Logs.debug('tex: trying %s%s'%(path,k))
+								found=up.find_resource(path+k)
+								if found:
+									break
 							for tsk in self.generator.tasks:
 								if not found or found in tsk.outputs:
@@ -89,4 +105,9 @@
 										parse_node(found)
 										break
+							if found and multibib and found.name.endswith('.bib'):
+								try:
+									self.multibibs.append(found)
+								except AttributeError:
+									self.multibibs=[found]
 						if add_name:
 							names.append(path)
@@ -103,14 +124,20 @@
 			try:
 				ct=aux_node.read()
-			except(OSError,IOError):
+			except EnvironmentError:
 				Logs.error('Error reading %s: %r'%aux_node.abspath())
 				continue
 			if g_bibtex_re.findall(ct):
-				Logs.warn('calling bibtex')
+				Logs.info('calling bibtex')
 				self.env.env={}
 				self.env.env.update(os.environ)
-				self.env.env.update({'BIBINPUTS':self.TEXINPUTS,'BSTINPUTS':self.TEXINPUTS})
+				self.env.env.update({'BIBINPUTS':self.texinputs(),'BSTINPUTS':self.texinputs()})
 				self.env.SRCFILE=aux_node.name[:-4]
 				self.check_status('error when calling bibtex',self.bibtex_fun())
+		for node in getattr(self,'multibibs',[]):
+			self.env.env={}
+			self.env.env.update(os.environ)
+			self.env.env.update({'BIBINPUTS':self.texinputs(),'BSTINPUTS':self.texinputs()})
+			self.env.SRCFILE=node.name[:-4]
+			self.check_status('error when calling bibtex',self.bibtex_fun())
 	def bibunits(self):
 		try:
@@ -120,19 +147,20 @@
 		else:
 			if bibunits:
-				fn=['bu'+str(i)for i in xrange(1,len(bibunits)+1)]
+				fn=['bu'+str(i)for i in range(1,len(bibunits)+1)]
 				if fn:
-					Logs.warn('calling bibtex on bibunits')
+					Logs.info('calling bibtex on bibunits')
 				for f in fn:
-					self.env.env={'BIBINPUTS':self.TEXINPUTS,'BSTINPUTS':self.TEXINPUTS}
+					self.env.env={'BIBINPUTS':self.texinputs(),'BSTINPUTS':self.texinputs()}
 					self.env.SRCFILE=f
 					self.check_status('error when calling bibtex',self.bibtex_fun())
 	def makeindex(self):
+		self.idx_node=self.inputs[0].change_ext('.idx')
 		try:
 			idx_path=self.idx_node.abspath()
 			os.stat(idx_path)
 		except OSError:
-			Logs.warn('index file %s absent, not calling makeindex'%idx_path)
+			Logs.info('index file %s absent, not calling makeindex'%idx_path)
 		else:
-			Logs.warn('calling makeindex')
+			Logs.info('calling makeindex')
 			self.env.SRCFILE=self.idx_node.name
 			self.env.env={}
@@ -142,4 +170,23 @@
 		if os.path.exists(os.path.join(p.abspath(),'btaux.aux')):
 			self.aux_nodes+=p.ant_glob('*[0-9].aux')
+	def makeglossaries(self):
+		src_file=self.inputs[0].abspath()
+		base_file=os.path.basename(src_file)
+		base,_=os.path.splitext(base_file)
+		for aux_node in self.aux_nodes:
+			try:
+				ct=aux_node.read()
+			except EnvironmentError:
+				Logs.error('Error reading %s: %r'%aux_node.abspath())
+				continue
+			if g_glossaries_re.findall(ct):
+				if not self.env.MAKEGLOSSARIES:
+					raise Errors.WafError("The program 'makeglossaries' is missing!")
+				Logs.warn('calling makeglossaries')
+				self.env.SRCFILE=base
+				self.check_status('error when calling makeglossaries %s'%base,self.makeglossaries_fun())
+				return
+	def texinputs(self):
+		return os.pathsep.join([k.abspath()for k in self.texinputs_nodes])+os.pathsep
 	def run(self):
 		env=self.env
@@ -148,39 +195,38 @@
 			env.append_value('PDFLATEXFLAGS','-interaction=batchmode')
 			env.append_value('XELATEXFLAGS','-interaction=batchmode')
-		fun=self.texfun
-		node=self.inputs[0]
-		srcfile=node.abspath()
-		texinputs=self.env.TEXINPUTS or''
-		self.TEXINPUTS=node.parent.get_bld().abspath()+os.pathsep+node.parent.get_src().abspath()+os.pathsep+texinputs+os.pathsep
 		self.cwd=self.inputs[0].parent.get_bld().abspath()
-		Logs.warn('first pass on %s'%self.__class__.__name__)
-		self.env.env={}
-		self.env.env.update(os.environ)
-		self.env.env.update({'TEXINPUTS':self.TEXINPUTS})
-		self.env.SRCFILE=srcfile
-		self.check_status('error when calling latex',fun())
-		self.aux_nodes=self.scan_aux(node.change_ext('.aux'))
-		self.idx_node=node.change_ext('.idx')
+		Logs.info('first pass on %s'%self.__class__.__name__)
+		cur_hash=self.hash_aux_nodes()
+		self.call_latex()
+		self.hash_aux_nodes()
 		self.bibtopic()
 		self.bibfile()
 		self.bibunits()
 		self.makeindex()
-		hash=''
+		self.makeglossaries()
 		for i in range(10):
-			prev_hash=hash
+			prev_hash=cur_hash
+			cur_hash=self.hash_aux_nodes()
+			if not cur_hash:
+				Logs.error('No aux.h to process')
+			if cur_hash and cur_hash==prev_hash:
+				break
+			Logs.info('calling %s'%self.__class__.__name__)
+			self.call_latex()
+	def hash_aux_nodes(self):
+		try:
+			nodes=self.aux_nodes
+		except AttributeError:
 			try:
-				hashes=[Utils.h_file(x.abspath())for x in self.aux_nodes]
-				hash=Utils.h_list(hashes)
-			except(OSError,IOError):
-				Logs.error('could not read aux.h')
-				pass
-			if hash and hash==prev_hash:
-				break
-			Logs.warn('calling %s'%self.__class__.__name__)
-			self.env.env={}
-			self.env.env.update(os.environ)
-			self.env.env.update({'TEXINPUTS':self.TEXINPUTS})
-			self.env.SRCFILE=srcfile
-			self.check_status('error when calling %s'%self.__class__.__name__,fun())
+				self.aux_nodes=self.scan_aux(self.inputs[0].change_ext('.aux'))
+			except IOError:
+				return None
+		return Utils.h_list([Utils.h_file(x.abspath())for x in self.aux_nodes])
+	def call_latex(self):
+		self.env.env={}
+		self.env.env.update(os.environ)
+		self.env.env.update({'TEXINPUTS':self.texinputs()})
+		self.env.SRCFILE=self.inputs[0].abspath()
+		self.check_status('error when calling latex',self.texfun())
 class latex(tex):
 	texfun,vars=Task.compile_fun('${LATEX} ${LATEXFLAGS} ${SRCFILE}',shell=False)
@@ -204,5 +250,5 @@
 @before_method('process_source')
 def apply_tex(self):
-	if not getattr(self,'type',None)in['latex','pdflatex','xelatex']:
+	if not getattr(self,'type',None)in('latex','pdflatex','xelatex'):
 		self.type='pdflatex'
 	tree=self.bld
@@ -212,10 +258,13 @@
 	if getattr(self,'deps',None):
 		deps=self.to_list(self.deps)
-		for filename in deps:
-			n=self.path.find_resource(filename)
-			if not n:
-				self.bld.fatal('Could not find %r for %r'%(filename,self))
-			if not n in deps_lst:
-				deps_lst.append(n)
+		for dep in deps:
+			if isinstance(dep,str):
+				n=self.path.find_resource(dep)
+				if not n:
+					self.bld.fatal('Could not find %r for %r'%(dep,self))
+				if not n in deps_lst:
+					deps_lst.append(n)
+			elif isinstance(dep,Node.Node):
+				deps_lst.append(dep)
 	for node in self.to_nodes(self.source):
 		if self.type=='latex':
@@ -227,21 +276,33 @@
 		task.env=self.env
 		if deps_lst:
-			try:
-				lst=tree.node_deps[task.uid()]
-				for n in deps_lst:
-					if not n in lst:
-						lst.append(n)
-			except KeyError:
-				tree.node_deps[task.uid()]=deps_lst
-		v=dict(os.environ)
-		p=node.parent.abspath()+os.pathsep+self.path.abspath()+os.pathsep+self.path.get_bld().abspath()+os.pathsep+v.get('TEXINPUTS','')+os.pathsep
-		v['TEXINPUTS']=p
+			for n in deps_lst:
+				if not n in task.dep_nodes:
+					task.dep_nodes.append(n)
+		if hasattr(self,'texinputs_nodes'):
+			task.texinputs_nodes=self.texinputs_nodes
+		else:
+			task.texinputs_nodes=[node.parent,node.parent.get_bld(),self.path,self.path.get_bld()]
+			lst=os.environ.get('TEXINPUTS','')
+			if self.env.TEXINPUTS:
+				lst+=os.pathsep+self.env.TEXINPUTS
+			if lst:
+				lst=lst.split(os.pathsep)
+			for x in lst:
+				if x:
+					if os.path.isabs(x):
+						p=self.bld.root.find_node(x)
+						if p:
+							task.texinputs_nodes.append(p)
+						else:
+							Logs.error('Invalid TEXINPUTS folder %s'%x)
+					else:
+						Logs.error('Cannot resolve relative paths in TEXINPUTS %s'%x)
 		if self.type=='latex':
 			if'ps'in outs:
 				tsk=self.create_task('dvips',task.outputs,node.change_ext('.ps'))
-				tsk.env.env=dict(v)
+				tsk.env.env=dict(os.environ)
 			if'pdf'in outs:
 				tsk=self.create_task('dvipdf',task.outputs,node.change_ext('.pdf'))
-				tsk.env.env=dict(v)
+				tsk.env.env=dict(os.environ)
 		elif self.type=='pdflatex':
 			if'ps'in outs:
@@ -250,5 +311,5 @@
 def configure(self):
 	v=self.env
-	for p in'tex latex pdflatex xelatex bibtex dvips dvipdf ps2pdf makeindex pdf2ps'.split():
+	for p in'tex latex pdflatex xelatex bibtex dvips dvipdf ps2pdf makeindex pdf2ps makeglossaries'.split():
 		try:
 			self.find_program(p,var=p.upper())
Index: waflib/Tools/vala.py
===================================================================
--- waflib/Tools/vala.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/vala.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -11,5 +11,5 @@
 	ext_out=['.h']
 	def run(self):
-		cmd=[self.env['VALAC']]+self.env['VALAFLAGS']
+		cmd=self.env.VALAC+self.env.VALAFLAGS
 		cmd.extend([a.abspath()for a in self.inputs])
 		ret=self.exec_command(cmd,cwd=self.outputs[0].parent.abspath())
@@ -160,5 +160,5 @@
 	valac=self.find_program(valac_name,var='VALAC')
 	try:
-		output=self.cmd_and_log(valac+' --version')
+		output=self.cmd_and_log(valac+['--version'])
 	except Exception:
 		valac_version=None
Index: waflib/Tools/waf_unit_test.py
===================================================================
--- waflib/Tools/waf_unit_test.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/waf_unit_test.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -3,6 +3,6 @@
 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
 
-import os,sys
-from waflib.TaskGen import feature,after_method
+import os
+from waflib.TaskGen import feature,after_method,taskgen_method
 from waflib import Utils,Task,Logs,Options
 testlock=Utils.threading.Lock()
@@ -12,4 +12,12 @@
 	if getattr(self,'link_task',None):
 		self.create_task('utest',self.link_task.outputs)
+@taskgen_method
+def add_test_results(self,tup):
+	Logs.debug("ut: %r",tup)
+	self.utest_result=tup
+	try:
+		self.bld.utest_results.append(tup)
+	except AttributeError:
+		self.bld.utest_results=[tup]
 class utest(Task.Task):
 	color='PINK'
@@ -24,9 +32,7 @@
 				return Task.RUN_ME
 		return ret
-	def run(self):
-		filename=self.inputs[0].abspath()
-		self.ut_exec=getattr(self.generator,'ut_exec',[filename])
-		if getattr(self.generator,'ut_fun',None):
-			self.generator.ut_fun(self)
+	def add_path(self,dct,path,var):
+		dct[var]=os.pathsep.join(Utils.to_list(path)+[os.environ.get(var,'')])
+	def get_test_env(self):
 		try:
 			fu=getattr(self.generator.bld,'all_test_paths')
@@ -40,30 +46,28 @@
 						if s not in lst:
 							lst.append(s)
-			def add_path(dct,path,var):
-				dct[var]=os.pathsep.join(Utils.to_list(path)+[os.environ.get(var,'')])
 			if Utils.is_win32:
-				add_path(fu,lst,'PATH')
+				self.add_path(fu,lst,'PATH')
 			elif Utils.unversioned_sys_platform()=='darwin':
-				add_path(fu,lst,'DYLD_LIBRARY_PATH')
-				add_path(fu,lst,'LD_LIBRARY_PATH')
+				self.add_path(fu,lst,'DYLD_LIBRARY_PATH')
+				self.add_path(fu,lst,'LD_LIBRARY_PATH')
 			else:
-				add_path(fu,lst,'LD_LIBRARY_PATH')
+				self.add_path(fu,lst,'LD_LIBRARY_PATH')
 			self.generator.bld.all_test_paths=fu
+		return fu
+	def run(self):
+		filename=self.inputs[0].abspath()
+		self.ut_exec=getattr(self.generator,'ut_exec',[filename])
+		if getattr(self.generator,'ut_fun',None):
+			self.generator.ut_fun(self)
 		cwd=getattr(self.generator,'ut_cwd','')or self.inputs[0].parent.abspath()
-		testcmd=getattr(Options.options,'testcmd',False)
+		testcmd=getattr(self.generator,'ut_cmd',False)or getattr(Options.options,'testcmd',False)
 		if testcmd:
 			self.ut_exec=(testcmd%self.ut_exec[0]).split(' ')
-		proc=Utils.subprocess.Popen(self.ut_exec,cwd=cwd,env=fu,stderr=Utils.subprocess.PIPE,stdout=Utils.subprocess.PIPE)
+		proc=Utils.subprocess.Popen(self.ut_exec,cwd=cwd,env=self.get_test_env(),stderr=Utils.subprocess.PIPE,stdout=Utils.subprocess.PIPE)
 		(stdout,stderr)=proc.communicate()
 		tup=(filename,proc.returncode,stdout,stderr)
-		self.generator.utest_result=tup
 		testlock.acquire()
 		try:
-			bld=self.generator.bld
-			Logs.debug("ut: %r",tup)
-			try:
-				bld.utest_results.append(tup)
-			except AttributeError:
-				bld.utest_results=[tup]
+			return self.generator.add_test_results(tup)
 		finally:
 			testlock.release()
Index: waflib/Tools/xlc.py
===================================================================
--- waflib/Tools/xlc.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/xlc.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -8,8 +8,6 @@
 def find_xlc(conf):
 	cc=conf.find_program(['xlc_r','xlc'],var='CC')
-	cc=conf.cmd_to_list(cc)
 	conf.get_xlc_version(cc)
 	conf.env.CC_NAME='xlc'
-	conf.env.CC=cc
 @conf
 def xlc_common_flags(conf):
Index: waflib/Tools/xlcxx.py
===================================================================
--- waflib/Tools/xlcxx.py	(revision 1a31baf977fc30945946af012270051e3504aa41)
+++ waflib/Tools/xlcxx.py	(revision 904702d027b3e5e51e28a12383eecea0b55611da)
@@ -8,8 +8,6 @@
 def find_xlcxx(conf):
 	cxx=conf.find_program(['xlc++_r','xlc++'],var='CXX')
-	cxx=conf.cmd_to_list(cxx)
 	conf.get_xlc_version(cxx)
 	conf.env.CXX_NAME='xlc++'
-	conf.env.CXX=cxx
 @conf
 def xlcxx_common_flags(conf):
