#
# Makefile
#
# Make file for Open Phone Abstraction library
#
# Copyright (c) 2001 Equivalence Pty. Ltd.
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
#
# The Original Code is Open Phone Abstraction Library.
#
# The Initial Developer of the Original Code is Equivalence Pty. Ltd.
#
# Contributor(s): ______________________________________.
#
# $Revision: 29051 $
# $Author: rjongbloed $
# $Date: 2013-01-29 22:22:11 -0600 (Tue, 29 Jan 2013) $
#

include opal_defs.mak

SHELL		:= /bin/sh
OS_NAME=$(shell uname -s)
ifeq ($(OS_NAME),SunOS)
  override SHELL=/usr/bin/bash
endif

SUBDIRS := 

ifeq ($(OPAL_PLUGINS),yes)
SUBDIRS += plugins 
endif

ifeq ($(OPAL_SAMPLES),yes)
SUBDIRS += samples/simple \
           samples/codectest \
           samples/callgen \
           samples/opalecho \
           samples/faxopal \
           samples/c_api
ifeq ($(OPAL_IVR),yes)
SUBDIRS += samples/opalmcu \
           samples/ivropal \
           samples/testpresent
endif
endif


ifeq ($(VERBOSE),)
Q=@
Q_CC = @echo [CC] `echo $< | sed s^@OPALDIR@/^^` ; 
Q_DEP= @echo [DEP] `echo $< | sed s^@OPALDIR@/^^` ; 
Q_AR = @echo [AR] `echo $@ | sed s^@OPALDIR@/^^` ;
Q_LD = @echo [LD] `echo $@ | sed s^@OPALDIR@/^^` ;
endif


ifeq ($(DEBUG_BUILD),yes)
  LIB_FILENAME_STATIC=$(DEBUG_LIB_FILENAME_STATIC)
  LIB_FILENAME_SHARED=$(DEBUG_LIB_FILENAME_SHARED)
  LIB_FILENAME_SHARED_PAT=$(DEBUG_LIB_FILENAME_SHARED_PAT)
  OPAL_OBJDIR=$(DEBUG_OPAL_OBJDIR)
  OPAL_DEPDIR=$(DEBUG_OPAL_DEPDIR)
else
  LIB_FILENAME_STATIC=$(RELEASE_LIB_FILENAME_STATIC)
  LIB_FILENAME_SHARED=$(RELEASE_LIB_FILENAME_SHARED)
  LIB_FILENAME_SHARED_PAT=$(RELEASE_LIB_FILENAME_SHARED_PAT)
  OPAL_OBJDIR=$(RELEASE_OPAL_OBJDIR)
  OPAL_DEPDIR=$(RELEASE_OPAL_DEPDIR)
endif


REVISION_FILE = $(OPALDIR)/revision.h

ASN_SRCDIR := $(OPAL_SRCDIR)/asn
ASN_INCDIR := $(OPAL_INCDIR)/asn

VPATH_CXX := $(OPAL_SRCDIR)/opal \
	     $(OPAL_SRCDIR)/rtp \
	     $(OPAL_SRCDIR)/lids \
	     $(OPAL_SRCDIR)/codec \
             $(OPAL_SRCDIR)/t38 \
             $(OPAL_SRCDIR)/im

ifneq (,$(wildcard src/iax2))
IAX2_AVAIL = yes
VPATH_CXX += $(OPAL_SRCDIR)/iax2 
endif

ifneq (,$(wildcard src/zrtp))
ZRTP_AVAIL = yes
VPATH_CXX += $(OPAL_SRCDIR)/zrtp
endif

ifneq (,$(wildcard src/sip))
SIP_AVAIL = yes
VPATH_CXX += $(OPAL_SRCDIR)/sip
endif

ifneq (,$(wildcard src/h323))
H323_AVAIL = yes
VPATH_CXX += $(OPAL_SRCDIR)/h323 \
	     $(OPAL_SRCDIR)/t120 \
	     $(OPAL_SRCDIR)/asn 
endif

