# $Id: Makefile,v 1.210 2001/07/26 20:44:19 icahoon Exp $

BUILD = build

ifdef RELEASE 

STAGING_ARGS = -R 

endif

.PHONY : netMgnt proxy_agent snmp support h323 mgcp proxy_base rtp subdirs cleanall clean doc contrib contrib_equiv mgcp_demo rtp_demo releasedir util sdp sip siptest co login usage mgcp_test rtp_test sdp_test sip_test util_test tdiff_correct.log docdir ps cdrlib pslib libpep ps cdr osp libOSP common libpdp libpep policy ua ua_test release staging staging_notar heartbeat hbs snmpplusplus vme vmcp mail vmserver fsvm java rpm siph323csgw install

SUBDIRS = netMgnt snmpplusplus proxy_agent snmp rtp mgcp proxy_base private h323 sip sdp heartbeat hbs util contrib 

NO_DISTRO_SUBDIRS = apache-rs do-not-distribute doc gw h323 private release sipvm tripstack

EXTERNAL_SUBDIRS = rtp mgcp sdp util sip

######################################################################

# this code is the start of modularity for the makefile process.  we
# won't be using it for the moment, however.

#MAKE_INCLUDES := $(foreach dir,$(SUBDIRS),$(dir)/Makefile.data)

#-include $(MAKE_INCLUDES)

#default:
#	@echo "The make file no longer supports a default target."
#	@echo "Please choose one of the following:"
#	@echo ""
#	@for i in $(TARGET_LIST) ; do echo "$$i" ; done
#	@echo "all		all of the above targets"
#	@echo "clean		clean all code"
#	@echo "cleanall		clean all code thoroughly"

######################################################################

usage:
	@echo "The make file no longer supports a default target."
	@echo "Please choose one of the following:"
	@echo ""
	@echo "contrib        support items for other stacks"
	@echo "h323           H.323 stack and examples"
	@echo "snmp           C SNMP Library, no Management Station"
	@echo "proxy_agent    C++ SNMP Library and trap agent"
	@echo "netMgnt        Network Management Station"
	@echo "libmgcp        MGCP stack only"
	@echo "mgcp           MGCP stack and examples"
	@echo "mgcp_test      MGCP stack + test cases"
	@echo "proxy_base     Proxy Base"
	@echo "sip            SIP stack"
	@echo "sip_test       SIP stack + test cases"
	@echo "ua             SIP User Agent"
	@echo "ua_test        SIP User Agent + test"
	@echo "rtp            RTP stack and examples"
	@echo "rtp_test       RTP stack and examples + test cases"
	@echo "rtspstack      RTSP stack"
	@echo "rtspif         RTSP inteface"
	@echo "rtspserver     RTSP server"
	@echo "rtspclient     RTSP client"
	@echo "sdp            SDP stack and test program"
	@echo "sdp_test       SDP stack and test program + test cases"
	@echo "util           Vovida utility library"
	@echo "util_test      Vovida utility library + test cases"
	@echo "cdrlib         CDR Library"
	@echo "pslib          Provisioning Library"
	@echo "libpep         Policy Library"
	@echo "policy         Policy Server"
	@echo "rtp_demo       RTP stack and examples (copied to release)"
	@echo "fs             SIP Feature Server"
	@echo "cpl            CPL Building Blocks"
	@echo "cplfs          CPL Feature Server"
	@echo "fsvm           VM Feature Server"
	@echo "js             JTAPI Feature Server"
	@echo "rs             SIP Redirect Server"
	@echo "ls             TRIP Location Server"
	@echo "ms             SIP Marshal Server"
	@echo "ps             Provisioning Server"
	@echo "loadgen        Load Generator"
	@echo "siph323csgw    SIP-H.323 Call Signaling Gateway"
	@echo "heartbeat      Heartbeat Library"
	@echo "hbs            Heartbeat Server"
	@echo "delopy         deploy program"
	@echo "vmserver       vmserver"
	@echo "vme            vme"
	@echo "vmcp           vmcp"
	@echo "mail           mail"
	@echo "osptnep        osp TransNexus enrollment client"
	@echo "java           SNMPClient.jar and psClient.jar"
	@echo "rpm            RPM"
	@echo "deploy         Installation and remote deployment tool"
	@echo ""
	@echo "test           run all test cases"
	@echo ""
	@echo "all            all of the above targets"
	@echo "clean          clean all code"
	@echo "cleanall       clean all code thoroughly"
	@echo "veryclean      clean debug.*, bin.*, *.d, *.o"

