# 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

# $XORP$

import os
import string

Import("env")

env = env.Clone()

is_shared = env.has_key('SHAREDLIBS')

env.AppendUnique(CPPPATH = [ "#" ])
env.AppendUnique(LIBPATH = [ '$BUILDDIR/libxipc',
			     '$BUILDDIR/libcomm',
                             '$BUILDDIR/libxorp' ] )
env.AppendUnique(LIBS = [ 'xorp_ipc',
			  'xorp_comm',
                          'xorp_core' ])

xifs = [
    'cli_manager.xif',
    'cli_processor.xif',
    'common.xif',
    'coord.xif',
    'datain.xif',
    'fea_fib_client.xif',
    'fea_fib.xif',
    'fea_ifmgr_mirror.xif',
    'fea_ifmgr_replicator.xif',
    'fea_ifmgr.xif',
    'fea_rawlink_client.xif',
    'fea_rawlink.xif',
    'fea_rawpkt4_client.xif',
    'fea_rawpkt4.xif',
    'fib2mrib.xif',
    'finder_client.xif',
    'finder_event_notifier.xif',
    'finder_event_observer.xif',
    'finder.xif',
    'fti.xif',
    'mfea_client.xif',
    'mfea.xif',
    'mld6igmp_client.xif',
    'mld6igmp.xif',
    'pim.xif',
    'policy_backend.xif',
    'policy_redist4.xif',
    'policy_redist6.xif',
    'policy.xif',
    'redist4.xif',
    'redist6.xif',
    'redist_transaction4.xif',
    'redist_transaction6.xif',
    'rib_client.xif',
    'rib.xif',
    'rtrmgr_client.xif',
    'rtrmgr.xif',
    'socket4_user.xif',
    'socket4.xif',
    'static_routes.xif',
    'test_peer.xif',
    'test.xif',
    'test_xrls.xif',
    ]

if env['enable_bgp']:
    xifs.append('bgp.xif')
    
if not (env.has_key('disable_ipv6') and env['disable_ipv6']):
    xifs.append('socket6.xif')
    xifs.append('socket6_user.xif')
    xifs.append('fea_rawpkt6_client.xif')
    xifs.append('fea_rawpkt6.xif')
    if env['enable_ospf']:
        xifs.append('ospfv3.xif')

if not (env.has_key('disable_profile') and env['disable_profile']):
    xifs.append('profile_client.xif')
    xifs.append('profile.xif')

if not (env.has_key('disable_fw') and env['disable_fw']):
    xifs.append('fea_firewall.xif')

if env['enable_olsr']:
    xifs.append('olsr4.xif')
    
if env['enable_wrapper']:
    xifs.append('wrapper4.xif')

if env['enable_rip']:
    xifs.append('rip.xif')
    xifs.append('ripng.xif')

if env['enable_vrrp']:
    xifs.append('vrrp.xif')

if env['enable_ospf']:
    xifs.append('ospfv2.xif')

Depends('common.xif', '../../xorp_config.h');
Depends('fea.xif', 'common.xif');

all_xif_libs = []

for xif in xifs:
    base = xif[:-len('.xif')]
    tgt = 'libxif_' + base
    src = base + '_xif.cc'

    env.CLNTGEN(xif)

    if is_shared:
        lib = env.SharedLibrary(tgt, src)
        # symlink an alias for each library when $ORIGIN is in use.
        if env['rtld_origin']:
            for obj in lib:
                env.AddPostAction(lib,
                    env.Symlink(obj.abspath,
                                os.path.join(env['xorp_alias_libdir'], str(obj))))
    else:
        lib = env.StaticLibrary(tgt, src)

    all_xif_libs.append(lib)

    if env['enable_tests'] or base[:4] != "test":
        if is_shared:
            env.Alias('install', env.InstallLibrary(env['xorp_libdir'], lib))

Default(all_xif_libs)
