###############################################################################
# Makefile for P2P library
#
# Copyright 2007 BroadOn Communications Corp.  All rights reserved.
#
###############################################################################

USES_RM = 0

include ../../../../devroot/include/make/SDKdefs
include ../share/libraries_common.mk

# shared library has some PPC-only code
LIBSHR_BW_PATH          =../share

SRCDIR = src

include $(GBA_SOURCE)/sw/common/lib/p2p/services/Make.common

# module name should be set to the name of this subdirectory
MODULENAME	= p2p_services

# This indicates to commondefs/modulerules as to where this directory is
# The selectable paths are restricted to limit the number of subtrees
# that are added to the SDK tree.
LIB		= TRUE

# Library building
# LIBNAME specifies the name of the library.  No suffix is required, as
# that will depend on whether this is a DEBUG build or not.
# The final name of the library will be $(LIBNAME)$(LIBSUFFIX)
LIBNAME		= p2p_services

# CLIBSRCS/CPPLIBSRCS specifies all C/C++ files that are built and linked into 
# the library.
# ASMLIBSRCS are all assembly files that will be built and linked into the lib.
CLIBSRCS       = \
		 $(CFILES) \
		 p2p_serialization.c \
		 shr_getopt.c \
		 shr_mem.c \
		 shr_th_bw.c \
		 shr_time_bw.c \
		 shr_mem_bw.c \
		 shr_trace.c
	
# ends up being BUILD_ROOT, the core of MODULE_ROOT
REX_BUILDDIR = ../..

# modulerules contains the rules that will use the above variables 
# and dependencies below to construct the library and binaries specified.
include $(REVOLUTION_EXT_ROOT)/build/buildtools/modulerules

CCFLAGS_WARNING = -W padding,nounused

INCLUDES       += \
		  -I"$(REVOLUTION_SDK_ROOT)/include/revolution" \
		  -I$(P2P_INC_ROOT) \
		  -I$(P2P_PRIV_INC_ROOT) \
		  -I../share/include/ \
		  -I./../../../include/ # for BW-specific private headers

setup:	
	@if [ -z '$(REVOLUTION_P2P_ROOT)' ]; then\
	    echo "You must establish environment variable REVOLUTION_P2P_ROOT before proceeding."; \
	    exit 1; \
	fi
	@if [ ! -w '$(REVOLUTION_P2P_ROOT)' -o ! -d '$(REVOLUTION_P2P_ROOT)' ]; then\
	    mkdir -p '$(REVOLUTION_P2P_ROOT)'; \
	fi
	rsync -avz $(LIBSHR_BW_PATH)/src/*.c  ./src/
	rsync -avz $(GBA_SOURCE)/sw/common/lib/p2p/share/*.c ./src/
	rsync -avz $(GBA_SOURCE)/sw/common/lib/p2p/services/*.c ./src/
# $(SETUP_ROOTS) does not create directory $(DEP_ROOT), without which build will fail
	mkdir -p $(DEP_ROOT)

P2P_SERVICES_HFILES={p2p_services.h,p2p_services_priv.h}
P2P_PRIV_SERVICES_HFILES={p2p_svcs_i.h,vna_misc.h,p2p_services_deprecated.h}

P2P_PRIV_API_HFILES={p2p_server_rpc.h,p2p_plat.h}

P2P_SHARE_HFILES={p2p_serialization.h,shr_trace.h,shr_types.h}
P2P_PRIV_SHARE_HFILES={shr_plat.h,shr_th.h,shr_mem.h,shr_getopt.h,shr_trace_i.h,shr_time.h,shr_lib.h}

P2P_PRIV_VN_HFILES=vntypes.h

headers:
	@if [ ! -w $(P2P_INC_ROOT) -o ! -d $(P2P_INC_ROOT) ]; then \
	    	mkdir -p $(P2P_INC_ROOT); \
	fi
	@if [ ! -w $(P2P_PRIV_INC_ROOT) -o ! -d $(P2P_PRIV_INC_ROOT) ]; then \
	    	mkdir -p $(P2P_PRIV_INC_ROOT); \
	fi
	$(INSTALL) -p $(GBA_SOURCE)/sw/common/lib/p2p/services/$(P2P_SERVICES_HFILES) $(P2P_INC_ROOT)
	$(INSTALL) -p $(GBA_SOURCE)/sw/common/lib/p2p/services/$(P2P_PRIV_SERVICES_HFILES) $(P2P_PRIV_INC_ROOT)
	$(INSTALL) -p $(GBA_SOURCE)/sw/common/lib/p2p/api/$(P2P_PRIV_API_HFILES) $(P2P_PRIV_INC_ROOT)
	$(INSTALL) -p $(GBA_SOURCE)/sw/common/lib/p2p/share/$(P2P_SHARE_HFILES) $(P2P_INC_ROOT)
	$(INSTALL) -p $(GBA_SOURCE)/sw/common/lib/p2p/share/$(P2P_PRIV_SHARE_HFILES) $(P2P_PRIV_INC_ROOT)
	$(INSTALL) -p $(GBA_SOURCE)/sw/common/lib/p2p/vn/$(P2P_PRIV_VN_HFILES) $(P2P_PRIV_INC_ROOT)