ifneq (,$(wildcard src/h224))
H224_AVAIL = yes
VPATH_CXX += $(OPAL_SRCDIR)/h224

endif

ifneq (,$(wildcard src/h460))
H460_AVAIL = yes
VPATH_CXX += $(OPAL_SRCDIR)/h460
endif

VPATH_C := $(OPAL_SRCDIR)/codec

########################################
# Source files for library

SOURCES := $(OPAL_SRCDIR)/opal/manager.cxx \
           $(OPAL_SRCDIR)/opal/console_mgr.cxx \
           $(OPAL_SRCDIR)/opal/endpoint.cxx \
           $(OPAL_SRCDIR)/opal/rtpep.cxx \
           $(OPAL_SRCDIR)/opal/connection.cxx \
           $(OPAL_SRCDIR)/opal/rtpconn.cxx \
           $(OPAL_SRCDIR)/opal/localep.cxx \
           $(OPAL_SRCDIR)/opal/call.cxx \
           $(OPAL_SRCDIR)/opal/mediafmt.cxx \
           $(OPAL_SRCDIR)/opal/mediatype.cxx \
           $(OPAL_SRCDIR)/opal/mediastrm.cxx \
           $(OPAL_SRCDIR)/opal/patch.cxx \
           $(OPAL_SRCDIR)/opal/transcoders.cxx \
           $(OPAL_SRCDIR)/opal/transports.cxx \
           $(OPAL_SRCDIR)/opal/guid.cxx \
           $(OPAL_SRCDIR)/rtp/rtp.cxx \
           $(OPAL_SRCDIR)/rtp/jitter.cxx \
           $(OPAL_SRCDIR)/rtp/metrics.cxx \
           $(OPAL_SRCDIR)/rtp/pcapfile.cxx \
           $(OPAL_SRCDIR)/opal/opal_c.cxx \
           $(OPAL_SRCDIR)/opal/pres_ent.cxx

ifeq ($(OPAL_IVR), yes)
SOURCES += $(OPAL_SRCDIR)/opal/ivr.cxx \
           $(OPAL_SRCDIR)/opal/opalvxml.cxx 
endif


ifeq ($(OPAL_HAS_MIXER), yes)
SOURCES += $(OPAL_SRCDIR)/opal/recording.cxx \
           $(OPAL_SRCDIR)/opal/opalmixer.cxx
ifeq ($(OSTYPE),mingw)
LIBS += -lvfw32
endif
endif

ifeq ($(OPAL_HAS_PCSS), yes)
SOURCES += $(OPAL_SRCDIR)/opal/pcss.cxx
endif

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

# H.323 files

ifeq ($(OPAL_H323),yes)
ifdef H323_AVAIL

SIMPLE_ASN_FILES := x880 mcs gcc

ifeq ($(OPAL_H450),yes)
SIMPLE_ASN_FILES += h4501 h4502 h4503 h4504 h4505 h4506 h4507 h4508 h4509 h45010 h45011
SOURCES		 += $(OPAL_SRCDIR)/h323/h450pdu.cxx 
endif

ASN_H_FILES   := $(addprefix $(ASN_INCDIR)/,$(addsuffix .h,  $(SIMPLE_ASN_FILES)))
ASN_CXX_FILES := $(addprefix $(ASN_SRCDIR)/,$(addsuffix .cxx,$(SIMPLE_ASN_FILES)))

ASN_H_FILES   += $(ASN_INCDIR)/h225.h
ASN_CXX_FILES += $(ASN_SRCDIR)/h225_1.cxx $(ASN_SRCDIR)/h225_2.cxx

ASN_H_FILES   += $(ASN_INCDIR)/h235.h $(ASN_SRCDIR)/h235_t.cxx
ASN_CXX_FILES += $(ASN_SRCDIR)/h235.cxx

ASN_H_FILES   += $(ASN_INCDIR)/h245.h
ASN_CXX_FILES += $(ASN_SRCDIR)/h245_1.cxx $(ASN_SRCDIR)/h245_2.cxx $(ASN_SRCDIR)/h245_3.cxx

