3
# WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
6
from waflib import Utils,Task,Errors,Logs
7
from waflib.TaskGen import feature,before_method
8
re_bibunit=re.compile(r'\\(?P<type>putbib)\[(?P<file>[^\[\]]*)\]',re.M)
12
if not node:return nodes
14
for match in re_bibunit.finditer(code):
15
path=match.group('file')
18
Logs.debug('tex: trying %s%s'%(path,k))
19
fi=node.parent.find_resource(path+k)
23
Logs.debug('tex: could not find %s'%path)
24
Logs.debug("tex: found the following bibunit files: %s"%nodes)
26
exts_deps_tex=['','.ltx','.tex','.bib','.pdf','.png','.eps','.ps']
27
exts_tex=['.ltx','.tex']
28
re_tex=re.compile(r'\\(?P<type>include|bibliography|putbib|includegraphics|input|import|bringin|lstinputlisting)(\[[^\[\]]*\])?{(?P<file>[^{}]*)}',re.M)
29
g_bibtex_re=re.compile('bibdata',re.M)
31
bibtex_fun,_=Task.compile_fun('${BIBTEX} ${BIBTEXFLAGS} ${SRCFILE}',shell=False)
32
bibtex_fun.__doc__="""
33
Execute the program **bibtex**
35
makeindex_fun,_=Task.compile_fun('${MAKEINDEX} ${MAKEINDEXFLAGS} ${SRCFILE}',shell=False)
36
makeindex_fun.__doc__="""
37
Execute the program **makeindex**
39
def exec_command(self,cmd,**kw):
40
bld=self.generator.bld
42
if not kw.get('cwd',None):
44
except AttributeError:
45
bld.cwd=kw['cwd']=bld.variant_dir
46
return Utils.subprocess.Popen(cmd,**kw).wait()
47
def scan_aux(self,node):
49
re_aux=re.compile(r'\\@input{(?P<file>[^{}]*)}',re.M)
52
for match in re_aux.finditer(code):
53
path=match.group('file')
54
found=node.parent.find_or_declare(path)
55
if found and found not in nodes:
56
Logs.debug('tex: found aux node '+found.abspath())
66
if not node:return(nodes,names)
73
for match in re_tex.finditer(code):
74
for path in match.group('file').split(','):
78
for k in exts_deps_tex:
79
Logs.debug('tex: trying %s%s'%(path,k))
80
found=node.parent.find_resource(path+k)
81
for tsk in self.generator.tasks:
82
if not found or found in tsk.outputs:
88
if found.name.endswith(ext):
95
x.parent.get_bld().mkdir()
96
Logs.debug("tex: found the following : %s and names %s"%(nodes,names))
98
def check_status(self,msg,retcode):
100
raise Errors.WafError("%r command exit status %r"%(msg,retcode))
102
for aux_node in self.aux_nodes:
105
except(OSError,IOError):
106
Logs.error('Error reading %s: %r'%aux_node.abspath())
108
if g_bibtex_re.findall(ct):
109
Logs.warn('calling bibtex')
111
self.env.env.update(os.environ)
112
self.env.env.update({'BIBINPUTS':self.TEXINPUTS,'BSTINPUTS':self.TEXINPUTS})
113
self.env.SRCFILE=aux_node.name[:-4]
114
self.check_status('error when calling bibtex',self.bibtex_fun())
117
bibunits=bibunitscan(self)
119
Logs.error('error bibunitscan')
122
fn=['bu'+str(i)for i in xrange(1,len(bibunits)+1)]
124
Logs.warn('calling bibtex on bibunits')
126
self.env.env={'BIBINPUTS':self.TEXINPUTS,'BSTINPUTS':self.TEXINPUTS}
128
self.check_status('error when calling bibtex',self.bibtex_fun())
131
idx_path=self.idx_node.abspath()
134
Logs.warn('index file %s absent, not calling makeindex'%idx_path)
136
Logs.warn('calling makeindex')
137
self.env.SRCFILE=self.idx_node.name
139
self.check_status('error when calling makeindex %s'%idx_path,self.makeindex_fun())
141
p=self.inputs[0].parent.get_bld()
142
if os.path.exists(os.path.join(p.abspath(),'btaux.aux')):
143
self.aux_nodes+=p.ant_glob('*[0-9].aux')
146
if not env['PROMPT_LATEX']:
147
env.append_value('LATEXFLAGS','-interaction=batchmode')
148
env.append_value('PDFLATEXFLAGS','-interaction=batchmode')
149
env.append_value('XELATEXFLAGS','-interaction=batchmode')
152
srcfile=node.abspath()
153
texinputs=self.env.TEXINPUTS or''
154
self.TEXINPUTS=node.parent.get_bld().abspath()+os.pathsep+node.parent.get_src().abspath()+os.pathsep+texinputs+os.pathsep
155
self.cwd=self.inputs[0].parent.get_bld().abspath()
156
Logs.warn('first pass on %s'%self.__class__.__name__)
158
self.env.env.update(os.environ)
159
self.env.env.update({'TEXINPUTS':self.TEXINPUTS})
160
self.env.SRCFILE=srcfile
161
self.check_status('error when calling latex',fun())
162
self.aux_nodes=self.scan_aux(node.change_ext('.aux'))
163
self.idx_node=node.change_ext('.idx')
172
hashes=[Utils.h_file(x.abspath())for x in self.aux_nodes]
173
hash=Utils.h_list(hashes)
174
except(OSError,IOError):
175
Logs.error('could not read aux.h')
177
if hash and hash==prev_hash:
179
Logs.warn('calling %s'%self.__class__.__name__)
181
self.env.env.update(os.environ)
182
self.env.env.update({'TEXINPUTS':self.TEXINPUTS})
183
self.env.SRCFILE=srcfile
184
self.check_status('error when calling %s'%self.__class__.__name__,fun())
186
texfun,vars=Task.compile_fun('${LATEX} ${LATEXFLAGS} ${SRCFILE}',shell=False)
188
texfun,vars=Task.compile_fun('${PDFLATEX} ${PDFLATEXFLAGS} ${SRCFILE}',shell=False)
190
texfun,vars=Task.compile_fun('${XELATEX} ${XELATEXFLAGS} ${SRCFILE}',shell=False)
191
class dvips(Task.Task):
192
run_str='${DVIPS} ${DVIPSFLAGS} ${SRC} -o ${TGT}'
194
after=['latex','pdflatex','xelatex']
195
class dvipdf(Task.Task):
196
run_str='${DVIPDF} ${DVIPDFFLAGS} ${SRC} ${TGT}'
198
after=['latex','pdflatex','xelatex']
199
class pdf2ps(Task.Task):
200
run_str='${PDF2PS} ${PDF2PSFLAGS} ${SRC} ${TGT}'
202
after=['latex','pdflatex','xelatex']
204
@before_method('process_source')
206
if not getattr(self,'type',None)in['latex','pdflatex','xelatex']:
209
outs=Utils.to_list(getattr(self,'outs',[]))
210
self.env['PROMPT_LATEX']=getattr(self,'prompt',1)
212
if getattr(self,'deps',None):
213
deps=self.to_list(self.deps)
214
for filename in deps:
215
n=self.path.find_resource(filename)
217
self.bld.fatal('Could not find %r for %r'%(filename,self))
218
if not n in deps_lst:
220
for node in self.to_nodes(self.source):
221
if self.type=='latex':
222
task=self.create_task('latex',node,node.change_ext('.dvi'))
223
elif self.type=='pdflatex':
224
task=self.create_task('pdflatex',node,node.change_ext('.pdf'))
225
elif self.type=='xelatex':
226
task=self.create_task('xelatex',node,node.change_ext('.pdf'))
230
lst=tree.node_deps[task.uid()]
235
tree.node_deps[task.uid()]=deps_lst
237
p=node.parent.abspath()+os.pathsep+self.path.abspath()+os.pathsep+self.path.get_bld().abspath()+os.pathsep+v.get('TEXINPUTS','')+os.pathsep
239
if self.type=='latex':
241
tsk=self.create_task('dvips',task.outputs,node.change_ext('.ps'))
244
tsk=self.create_task('dvipdf',task.outputs,node.change_ext('.pdf'))
246
elif self.type=='pdflatex':
248
self.create_task('pdf2ps',task.outputs,node.change_ext('.ps'))
252
for p in'tex latex pdflatex xelatex bibtex dvips dvipdf ps2pdf makeindex pdf2ps'.split():
254
self.find_program(p,var=p.upper())
255
except self.errors.ConfigurationError:
257
v['DVIPSFLAGS']='-Ppdf'