1#!/usr/bin/env python
2# encoding: utf-8
3# Thomas Nagy, 2011 (ita)
4
5"""
6Latex processing using "biber"
7"""
8
9import os
10from waflib import Task, Logs
11
12from waflib.Tools import tex as texmodule
13
14class tex(texmodule.tex):
15	biber_fun, _ = Task.compile_fun('${BIBER} ${BIBERFLAGS} ${SRCFILE}',shell=False)
16	biber_fun.__doc__ = """
17	Execute the program **biber**
18	"""
19
20	def bibfile(self):
21		return None
22
23	def bibunits(self):
24		self.env.env = {}
25		self.env.env.update(os.environ)
26		self.env.env.update({'BIBINPUTS': self.texinputs(), 'BSTINPUTS': self.texinputs()})
27		self.env.SRCFILE = self.aux_nodes[0].name[:-4]
28
29		if not self.env['PROMPT_LATEX']:
30			self.env.append_unique('BIBERFLAGS', '--quiet')
31
32		path = self.aux_nodes[0].abspath()[:-4] + '.bcf'
33		if os.path.isfile(path):
34			Logs.warn('calling biber')
35			self.check_status('error when calling biber, check %s.blg for errors' % (self.env.SRCFILE), self.biber_fun())
36		else:
37			super(tex, self).bibfile()
38			super(tex, self).bibunits()
39
40class latex(tex):
41	texfun, vars = Task.compile_fun('${LATEX} ${LATEXFLAGS} ${SRCFILE}', shell=False)
42class pdflatex(tex):
43	texfun, vars =  Task.compile_fun('${PDFLATEX} ${PDFLATEXFLAGS} ${SRCFILE}', shell=False)
44class xelatex(tex):
45	texfun, vars = Task.compile_fun('${XELATEX} ${XELATEXFLAGS} ${SRCFILE}', shell=False)
46
47def configure(self):
48	"""
49	Almost the same as in tex.py, but try to detect 'biber'
50	"""
51	v = self.env
52	for p in ' biber tex latex pdflatex xelatex bibtex dvips dvipdf ps2pdf makeindex pdf2ps'.split():
53		try:
54			self.find_program(p, var=p.upper())
55		except self.errors.ConfigurationError:
56			pass
57	v['DVIPSFLAGS'] = '-Ppdf'
58
59