ASN_H_FILES   += $(ASN_INCDIR)/h248.h
ASN_CXX_FILES += $(ASN_SRCDIR)/h248.cxx

ifeq ($(OPAL_H501),yes)
ASN_H_FILES   += $(ASN_INCDIR)/h501.h
ASN_CXX_FILES += $(ASN_SRCDIR)/h501.cxx
endif

.PRECIOUS: $(ASN_CXX_FILES) $(ASN_H_FILES)


SOURCES += $(ASN_CXX_FILES) \
           $(OPAL_SRCDIR)/h323/h323ep.cxx \
           $(OPAL_SRCDIR)/h323/h323.cxx \
           $(OPAL_SRCDIR)/h323/h323caps.cxx \
           $(OPAL_SRCDIR)/h323/h323neg.cxx \
           $(OPAL_SRCDIR)/h323/h323pdu.cxx \
           $(OPAL_SRCDIR)/h323/h323rtp.cxx \
           $(OPAL_SRCDIR)/h323/channels.cxx \
           $(OPAL_SRCDIR)/h323/svcctrl.cxx \
           $(OPAL_SRCDIR)/h323/q931.cxx \
           $(OPAL_SRCDIR)/h323/transaddr.cxx \
           $(OPAL_SRCDIR)/h323/gkclient.cxx \
           $(OPAL_SRCDIR)/h323/gkserver.cxx \
           $(OPAL_SRCDIR)/h323/h225ras.cxx \
           $(OPAL_SRCDIR)/h323/h323trans.cxx \
           $(OPAL_SRCDIR)/h323/h235auth.cxx \

ifeq ($(OPAL_H501),yes)
SOURCES += $(OPAL_SRCDIR)/h323/h501pdu.cxx \
           $(OPAL_SRCDIR)/h323/h323annexg.cxx \
           $(OPAL_SRCDIR)/h323/peclient.cxx 
endif

ifeq ($(OPAL_H460), yes)
ifdef H460_AVAIL
SOURCES += $(OPAL_SRCDIR)/h460/h4601.cxx \
	   $(OPAL_SRCDIR)/h460/h46018.cxx \
	   $(OPAL_SRCDIR)/h460/h46019.cxx \
	   $(OPAL_SRCDIR)/h460/h4609.cxx \
	   $(OPAL_SRCDIR)/h460/h460p.cxx \
	   $(OPAL_SRCDIR)/h460/h460pres.cxx \
	   $(OPAL_SRCDIR)/h460/h460tm.cxx
endif
endif

ifeq ($(OPAL_PTLIB_SSL), yes)
SOURCES += $(OPAL_SRCDIR)/h235auth1.cxx
LIBS += -lcrypto
endif

ifeq ($(OPAL_T120DATA), yes)
SOURCES += $(OPAL_SRCDIR)/t120/t120proto.cxx \
	   $(OPAL_SRCDIR)/t120/h323t120.cxx \
	   $(OPAL_SRCDIR)/t120/x224.cxx 
endif

ifeq ($(OPAL_T38_CAP), yes)
SOURCES += $(OPAL_SRCDIR)/t38/h323t38.cxx
endif

ifeq ($(OPAL_HAS_H224), yes)
ifdef H224_AVAIL
SOURCES += $(OPAL_SRCDIR)/h224/h323h224.cxx
endif
endif

endif
endif

##################
# IAX2 files

ifeq ($(OPAL_IAX2), yes)
ifdef IAX2_AVAIL

SOURCES += \
           $(OPAL_SRCDIR)/iax2/callprocessor.cxx \
           $(OPAL_SRCDIR)/iax2/frame.cxx \
           $(OPAL_SRCDIR)/iax2/iax2con.cxx \
           $(OPAL_SRCDIR)/iax2/iax2ep.cxx \
           $(OPAL_SRCDIR)/iax2/iax2medstrm.cxx \
           $(OPAL_SRCDIR)/iax2/iedata.cxx \
           $(OPAL_SRCDIR)/iax2/ies.cxx \
           $(OPAL_SRCDIR)/iax2/processor.cxx \
           $(OPAL_SRCDIR)/iax2/receiver.cxx \
           $(OPAL_SRCDIR)/iax2/regprocessor.cxx\
           $(OPAL_SRCDIR)/iax2/remote.cxx \
           $(OPAL_SRCDIR)/iax2/safestrings.cxx \
           $(OPAL_SRCDIR)/iax2/sound.cxx \
           $(OPAL_SRCDIR)/iax2/specialprocessor.cxx \
           $(OPAL_SRCDIR)/iax2/transmit.cxx 
