# Copyright (c) 2009 XORP, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, Version 2, June
# 1991 as published by the Free Software Foundation. Redistribution
# and/or modification of this program under the terms of any other
# version of the GNU General Public License is not permitted.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
# see the GNU General Public License, Version 2, a copy of which can be
# found in the XORP LICENSE.gpl file.
#
# XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
# http://xorp.net

# $XORP$

import os
Import("env")

env = env.Clone()

env.AppendUnique(CPPPATH = [
	'#',
	'$BUILDDIR',
	'$BUILDDIR/libxipc',
	])

env.AppendUnique(LIBPATH = [
	'$BUILDDIR/xrl/interfaces',
	'$BUILDDIR/xrl/targets',
	'$BUILDDIR/libxipc',
	'$BUILDDIR/libxorp',
	'$BUILDDIR/libcomm',
	])

env.AppendUnique(LIBS = [
	'xorp_ipc',
	'xorp_finder',
	'xorp_core',
	'xorp_comm',
	])

# Missing:
# test_finder_deaths.sh
# test_leaks.sh
# test_xrl_parser.sh

simple_cpp_tests = [
	#'finder',		# XXX test target needed
	#'finder_events',
	#'finder_messenger',
	#'finder_msgs',
	#'finder_tcp',
	#'finder_to',
	'lemming',
	#'receiver',		# compound
	'stcp',
	'stcppf',
	'xrl',
	'xrl_args',
	'xrl_atom',
	'xrl_error',
	'xrl_parser',
	'xrl_router',
]

cpp_test_targets = []

for ct in simple_cpp_tests:
    cpp_test_targets.append(env.AutoTest(target = 'test_%s' % ct,
                                         source = 'test_%s.cc' % ct))

# XXX Now to run them.

### test_xrl_sender/receiver

env = env.Clone()

def local_rpath(tenv):
    """ Return tenv's RPATH munged to contain absolute build path. """
    return [ x.replace('$BUILDDIR', Dir(tenv['BUILDDIR']).abspath) \
             for x in tenv['LIBPATH'] ]

env.AppendUnique(RPATH = local_rpath(env) )

env.PrependUnique(LIBS = [
	'xif_test_xrls',
	'xst_test_xrls',
	])

test_receiver_o = env.Object('test_receiver.cc')

test_xrl_receiver_srcs = [ 'test_xrl_receiver.cc', test_receiver_o ]
test_xrl_receiver = env.Program(target = 'test_xrl_receiver',
				source = test_xrl_receiver_srcs)
# XXX Build on 'check', but don't run.
env.Alias('check', test_xrl_receiver)

# TODO: Run on 'check' using the provided shell scripts.
#runner = env.Action(test[0].abspath)
#env.Alias('check', test, runner)

test_xrl_sender_srcs = [ 'test_xrl_sender.cc', test_receiver_o ]
test_xrl_sender = env.Program(target = 'test_xrl_sender',
			      source = test_xrl_sender_srcs)

# XXX Build on 'check', but don't run.
env.Alias('check', test_xrl_sender)

Default()
