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 if found and not found in self.outputs:
85 if found.name.endswith(ext):
92 x.parent.get_bld().mkdir()
93 Logs.debug("tex: found the following : %s and names %s"%(nodes,names))
95 def check_status(self,msg,retcode):
97 raise Errors.WafError("%r command exit status %r"%(msg,retcode))
101 for aux_node in self.aux_nodes:
103 if g_bibtex_re.findall(ct):
106 except(OSError,IOError):
107 Logs.error('error bibtex scan')
110 Logs.warn('calling bibtex')
112 self.env.env.update(os.environ)
113 self.env.env.update({'BIBINPUTS':self.TEXINPUTS,'BSTINPUTS':self.TEXINPUTS})
114 self.env.SRCFILE=self.aux_nodes[0].name[:-4]
115 self.check_status('error when calling bibtex',self.bibtex_fun())
118 bibunits=bibunitscan(self)
120 Logs.error('error bibunitscan')
123 fn=['bu'+str(i)for i in xrange(1,len(bibunits)+1)]
125 Logs.warn('calling bibtex on bibunits')
127 self.env.env={'BIBINPUTS':self.TEXINPUTS,'BSTINPUTS':self.TEXINPUTS}
129 self.check_status('error when calling bibtex',self.bibtex_fun())
132 idx_path=self.idx_node.abspath()
135 Logs.warn('index file %s absent, not calling makeindex'%idx_path)
137 Logs.warn('calling makeindex')
138 self.env.SRCFILE=self.idx_node.name
140 self.check_status('error when calling makeindex %s'%idx_path,self.makeindex_fun())
143 if not env['PROMPT_LATEX']:
144 env.append_value('LATEXFLAGS','-interaction=batchmode')
145 env.append_value('PDFLATEXFLAGS','-interaction=batchmode')
146 env.append_value('XELATEXFLAGS','-interaction=batchmode')
149 srcfile=node.abspath()
150 texinputs=self.env.TEXINPUTS or''
151 self.TEXINPUTS=node.parent.get_bld().abspath()+os.pathsep+node.parent.get_src().abspath()+os.pathsep+texinputs+os.pathsep
152 self.cwd=self.inputs[0].parent.get_bld().abspath()
153 Logs.warn('first pass on %s'%self.__class__.__name__)
155 self.env.env.update(os.environ)
156 self.env.env.update({'TEXINPUTS':self.TEXINPUTS})
157 self.env.SRCFILE=srcfile
158 self.check_status('error when calling latex',fun())
159 self.aux_nodes=self.scan_aux(node.change_ext('.aux'))
160 self.idx_node=node.change_ext('.idx')
168 hashes=[Utils.h_file(x.abspath())for x in self.aux_nodes]
169 hash=Utils.h_list(hashes)
170 except(OSError,IOError):
171 Logs.error('could not read aux.h')
173 if hash and hash==prev_hash:
175 Logs.warn('calling %s'%self.__class__.__name__)
177 self.env.env.update(os.environ)
178 self.env.env.update({'TEXINPUTS':self.TEXINPUTS})
179 self.env.SRCFILE=srcfile
180 self.check_status('error when calling %s'%self.__class__.__name__,fun())
182 texfun,vars=Task.compile_fun('${LATEX} ${LATEXFLAGS} ${SRCFILE}',shell=False)
184 texfun,vars=Task.compile_fun('${PDFLATEX} ${PDFLATEXFLAGS} ${SRCFILE}',shell=False)
186 texfun,vars=Task.compile_fun('${XELATEX} ${XELATEXFLAGS} ${SRCFILE}',shell=False)
187 class dvips(Task.Task):
188 run_str='${DVIPS} ${DVIPSFLAGS} ${SRC} -o ${TGT}'
190 after=['latex','pdflatex','xelatex']
191 class dvipdf(Task.Task):
192 run_str='${DVIPDF} ${DVIPDFFLAGS} ${SRC} ${TGT}'
194 after=['latex','pdflatex','xelatex']
195 class pdf2ps(Task.Task):
196 run_str='${PDF2PS} ${PDF2PSFLAGS} ${SRC} ${TGT}'
198 after=['latex','pdflatex','xelatex']
200 @before_method('process_source')
202 if not getattr(self,'type',None)in['latex','pdflatex','xelatex']:
205 outs=Utils.to_list(getattr(self,'outs',[]))
206 self.env['PROMPT_LATEX']=getattr(self,'prompt',1)
208 if getattr(self,'deps',None):
209 deps=self.to_list(self.deps)
210 for filename in deps:
211 n=self.path.find_resource(filename)
213 self.bld.fatal('Could not find %r for %r'%(filename,self))
214 if not n in deps_lst:
216 for node in self.to_nodes(self.source):
217 if self.type=='latex':
218 task=self.create_task('latex',node,node.change_ext('.dvi'))
219 elif self.type=='pdflatex':
220 task=self.create_task('pdflatex',node,node.change_ext('.pdf'))
221 elif self.type=='xelatex':
222 task=self.create_task('xelatex',node,node.change_ext('.pdf'))
226 lst=tree.node_deps[task.uid()]
231 tree.node_deps[task.uid()]=deps_lst
232 if self.type=='latex':
234 tsk=self.create_task('dvips',task.outputs,node.change_ext('.ps'))
235 tsk.env.env={'TEXINPUTS':node.parent.abspath()+os.pathsep+self.path.abspath()+os.pathsep+self.path.get_bld().abspath()}
237 tsk=self.create_task('dvipdf',task.outputs,node.change_ext('.pdf'))
238 tsk.env.env={'TEXINPUTS':node.parent.abspath()+os.pathsep+self.path.abspath()+os.pathsep+self.path.get_bld().abspath()}
239 elif self.type=='pdflatex':
241 self.create_task('pdf2ps',task.outputs,node.change_ext('.ps'))
245 for p in'tex latex pdflatex xelatex bibtex dvips dvipdf ps2pdf makeindex pdf2ps'.split():
247 self.find_program(p,var=p.upper())
248 except self.errors.ConfigurationError:
250 v['DVIPSFLAGS']='-Ppdf'