endif
endif

################################################################################
# ZRTP files

ifeq ($(OPAL_ZRTP),yes)
ifdef ZRTP_AVAIL

SOURCES += $(OPAL_SRCDIR)/zrtp/opalzrtp.cxx \
           $(OPAL_SRCDIR)/rtp/zrtpudp.cxx

endif
endif


################################################################################
# SIP files

ifeq ($(OPAL_SIP),yes)
ifdef SIP_AVAIL

SOURCES += $(OPAL_SRCDIR)/sip/sipep.cxx \
           $(OPAL_SRCDIR)/sip/sipcon.cxx \
           $(OPAL_SRCDIR)/sip/sippdu.cxx \
           $(OPAL_SRCDIR)/sip/sdp.cxx \
           $(OPAL_SRCDIR)/sip/handlers.cxx \
           $(OPAL_SRCDIR)/sip/sippres.cxx

ifeq ($(OPAL_T38_CAP), yes)
SOURCES += $(OPAL_SRCDIR)/t38/sipt38.cxx
endif

endif
endif

##################
# H.224 files

ifeq ($(OPAL_HAS_H224), yes)
ifdef H224_AVAIL

SOURCES += $(OPAL_SRCDIR)/h224/q922.cxx \
	   $(OPAL_SRCDIR)/h224/h224.cxx \
	   $(OPAL_SRCDIR)/h224/h281.cxx
endif
endif

##################
# LIDS

ifeq ($(OPAL_LID), yes)

SOURCES += $(OPAL_SRCDIR)/lids/lid.cxx \
           $(OPAL_SRCDIR)/lids/lidep.cxx \
           $(OPAL_SRCDIR)/lids/lidpluginmgr.cxx \

endif

##################
# CAPI

ifeq ($(OPAL_CAPI), yes)

SOURCES += $(OPAL_SRCDIR)/lids/capi_ep.cxx

endif

##################
# SRTP

ifeq ($(OPAL_SRTP), yes)

SOURCES += $(OPAL_SRCDIR)/rtp/srtp.cxx \

endif


ifneq (,$(SWIG))

####################################################
# Java interface

ifeq ($(OPAL_JAVA), yes)

JAVA_SRCDIR      = $(OPAL_SRCDIR)/java
JAVA_WRAPPER     = $(JAVA_SRCDIR)/java_swig_wrapper.c

VPATH_C         += $(JAVA_SRCDIR)
SOURCES         += $(JAVA_WRAPPER)

endif


####################################################
# Ruby interface

ifeq ($(OPAL_RUBY), yes)

RUBY_SRCDIR      = $(OPAL_SRCDIR)/ruby
RUBY_WRAPPER     = $(JAVA_SRCDIR)/ruby_swig_wrapper.c

VPATH_C         += $(RUBY_SRCDIR)
SOURCES         += $(RUBY_WRAPPER)

endif

endif # SWIG


##################
# T.38 Fax

ifeq ($(OPAL_FAX), yes)
SOURCES += $(OPAL_SRCDIR)/t38/t38proto.cxx \
           $(ASN_SRCDIR)/t38.cxx
endif


##################
# IM/MSRP

SOURCES += $(OPAL_SRCDIR)/im/t140.cxx \
	   $(OPAL_SRCDIR)/im/im_mf.cxx \
	   $(OPAL_SRCDIR)/im/rfc4103.cxx 

