#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2006 (ita)

# look for 'meow' below
#import Params

# the following two variables are used by the target "waf dist"
VERSION='0.0.1'
APPNAME='cpp_test'

# these variables are mandatory ('/' are converted automatically)
srcdir = '.'
blddir = 'build'


# if you do not like colors, uncomment the following lines:
#import Params
#Params.reset_colors()

def init():
	pass
	# disable the Waf preprocessor for finding dependencies
	#import Params
	#Params.g_preprocess=0

def set_options(opt):
	# options provided in a script in a subdirectory named "src"
	opt.sub_options('src')

	# options provided by the modules
	opt.tool_options('compiler_cxx')

	# custom options
	opt.add_option('--exe', action='store_true', default=False, help='Execute the program after it is compiled')

def configure(conf):
	# conf.env['CXX'] = Params.g_options.meow
	# CXX=g++-3.0 ./waf.py configure will use g++-3.0 instead of 'g++'
	conf.check_tool('compiler_cxx')

	## batched builds can be enabled by including the module optim_cc
	# conf.check_tool('batched_cc')

	conf.sub_config('src')

	conf.env['CXXFLAGS_MYPROG']='-O3'
	conf.env['LIB_MYPROG']='m'
	conf.env['SOME_INSTALL_DIR']='/tmp/ahoy/lib/'

	# works in a procedural way, so the order of calls does matter
	#conf.check_tool(['KDE3'])

	return
	# testcase for variants, look below
	env = conf.env.copy()
	env.set_variant('debug')
	conf.set_env_name('debug', env)
	conf.setenv('debug')
	conf.env['CXXFLAGS'] = '-D_REENTRANT -DDBG_ENABLED -Wall -O0 -ggdb3 -ftemplate-depth-128'

def build(bld):
	# process subfolders from here
	bld.add_subdirs('src src2')

	## installing resources and files - call them under build(bld) or shutdown()
	## to trigger the glob, ad a star in the name
	## the functions are not called if not in install mode
	#install_files('PREFIX', '', 'src/a2.h src/a1.h')
	install_files('PREFIX', 'subfolder/subsubfolder', 'src/*.h')
	#install_as('PREFIX', 'dir/bar.png', 'foo.png')

	return
	# testcase for variants
	for obj in copy.copy(TaskGen.g_allobjs):
		new_obj = obj.clone('debug')

def shutdown():
	# command to execute
	cmd = "PATH=plugins:$PATH LD_LIBRARY_PATH=build/default/src/:$LD_LIBRARY_PATH build/default/src/testprogram"

	# if the custom option is set, execute the program
	import os, Params
	if Params.g_options.exe:
		os.popen(cmd)

	# in case if more people ask
	#if Params.g_commands['install']:
	#	try: os.popen("/sbin/ldconfig")
	#	except: pass