#
# this include is here because our default target overrides everyone
# else's default target

include $(BUILD)/Makefile.pre


MAKE_NOJ = $(patsubst %-j4,%, $(patsubst %-j2,%, $(MAKE)))

cleantest: 
	-rm testall.log

test: rtp_test util_test mgcp_test sip_test sdp_test  ua_test

tdiff_correct.log:
	find . -name 'T_RESULTS.bin*' -print | xargs -icat_results cat cat_results >> T_RESULTS.all
	tools/test-analyzer -d T_RESULTS.all > tdiff_correct.log

test_report_manual: tdiff_correct.log
	echo "Generating test report from current testall.log"
	tools/test-analyzer -d testall.log > tdiff.log
	echo "Test report for " `date` > TEST_REPORT.txt
	echo "If there are changes, they will appear below this line:" >> TEST_REPORT.txt
	echo "----------------------------------------------------------------------" >> TEST_REPORT.txt
	diff -c tdiff_correct.log tdiff.log >> TEST_REPORT.txt

test_report:
	-$(MAKE) -k test
	$(MAKE) test_report_manual

contrib: releasedir
	cd contrib; $(MAKE)

contrib_equiv:
	cd contrib; $(MAKE) Equivalence

contrib_imap:
	cd contrib; $(MAKE) imap
        
h323:
	cd h323; $(MAKE)

snmp: proxy_agent
	cd snmp; $(MAKE)

proxy_agent:	proxy_base
	cd proxies/agent; $(MAKE)

snmpplusplus:  snmp
	cd snmp++ ; $(MAKE)

netMgnt:	snmpplusplus
	cd proxies/netMgnt; $(MAKE)

cdrlib:
	cd cdr/cdrLib; $(MAKE)

pslib: contrib
	-( test -d provisioning/util ) && ( cd provisioning/util; $(MAKE) )
	-( test -d provisioning/psLib ) && ( cd provisioning/psLib; $(MAKE) )

libpep:
	cd policy/libpep; $(MAKE)

ospold:
	-( test -d do-not-distribute/osptk-2.5.1 ) && (cd do-not-distribute/osptk-2.5.1/src ; ./osp_sdk_compile.ksh -d client)

osp: openssl
	cd contrib ; $(MAKE) osp

common: 
	cd policy/common ; $(MAKE)

libpdp: contrib
	cd policy/libpdp ; $(MAKE)

libOSP: osp common
	-(cd policy/libOSP; $(MAKE))

copsstack: util contrib
	cd policy/copsstack; $(MAKE)

trip: util contrib 
	cd tripstack; $(MAKE) all

policy: libpdp common libOSP copsstack
	cd policy/policyServer; $(MAKE)

policy_test: libpep common libOSP copsstack
	cd policy/test ; $(MAKE)

util: contrib
	@( test -d util && test -f util/Makefile ) || ( echo; echo; echo "please check out the util directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co util" ; echo;echo && exit -1 )
	cd util; $(MAKE)

util_test: contrib
	@( test -d util && test -f util/Makefile ) || ( echo; echo; echo "please check out the util directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co util" ; echo;echo && exit -1 )
	cd util; $(MAKE) test

rtp: contrib util
	@( test -d rtp && test -f rtp/Makefile ) || ( echo; echo; echo "please check out the rtp directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co rtp" ; echo;echo && exit -1 )
	cd rtp; $(MAKE)