ifeq ($(OPAL_HAS_MSRP), yes)
SOURCES += $(OPAL_SRCDIR)/im/msrp.cxx 
endif
ifeq ($(OPAL_HAS_SIPIM), yes)
SOURCES += $(OPAL_SRCDIR)/im/sipim.cxx 
endif

##################
# Software codecs

SOURCES += $(OPAL_SRCDIR)/codec/g711codec.cxx \
           $(OPAL_SRCDIR)/codec/g711.c \
           $(OPAL_SRCDIR)/codec/g722mf.cxx \
           $(OPAL_SRCDIR)/codec/g7221mf.cxx \
           $(OPAL_SRCDIR)/codec/g7222mf.cxx \
           $(OPAL_SRCDIR)/codec/g7231mf.cxx \
           $(OPAL_SRCDIR)/codec/g726mf.cxx \
           $(OPAL_SRCDIR)/codec/g728mf.cxx \
           $(OPAL_SRCDIR)/codec/g729mf.cxx \
           $(OPAL_SRCDIR)/codec/gsm0610mf.cxx \
           $(OPAL_SRCDIR)/codec/gsmamrmf.cxx \
           $(OPAL_SRCDIR)/codec/iLBCmf.cxx \
           $(OPAL_SRCDIR)/codec/t38mf.cxx \
           $(OPAL_SRCDIR)/codec/rfc2833.cxx \
           $(OPAL_SRCDIR)/codec/opalwavfile.cxx \
	   $(OPAL_SRCDIR)/codec/silencedetect.cxx \
	   $(OPAL_SRCDIR)/codec/opalpluginmgr.cxx \
	   $(OPAL_SRCDIR)/codec/ratectl.cxx 

ifeq ($(OPAL_VIDEO), yes)
SOURCES += $(OPAL_SRCDIR)/codec/vidcodec.cxx 
endif

ifeq ($(OPAL_RFC4175), yes)
SOURCES += $(OPAL_SRCDIR)/codec/rfc4175.cxx
endif

ifeq ($(OPAL_RFC2435), yes)
SOURCES += $(OPAL_SRCDIR)/codec/rfc2435.cxx
endif

ifeq ($(OPAL_G711PLC), yes)
SOURCES += $(OPAL_SRCDIR)/codec/g711a1_plc.cxx
endif

ifeq ($(OPAL_AEC), yes)

SOURCES		+= $(OPAL_SRCDIR)/codec/echocancel.cxx

ifeq ($(SPEEXDSP_SYSTEM), no)

SPEEXDSP_SRCDIR    = $(OPAL_SRCDIR)/codec/speex/libspeex

VPATH_C         += $(SPEEXDSP_SRCDIR)
VPATH_CXX       += $(SPEEXDSP_SRCDIR)

SOURCES         += $(SPEEXDSP_SRCDIR)/speex_preprocess.c \
		   $(SPEEXDSP_SRCDIR)/smallft.c \
                   $(SPEEXDSP_SRCDIR)/misc.c \
                   $(SPEEXDSP_SRCDIR)/mdf.c \
                   $(SPEEXDSP_SRCDIR)/math_approx.c \
                   $(SPEEXDSP_SRCDIR)/kiss_fftr.c \
                   $(SPEEXDSP_SRCDIR)/kiss_fft.c \
                   $(SPEEXDSP_SRCDIR)/fftwrap.c
endif # SPEEXDSP_SYSTEM

endif # ifeq ($(OPAL_AEC), yes)

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

ifeq ($(OSTYPE),Darwin)
CFLAGS		+= -fno-common -dynamic
ARCHIVE			:= libtool -static -o
endif # Darwin

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

#ifeq ($(OSTYPE),mingw)
#LDFLAGS += -enable-runtime-pseudo-reloc -fatal-warning
#endif # mingw

###############################################################################
# Build rules

.SUFFIXES:	.cxx .prc 

vpath %.cxx $(VPATH_CXX)
vpath %.cpp $(VPATH_CXX)
vpath %.c   $(VPATH_C)
vpath %.o   $(OPAL_OBJDIR)
vpath %.dep $(OPAL_DEPDIR)

