import platform 

Import('env', 'build_type', 'prefix', 'version_info', 'test_xml')

test_env = env.Clone()
test_env.Append(LIBPATH = ['#build/src']);
test_env.Append(LIBS = ['ucore_' + build_type, 'check'])

system = platform.system()

#NetBSD needs /usr/pkg/... 
if 'netbsd' in system.lower():
    test_env.Append(LIBPATH = ['/usr/pkg/lib'])
    test_env.Append(LINKFLAGS = ['-Wl,-rpath,/usr/pkg/lib'])
    test_env.Append(CPPPATH = ['/usr/pkg/include'])

    

tests = test_env.Glob('test_*.c')

test_executable = 'test_runner'
#run test_runner --xml to produce an xml result file
if test_xml:
    test_executable += ' -x'

prog = test_env.Program('test_runner', tests)
cmd  = test_env.Command(target='test_phony' , 
                            source = None, 
                            action= test_env.Dir('.').abspath + '/' + test_executable)
test_env.Depends(cmd, prog)
test_env.AlwaysBuild(cmd)