rtp_test: contrib util
	@( test -d rtp && test -f rtp/Makefile ) || ( echo; echo; echo "please check out the rtp directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co rtp" ; echo;echo && exit -1 )
	cd rtp; $(MAKE) test

rtspstack: util sdp
	@( test -d rtsp/rtspstack && test -f rtsp/rtspstack/Makefile ) || ( echo; echo; echo "please check out the rtsp directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co rtsp" ; echo;echo && exit -1 )
	cd rtsp/rtspstack; $(MAKE)

rtspif: util sdp rtp rtspstack
	@( test -d rtsp/rtspif && test -f rtsp/rtspif/Makefile ) || ( echo; echo; echo "please check out the rtsp directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co rtsp" ; echo;echo && exit -1 )
	cd rtsp/rtspif; $(MAKE)

rtspserver: util sdp rtp rtspif rtspstack
	@( test -d rtsp/rtspserver && test -f rtsp/rtspserver/Makefile ) || ( echo; echo; echo "please check out the rtsp directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co rtsp" ; echo;echo && exit -1 )
	cd rtsp/rtspserver; $(MAKE)

rtspclient: util
	@( test -d rtsp/rtspclient && test -f rtsp/rtspclient/Makefile ) || ( echo; echo; echo "please check out the rtsp directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co rtsp" ; echo;echo && exit -1 )
	cd rtsp/rtspclient; $(MAKE)

sdp: util
	@( test -d sdp && test -f sdp/Makefile ) || ( echo; echo; echo "please check out the sdp directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co sdp" ; echo;echo && exit -1 )
	cd sdp; $(MAKE) 

sdp_test: util
	@( test -d sdp && test -f sdp/Makefile ) || ( echo; echo; echo "please check out the sdp directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co sdp" ; echo;echo && exit -1 )
	cd sdp; $(MAKE) test

rtp_demo: rtp
	@( test -d rtp && test -f rtp/Makefile ) || ( echo; echo; echo "please check out the rtp directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co rtp" ; echo;echo && exit -1 )
	(cd rtp; $(MAKE) install)
	(cd rtp/test ; $(MAKE) ; $(MAKE) install)

libmgcp: contrib sdp util
	@( test -d mgcp && test -f mgcp/Makefile ) || ( echo; echo; echo "please check out the mgcp directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co mgcp" ; echo;echo && exit -1 )
	cd mgcp; $(MAKE) mgcp

mgcp_examples:
	@( test -d mgcp && test -f mgcp/Makefile ) || ( echo; echo; echo "please check out the mgcp directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co mgcp" ; echo;echo && exit -1 )
	cd mgcp; $(MAKE) examples

mgcp_demo: mgcp
	@( test -d mgcp && test -f mgcp/Makefile ) || ( echo; echo; echo "please check out the mgcp directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co mgcp" ; echo;echo && exit -1 )
	cd mgcp; $(MAKE) install

mgcp: libmgcp mgcp_examples

mgcp_test:
	@( test -d mgcp && test -f mgcp/Makefile ) || ( echo; echo; echo "please check out the mgcp directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co mgcp" ; echo;echo && exit -1 )
	cd mgcp; $(MAKE) test

proxy_base: heartbeat contrib sip sdp pslib util 
	@( test -d sip/base && test -f sip/base/README ) || ( echo; echo; echo "please check out the proxyBase directory first" ; echo;echo && exit -1 )
	cd sip/base; $(MAKE)

sip: contrib sdp  util 
	@( test -d sip/sipstack && test -f sip/sipstack/README ) || ( echo; echo; echo "please check out the sip directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co sip" ; echo;echo && exit -1 )
	cd sip/sipstack; $(MAKE)