#  clean whitespace out of source file list
SOURCES         := $(strip $(SOURCES))

#
# create list of object files 
#
SRC_OBJS := $(SOURCES:.c=.o)
SRC_OBJS := $(SRC_OBJS:.cxx=.o)
SRC_OBJS := $(SRC_OBJS:.cpp=.o)
OBJS	 := $(EXTERNALOBJS) $(patsubst %.o, $(OPAL_OBJDIR)/%.o, $(notdir $(SRC_OBJS) $(OBJS)))

#
# create list of dependency files 
#
SRC_DEPS := $(SOURCES:.c=.dep)
SRC_DEPS := $(SRC_DEPS:.cxx=.dep)
SRC_DEPS := $(SRC_DEPS:.cpp=.dep)
DEPS	 := $(patsubst %.dep, $(OPAL_DEPDIR)/%.dep, $(notdir $(SRC_DEPS) $(DEPS)))

#
# define rule for .cxx, .cpp and .c files
#


$(OPAL_OBJDIR)/%.o : %.cxx
	@if [ ! -d $(OPAL_OBJDIR) ] ; then mkdir -p $(OPAL_OBJDIR) ; fi
	$(Q_CC)$(CXX) $(CXXFLAGS) -c $< -o $@

$(OPAL_OBJDIR)/%.o :  %.c 
	@if [ ! -d $(OPAL_OBJDIR) ] ; then mkdir -p $(OPAL_OBJDIR) ; fi
	$(Q_CC)$(CC) $(CFLAGS) -c $< -o $@

#
# define rule for .dep files
#
$(OPAL_DEPDIR)/%.dep : %.cxx 
	@if [ ! -d $(OPAL_DEPDIR) ] ; then mkdir -p $(OPAL_DEPDIR) ; fi
	@printf %s $(OPAL_OBJDIR)/ > $@
	$(Q_DEP)$(CXX) $(CXXFLAGS:-g=) -M $< >> $@

$(OPAL_DEPDIR)/%.dep : %.c 
	@if [ ! -d $(OPAL_DEPDIR) ] ; then mkdir -p $(OPAL_DEPDIR) ; fi
	@printf %s $(OPAL_OBJDIR)/ > $@
	$(Q_DEP)$(CC) $(CFLAGS:-g=) -M $< >> $@


#####################################################################
# Main targets

# This target was intetionally put here since make dumbly executes the first it finds
# when called without an explicit target.


.PHONY: default_target

ifeq ($(OPAL_SHARED_LIB),)
default_target :: opt
else
default_target :: Makefile $(OPAL_LIBDIR)/$(LIB_FILENAME_STATIC)
ifeq ($(OPAL_SHARED_LIB),1)
default_target :: $(OPAL_LIBDIR)/$(LIB_FILENAME_SHARED)
endif
default_target :: subdirs
endif

.PHONY: default_depend
default_depend :: depend

.PHONY: subdirs $(SUBDIRS)

subdirs:
	@set -e; $(foreach dir,$(SUBDIRS),if test -d ${dir} ; then $(MAKE) -C $(dir); fi ; )

clean:
	rm -rf $(OPAL_LIBDIR)
	@set -e; $(foreach dir,$(SUBDIRS),if test -d ${dir} ; then $(MAKE) -C $(dir) clean; fi ; )

depend:   Makefile $(DEPS) 
	@set -e; $(foreach dir,$(SUBDIRS),if test -d ${dir} ; then $(MAKE) -C $(dir) depend; fi ; )


