# Copyright AllSeen Alliance. All rights reserved.
#
#    Permission to use, copy, modify, and/or distribute this software for any
#    purpose with or without fee is hereby granted, provided that the above
#    copyright notice and this permission notice appear in all copies.
#
#    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
#    WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
#    MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
#    ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
#    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
#    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
#    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# 

Import('router_env', 'router_objs', 'srobj')

# Build the resources for the dll
rsc = router_env.RES('DaemonResources.rc')

daemon_static_lib = [];
daemon_shared_lib = [];

# Build the Windows daemon.
router_libs = router_env.SharedLibrary('daemonlib', ['daemon-service.cc', 'daemon-main.cc'] + srobj + router_objs + rsc)

# the variable router_libs contains the file nodes for the  static library and the 
# shared library however it may contain more files such as .pdb files on windows.  
# Search through the list and assign the static library to daemon_static_lib  and 
# the shared library to daemon_shared_lib variable.
for x in router_libs: 
    if router_env['LIBSUFFIX'] in str(x):
        daemon_static_lib = x;
    if router_env['SHLIBSUFFIX'] in str(x):
        daemon_shared_lib = x;

router_env.Install('$CPP_DISTDIR/lib', daemon_static_lib) #put the *.lib file in the lib folder
env2 = router_env.Clone();
env2.Append(LIBS = ['daemonlib'])
daemon = []

progs = [daemon, daemon_shared_lib] # daemonlibs.dll will be returned
Return('progs')