sip_test: contrib sdp util
	@( test -d sip/sipstack && test -f sip/sipstack/README ) || ( echo; echo; echo "please check out the sip directory first by doing cvs -d :pserver:<random-login>:/home/cvsroot co sip" ; echo;echo && exit -1 )
	cd sip/test; $(MAKE) test

libsndfile:
	cd contrib ; $(MAKE) libsndfile

http: util
	@( test -d http && test -f http/README ) || ( echo; echo; echo "please check out the sip directory first by doing cvs -d :pserver:anonymous@sniff.gloo.net:/home/cvsroot co sip" ; echo;echo && exit -1 )
	cd http && $(MAKE)

http_test: http
	cd http && $(MAKE) unit_test
                
ua: proxy_base libsndfile rtp
	@( test -d sip/ua/ && test -f sip/ua/Makefile ) || ( echo; echo; echo "please check out the ua directory first" ; echo;echo && exit -1 )
	cd sip/ua/; $(MAKE)

ua_test: ua
	@( test -d sip/ua/ && test -f sip/ua/Makefile ) || ( echo; echo; echo "please check out the ua directory first" ; echo;echo && exit -1 )
	cd sip/ua/; $(MAKE) test

callAgent:  heartbeat pslib sip  libmgcp rtp sdp util
	@( test -d translators/mgcp/ && test -f translators/mgcp/Makefile ) || ( echo; echo; echo "please check out the translators/mgcp directory first" ; echo;echo && exit -1 )
	cd translators/mgcp; $(MAKE)

callAgentNCS:
	echo

install:
	@echo "This makefile does not support 'make install'.  Please use one"
	@echo "of the following instead:"
	@echo
	@echo "make allinone       install a pre-configured all-in-one system"
	@echo "                    (use this if this is your first time installing"
	@echo "                    VOCAL)"
	@echo
	@echo "make upgrade-aio    upgrade an all-in-one system"
	@echo
	@echo "make staging        prepare a tar.gz file for installing onto"
	@echo "                    multiple systems (for experienced users)"


install-bin: staging_notar
	mkdir -p /usr/local/vocal/bin
	(cd stage/bin ; tar cf - . ) | (cd /usr/local/vocal/bin ; tar xf - )

allinone: install-bin
	cd install/allinoneconfigure ; ./allinoneconfigure

fs: sip proxy_base
	@( test -d proxies/fs/cpl && test -f proxies/fs/cpl/Makefile && test -d proxies/fs/base && test -f proxies/fs/base/Makefile ) || ( echo; echo; echo "please check out the proxies/fs directory first" ; echo;echo && exit -1 )
	cd proxies/fs/cpl; $(MAKE)
	cd proxies/fs/base; $(MAKE)

cpl: sip
	@( test -d proxies/fs/cpl && test -f proxies/fs/cpl/Makefile ) || ( echo; echo; echo "please check out the proxies/fs/cpl directory first" ; echo;echo && exit -1 )
	cd proxies/fs/cpl; $(MAKE)

cplfs: cpl
	@( test -d proxies/fs/base && test -f proxies/fs/base/Makefile ) || ( echo; echo; echo "please check out the proxies/fs/base directory first" ; echo;echo && exit -1 )
	cd proxies/fs/base; $(MAKE)

fsvm: sip proxy_base
	cd proxies/fs/cpl; $(MAKE)
	cd proxies/fs/vm; $(MAKE)

js: sip proxy_base heartbeat
	@( test -d proxies/fs/jtapi/server && test -f proxies/fs/jtapi/server/Makefile ) || ( echo; echo; echo "please check out the proxies/fs/jtapi/server directory first" ; echo;echo && exit -1 )
	cd proxies/fs/jtapi/server; $(MAKE)

heartbeat: util
	-( test -d heartbeat && test -f heartbeat/Makefile ) && ( cd heartbeat; $(MAKE) )

hbs: util heartbeat 
	@( test -d heartbeat/hbs && test -f heartbeat/hbs/Makefile ) || ( echo; echo; echo "please check out the hbs (heartbeat server) directory first" ; echo;echo && exit -1 )
	cd heartbeat/hbs; $(MAKE)