ifneq ($(wildcard $(OPAL_DEPDIR)/*.dep),)
include $(OPAL_DEPDIR)/*.dep
endif

Makefile: Makefile.in configure
	@echo
	@echo "*******************************************************"
	@echo Makefile is not up to date, is a ./configure necessary?
	@echo "*******************************************************"
	@false


#####################################################################
# Targets for the libraries

$(OPAL_LIBDIR)/$(LIB_FILENAME_STATIC): $(OBJS) 
	@if [ ! -d $(OPAL_LIBDIR) ] ; then mkdir $(OPAL_LIBDIR) ; fi
	$(Q_AR)$(ARCHIVE) $(OPAL_LIBDIR)/$(LIB_FILENAME_STATIC) $(OBJS)
ifeq ($(HAVE_RANLIB),yes)
	$(RANLIB) $(OPAL_LIBDIR)/$(LIB_FILENAME_STATIC)
endif

$(OPAL_LIBDIR)/$(LIB_FILENAME_SHARED): $(OPAL_LIBDIR)/$(LIB_FILENAME_STATIC)

ifeq ($(OPAL_SHARED_LIB),1)

  $(OPAL_LIBDIR)/$(LIB_FILENAME_SHARED): $(OPAL_LIBDIR)/$(LIB_FILENAME_SHARED_PAT)
	rm -f $(OPAL_LIBDIR)/$(LIB_FILENAME_SHARED) ; ln -sf  $(LIB_FILENAME_SHARED_PAT) $(OPAL_LIBDIR)/$(LIB_FILENAME_SHARED)

  $(OPAL_LIBDIR)/$(LIB_FILENAME_SHARED_PAT): $(OPAL_LIBDIR)/$(LIB_FILENAME_STATIC)
	@if [ ! -d $(OPAL_LIBDIR) ] ; then mkdir $(OPAL_LIBDIR) ; fi
	$(Q_LD)$(LD) $(LDSOOPTS) -o $(OPAL_LIBDIR)/$(LIB_FILENAME_SHARED_PAT) $(LDFLAGS) $(EXTLIBS) $(OBJS) $(LIBS)

endif # OPAL_SHARED_LIB


ifneq (,$(SWIG))

ifeq ($(OPAL_JAVA), yes)
$(JAVA_WRAPPER): $(JAVA_SRCDIR)/opal.i $(OPAL_INCDIR)/opal.h
	$(SWIG) -java -package org.opalvoip -w451 -I$(OPAL_INCDIR) -o $@ $<
endif

ifeq ($(OPAL_RUBY), yes)
$(RUBY_WRAPPER): $(RUBY_SRCDIR)/opal.i $(OPAL_INCDIR)/opal.h
	$(SWIG) -ruby -w451 -I$(OPAL_INCDIR) -o $@ $<
endif

endif


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

$(OPAL_SRCDIR)/opal/manager.cxx: $(REVISION_FILE)

$(REVISION_FILE) : $(REVISION_FILE).in
ifeq ($(shell which svn 2> /dev/null),)
	$(Q)sed -e "s/.WCREV./`sed -n -e 's/.*Revision: \([0-9]*\).*/\1/p' $<`/" $< > $@
else
ifeq ($(wildcard .svn),)
	$(Q)sed -e "s/.WCREV./`sed -n -e 's/.*Revision: \([0-9]*\).*/\1/p' $<`/" $< > $@
else
	$(Q)sed "s/SVN_REVISION.*/SVN_REVISION `LC_ALL=C svn info | sed -n 's/Revision: //p'`/" $< > $@.tmp
	$(Q)if diff -q $@ $@.tmp >/dev/null 2>&1; then \
	  rm $@.tmp; \
	else \
	  mv -f $@.tmp $@; \
	  echo "Revision file updated to `sed -n 's/.*SVN_REVISION\(.*\)/\1/p' $@`" ; \
	fi

.PHONY: $(REVISION_FILE)
endif
endif


#####################################################################
# Install targets

install:
	mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir)
	( if test -e $(OPAL_LIBDIR)/$(LIB_FILENAME_STATIC) ; then \
	  $(INSTALL) -m 755 $(OPAL_LIBDIR)/$(LIB_FILENAME_STATIC) $(DESTDIR)$(libdir) ; \
	fi )
	( if test -e $(OPAL_LIBDIR)/$(DEBUG_LIB_FILENAME_STATIC) ; then \
	  $(INSTALL) -m 755 $(OPAL_LIBDIR)/$(DEBUG_LIB_FILENAME_STATIC) $(DESTDIR)$(libdir) ; \
	fi )
	( if test -e $(OPAL_LIBDIR)/$(LIB_FILENAME_SHARED_PAT) ; then \
	  $(INSTALL) -m 755 $(OPAL_LIBDIR)/$(LIB_FILENAME_SHARED_PAT) $(DESTDIR)$(libdir) ; \
	  ln -snf $(LIB_FILENAME_SHARED_PAT) $(DESTDIR)$(libdir)/$(LIB_FILENAME_SHARED) ; \
	fi )
	( if test -e $(OPAL_LIBDIR)/$(DEBUG_LIB_FILENAME_SHARED_PAT) ; then \
	  $(INSTALL) -m 755 $(OPAL_LIBDIR)/$(DEBUG_LIB_FILENAME_SHARED_PAT) $(DESTDIR)$(libdir) ; \
	  ln -snf $(DEBUG_LIB_FILENAME_SHARED_PAT) $(DESTDIR)$(libdir)/$(DEBUG_LIB_FILENAME_SHARED) ; \
	fi )
	mkdir -p $(DESTDIR)$(libdir)/pkgconfig ; chmod 755 $(DESTDIR)$(libdir)/pkgconfig
	$(INSTALL) -m 644 opal.pc $(DESTDIR)$(libdir)/pkgconfig

	mkdir -p $(DESTDIR)$(includedir)/opal; chmod 755 $(DESTDIR)$(includedir)/opal
	$(INSTALL) -m 644 include/opal.h $(DESTDIR)$(includedir)/opal
	( for dir in asn codec h323 h460 iax2 im lids opal rtp sip t120 t38 zrtp; \
		do mkdir -p $(DESTDIR)$(includedir)/opal/$$dir ; chmod 755 $(DESTDIR)$(includedir)/opal/$$dir ; \
		( for fn in include/$$dir/*.h ; do \
			$(INSTALL) -m 644 $$fn $(DESTDIR)$(includedir)/opal/$$dir ; \
		done); \
	done)

ifeq ($(OPAL_PLUGINS),yes)
	$(MAKE) -C plugins install
endif

uninstall:
	( for filename in $(LIB_FILENAME_SHARED) \
                          $(LIB_FILENAME_SHARED_PAT) \
                          $(LIB_FILENAME_STATIC); \
	do rm -f $(DESTDIR)$(libdir)/$$filename ;\
	done)
	rm -rf $(DESTDIR)$(includedir)/opal
	rm -f $(DESTDIR)$(libdir)/pkgconfig/opal.pc

ifeq ($(OPAL_PLUGINS),yes)
	$(MAKE) -C plugins uninstall
endif


###############################################################################
# A collection or random useful targets

docs: FORCE
	rm -rf html
	doxygen opal_cfg.dxy > doxygen.out 2>&1

graphdocs: FORCE
	rm -rf html
	sed "s/HAVE_DOT.*=.*/HAVE_DOT=YES/" opal_cfg.dxy > /tmp/docs.dxy
	doxygen /tmp/docs.dxy > doxygen.out 2>&1
	rm /tmp/docs.dxy

FORCE:

opt:
	$(MAKE) DEBUG_BUILD=no OPAL_SHARED_LIB=1

optnoshared:
	$(MAKE) DEBUG_BUILD=no OPAL_SHARED_LIB=0

optdepend:
	$(MAKE) DEBUG_BUILD=no depend

debug:
	$(MAKE) DEBUG_BUILD=yes OPAL_SHARED_LIB=1

debugnoshared:
	$(MAKE) DEBUG_BUILD=yes OPAL_SHARED_LIB=0

debugdepend:
	$(MAKE) DEBUG_BUILD=yes depend

both: opt debug

bothnoshared:
	$(MAKE) DEBUG_BUILD=yes P_SHAREDLIB=0
	$(MAKE) DEBUG_BUILD=no P_SHAREDLIB=0

all: optdepend opt debugdepend debug

update:
	svn update
	$(MAKE) all

distclean: clean
	rm -rf config.log config.err autom4te.cache config.status a.out aclocal.m4
	rm -rf lib*

# End of file #################################################################
