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

# notes:
# 1. We think it is good to give names to our objects
# 2. In practice something like 'libkdegames' might do it better
# 3. Any coincidence with characters living or dead is purely coincidental

def myfun(self, name):

	import ccroot
	env2 = self.env.copy()
	env2['CXXFLAGS'] = "-Dxxxxxxxxxxxxxxxxxxxxxxx"

	node = self.path.find_resource(name)
	task = self.create_task('cxx', env2)

	task.scanner = ccroot.g_c_scanner
	task.path_lst = self.inc_paths
	task.defines  = self.scanner_defines

	task.inputs = [node]
	task.outputs = [node.change_ext(".o")]
	self.compiled_tasks.append(task)

def build(bld):
	import Options
	print "command-line parameter meow is ", Options.options.meow

	# 1. A simple program
	obj = bld.new_task_gen('cxx', 'program')
	obj.source='''
	a1.cpp
	b1.cpp b2.cpp
	main.cpp
	'''
	obj.target='testprogram'
	obj.defines='LINUX=1 BIDULE'
	# obj.add_obj_file('kk.o') # <- example on how to add custom object files considered source

	#obj.mappings["a1.cpp"] = myfun <- example of how to modify the environment for one file
	# of you need to modify more files, add custom object files or use the objects type

	# 2. A shared library
	# The extension (.so) is added automatically
	obj = bld.new_task_gen('cxx', 'shlib')
	obj.source='''
	a1.cpp
	b1.cpp b2.cpp
	'''
	#obj.name        = 'peter'
	obj.target       = 'testshlib'
	obj.install_path = '${SOME_INSTALL_DIR}'

	# 3. A static library
	# The extension (.a) is added automatically
	obj = bld.new_task_gen('cxx', 'staticlib')
	obj.source='''
	c1.cpp
	'''
	obj.name         = 'tony'
	obj.target       = 'teststaticlib'

	# 4. Another shared library
	obj = bld.new_task_gen('cxx', 'shlib')
	obj.source='''
	d1.cpp
	'''
	obj.target       = 'shlib1'
	obj.name         = 'john'
	obj.want_libtool = 1
	obj.vnum         = '1.2.3'

	# 5. A program that links against shlib1
	obj = bld.new_task_gen('cxx', 'program')
	obj.source='''
	e1.cpp
	'''
	obj.uselib       = 'MYPROG'
	obj.uselib_local = 'tony john testshlib' # 'tony john peter' # look for 'peter' above
	obj.target       = 'program_dyn_linked'

	# IMPORTANT WARNING:
	# uselib_local expects *names*, that is, the field obj.name
	# by simplicity, when there is no ambiguity: obj.target == obj.name

	# installing files, headers ..
	bld.install_files('${PREFIX}/include', 'a1.h')
	#install_as('${PREFIX}/dir/ahoy.h', 'a1.h')

def set_options(opt):
	# options defined if src/ was to be compiled as a standalone module
	opt.add_option('--meow', type='string', help='option hidden in the src module', dest='meow')

def configure(conf):
	print "sub-configuration file called (demo)"