rs: sip proxy_base
	@( test -d proxies/rs && test -f proxies/rs/Makefile ) || ( echo; echo; echo "please check out the proxies/rs directory first" ; echo;echo && exit -1 )
	cd proxies/rs; $(MAKE)

ls: ps
	@( test -d tripstack/tripcore && test -f tripstack/tripcore/Makefile ) || ( echo; echo; echo "please check out the tripstack/tripcore directory first" ; echo;echo && exit -1 )
	@( test -d tripstack/lsfunctions && test -f tripstack/lsfunctions/Makefile ) || ( echo; echo; echo "please check out the tripstack/lsfunctions directory first" ; echo;echo && exit -1 )
	@( test -d tripstack/lsserver && test -f tripstack/lsserver/Makefile ) || ( echo; echo; echo "please check out the tripstack/lsserver directory first" ; echo;echo && exit -1 )
	cd tripstack/tripcore; $(MAKE)
	cd tripstack/lsfunctions; $(MAKE)
	cd tripstack/lsserver; $(MAKE)

ls_test: ls
	@( test -d tripstack/test && test -f tripstack/test/Makefile ) || ( echo; echo; echo "please check out the tripstack/test directory first" ; echo;echo && exit -1 )
	cd tripstack/test; $(MAKE)


ms: sip proxy_base pslib cdrlib 
	@( test -d proxies/marshal/base && test -f proxies/marshal/base/Makefile ) || ( echo; echo; echo "please check out the proxies/marshal/base directory first" ; echo;echo && exit -1 )
	cd proxies/marshal/base; $(MAKE)

inet_ms: sip proxy_base pslib cdrlib libpep copsstack libOSP
	@( test -d proxies/marshal/base && test -f proxies/marshal/base/Makefile ) || ( echo; echo; echo "please check out the proxies/marshal/base directory first" ; echo;echo && exit -1 )
	@( test -d do-not-distribute ) || ( echo; echo; echo "please check out the do-not-distribute directory first" ; echo;echo && exit -1 )
	cd proxies/marshal/base; cp ms.cxx inet_ms.cxx; USE_POLICY=1; export USE_POLICY; $(MAKE)

vme:
	cd vm/vme ; $(MAKE)

vmcp:
	cd vm/vmcp ; $(MAKE)

mail: contrib contrib_imap
	cd vm/mail ; $(MAKE)

vmserver: contrib vme vmcp mail
	cd vm/vmserver ; $(MAKE)

ps: pslib util
	cd provisioning/pserver ; $(MAKE)
	cd provisioning/conversion ; $(MAKE)

cdr: contrib
	cd cdr/cdrServer ; $(MAKE)

openssl:
	-(cd do-not-distribute/openssl; $(MAKE_NOJ))

osptnep: pslib libOSP
	cd policy/enroll ; $(MAKE)

deploy:
	cd install ; $(MAKE)

siph323csgw: util contrib_equiv sip sdp proxy_base
	@( test -d translators/h323/siph323csgw && test -f translators/h323/siph323csgw/Makefile ) || ( echo; echo; echo "please check out the translators/h323 directory first" ; echo;echo && exit -1 )
	cd translators/h323/util; $(MAKE)
	cd translators/h323/info; $(MAKE)
	cd translators/h323/events; $(MAKE)
	cd translators/h323/sipevents; $(MAKE)
	cd translators/h323/gk; $(MAKE)
	cd translators/h323/proxy; $(MAKE)
	cd translators/h323/router; $(MAKE)
	cd translators/h323/translator; $(MAKE)
	cd translators/h323/siph323csgw; $(MAKE)

#all: ua callAgent fs rs hbs ps ms cdr fsvm vme vmcp mail vmserver snmp netMgnt js deploy ldap2vocaluser siph323csgw 
all: callAgent fs rs hbs ps ms cdr fsvm js deploy ldap2vocaluser ua vme vmcp mail vmserver 

