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

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

or just:
$ waf --view
'''

import os, Params

VERSION = '0.0.1'
APPNAME = 'test'

srcdir = '.'
blddir = 'build'

def build(bld) :
	target = bld.create_obj('tex', 'pdflatex')
	target.source = 'main.tex'

def configure(configuration):
        configuration.check_tool('tex')

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

def shutdown():
	def exists(cmd):
		try:
			txt = os.popen("which %s 2>/dev/null "%cmd).read().strip()
			return len(txt)>=len(cmd)
		except:
			return None

	if Params.g_options.view:
		for i in ["kpdf", "gnome-open", "xpdf"]:
			if exists(i):
				os.popen("%s build/default/main.pdf" % i)
				break
