#! /usr/bin/python
# -*- mode: python encoding: UTF-8 -*-

'''
run:
$ waf configure
$ waf
$ waf --view

or just:
$ waf --view
'''

import os
from waflib import Options

VERSION = '0.0.1'
APPNAME = 'pdf'

top = '.'
out = 'build'

def options(opts):
	opts.add_option('--view', action='store_true', default=False, help='View the document')

def configure(conf):
	conf.load('tex')
	if not conf.env['PDFLATEX']:
		conf.fatal('install pdflatex!')

	conf.find_program(['okular', 'kpdf', 'xpdf', 'gnome-open'], var='VIEW', mandatory=False)


def build(bld) :
	bld(features='tex', type='pdflatex', source='main.tex')

	def view(ctx):
		ctx.exec_command(ctx.env.VIEW + ['build/main.pdf'])

	if bld.env.VIEW and bld.options.view:
		bld.add_post_fun(view)