releasedir:
	mkdir -p release/bin.$(TARGET_NAME)
	mkdir -p release/lib.$(TARGET_NAME)

subdirs: 
	for i in $(SUBDIRS) ; do ( cd $$i && $(MAKE) ; $(MAKE) install ) ; done

cleanall:
	touch $$.$$.$$.d
	find . -name 'obj.*' -print -exec /bin/rm -rf {} \;
	find . -name 'bin.*' -print -exec /bin/rm -rf {} \;
	find . -name '*.d' -print -exec /bin/rm -f {} \;
	find . -name '.link_host' -print -exec /bin/rm -f {} \;
	for i in $(SUBDIRS) ; do ( cd $$i && $(MAKE) cleanall ) ; done
	rm -rf release/bin.*/*
	rm -rf release/lib.*/*
	rm -rf release/include/*

veryclean: clean
	- find . -name 'obj.*' -print -exec /bin/rm -rf {} \;
	- find . -name 'bin.*' -print -exec /bin/rm -rf {} \;
	- find . -name '*.o' -print -exec /bin/rm -f {} \;
	- find . -name '*.a' -print -exec /bin/rm -f {} \;
	- find . -name 'core' -print -exec /bin/rm -f {} \;
	- find . -name '.link_host' -print -exec /bin/rm -f {} \;

cleanln:
	ln -s README .asdfasdfadsasdfadsf
	find . -type l -print -exec /bin/rm -f {} \;

clean:
	- for i in $(SUBDIRS) ; do ( cd $$i && $(MAKE) clean ) ; done
	- find . -name '*.d' -print -exec /bin/rm -f {} \;

doc: .
	for i in $(SUBDIRS) ; do ( cd $$i && $(MAKE) $@ ) ; done

docdir:
	cvs -d '/home/cvsroot' co doc

#co: .external_cvs_server
#	tag=`cvs status Makefile | grep 'Sticky Tag' | perl -ne 'if(/\s+Sticky Tag:\s+([^\s]+)/) { if($$1 ne "(none)") { print "-r $$1";}}'`; echo $$tag ; for i in $(EXTERNAL_SUBDIRS) ; do (cvs -d `cat .external_cvs_server` co $$tag $$i ) ; done

#login:
#	( echo "Enter your username: " ; read foo ; echo :pserver:$$foo@random:/home/cvsroot > .external_cvs_server )

#.external_cvs_server:
#	( echo "Enter your username: " ; read foo ; echo :pserver:$$foo@random:/home/cvsroot > .external_cvs_server )

staging:
	cd stage/scripts; perl stage.pl -n $(TARGET_NAME) $(STAGING_ARGS)

staging_notar:
	cd stage/scripts; perl stage.pl -T -n $(TARGET_NAME)

release:
	cd stage/scripts; perl stage.pl -R -n $(TARGET_NAME)

staging-clean:
	cd stage; rm -rf bin

rpm:
	find . | fgrep -vi cvs | fgrep -vi do-not-distribute | egrep -v '^\.$$' | egrep -v './bin/' | egrep -v './stage/' > list_of_files; tar cvf Vocal-Sources-1.0.tar -T list_of_files; cp Vocal-Sources-1.0.tar /usr/src/redhat/SOURCES; rpm -ba install/rpm_specs/Vocal-Binaries-1.0-1.spec; rpm -ba install/rpm_specs/Vocal-1.0-1.spec

java:
	cd provisioning/java/build; ./build.sh clean; ./build.sh

jtapi:
	cd proxies/fs/jtapi/client/build; ./build.sh clean; ./build.sh

ldap2vocaluser:
	cd tools/ldap2vocaluser; $(MAKE)

distro:
	for i in $(NO_DISTRO_SUBDIRS) ; do ( \rm -rf $$i ) ; done

