# Copyright (c) 2009-2011 XORP, Inc and Others
#
# 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

# $ID$

import os
Import("env")

subdirs = [ 'tests' ]
SConscript(dirs = subdirs, exports='env')

env = env.Clone()
is_shared = env.has_key('SHAREDLIBS')

env.AppendUnique(CPPPATH = [ '#' ])

# External libraries.
# On BSD, and others, we need -lrt for clock_gettime().
if not (env.has_key('mingw') and env['mingw']):
    env.AppendUnique(LIBS = [ 'rt' ])
else:
    env.AppendUnique(LIBS = [ 'ws2_32' ])

libxorp_core_srcs = [
	# C files
	'daemon.c',
	'debug.c',
	'ether_compat.c',
	'gai_strerror.c',
	'getopt.c',
	'inet_ntop.c',
	'inet_pton.c',
	'random.c',
	'strlcpy.c',
	'strptime.c',
	'utility.c',
	'win_io.c',
	'xlog.c',

	# C++ files
	'asyncio.cc',
	'buffered_asyncio.cc',
        'bug_catcher.cc',
	'c_format.cc',
	'callback.cc',
	'clock.cc',
	'eventloop.cc',
	'exceptions.cc',
	'heap.cc',
	'ipnet.cc',
	'ipv4.cc',
	'ipv6.cc',
	'ipvx.cc',
	'mac.cc',
	'nexthop.cc',
	'popen.cc',
	'ref_ptr.cc',
	'round_robin.cc',
	'run_command.cc',
	'safe_callback_obj.cc',
	'selector.cc',
	'service.cc',
	'task.cc',
	'time_slice.cc',
	'timer.cc',
	'timeval.cc',
	'token.cc',
	'transaction.cc',
	'utils.cc',
	'vif.cc',
	'win_dispatcher.cc',
	]

if not (env.has_key('disable_profile') and env['disable_profile']):
    libxorp_core_srcs.append('profile.cc');



if is_shared:
    libxorp_core = env.SharedLibrary(target = 'libxorp_core',
				     source = libxorp_core_srcs)
    # Symlink the library into builddir's copy of lib, so that
    # rtld $ORIGIN references will pick it up automatically without
    # relinking. This syntax looks a little weird, as it makes the
    # action of building the symlink a 'PostAction' in the SCons
    # dependency graph.
    # We basically do this for every SharedLibrary we potentially
    # need to see for binaries not yet installed from the BUILDDIR.
    if env['rtld_origin']:
        for obj in libxorp_core:
            env.AddPostAction(libxorp_core,
                env.Symlink(obj.abspath,
                            os.path.join(env['xorp_alias_libdir'], str(obj))))
else:
    libxorp_core = env.StaticLibrary(target = 'libxorp_core',
				     source = libxorp_core_srcs)

if is_shared:
    env.Alias('install',
        env.InstallLibrary(env['xorp_libdir'], libxorp_core))

Default(libxorp_core)
