#! /bin/env python

################################################################################
#	\file   SConscript
#	\author Gregory Diamos <gregory.diamos@gatech.edu>
#   \date   Monday August 8, 2011
#	\brief  The SCons master build script for Archaeopteryx
################################################################################

import os
import inspect

## The script begins here
# try to import an environment first
try:
	Import('env')
except:
	try:
		exec open("../scripts/which.py")
		prefix = '../'
	except:
		exec open("scripts/which.py")
		prefix = './'
	exec open(prefix + "scripts/build_environment.py")
	env = Environment()
  
# find all source files in the source tree
sources = []
intermediate_headers = []
directories = [ ]
extensions = ['*.cu']

for dir in directories:
	for ext in extensions:
		regexp = os.path.join(dir, ext)
		sources.extend(env.Glob(regexp))

# Create the archaeopteryx unit tests
tests = []
libs  = env['EXTRA_LIBS']

tests.append(('TestFileAccesses',
	'archaeopteryx/util/test/TestFileAccess.cu', 'basic'))
tests.append(('TestRuntime',
	'archaeopteryx/runtime/test/TestRuntime.cu', 'basic'))

for test in tests:
	env.Program(test[0], [test[1]], LIBS=libs)

if env['test_level'] != 'none':
	print 'Adding unit tests to the build...'

level_map = { 'none' : 0, 'basic' : 1, 'full' : 2 }

for test in tests:
	if level_map[env['test_level']] >= level_map[test[2]]:
		print 'Adding test ' + test[0]
		Default(test[0])

