#################################################################################
#
# Makefile
#
# Makefile for the OpenH323 wrapper Library
#
# Copyright (c) 2002-2004 InAccess Networks
# Michalis Manousos <manousos@inaccessnetworks.com>
# Dimitris Economou <decon@inaccessnetworks.com>
#
# This file is part of "H.323 support for ASTERISK"
#
# "H.323 support for ASTERISK" is free software;
# you can redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the Free Software Foundation;
# either version 2 of the License, or (at your option) any later version. 
#
# "H.323 support for ASTERISK" 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.
# See the GNU General Public License for more details. 
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
#
# $Id: Makefile,v 1.23 2004/06/29 17:23:26 manousos Exp $
#
#################################################################################

.PHONY: .pwlib_version .openh323_version

STDCCFLAGS :=
# Compile-time flags from PWLib
#ifndef NO_IPv6
#STDCCFLAGS += -DP_HAS_IPV6
#endif

# Compile-time flags from OpenH323
ifdef NOVIDEO
STDCCFLAGS += -DNO_H323_VIDEO
endif
ifdef NOAUDIOCODECS
STDCCFLAGS += -DNO_H323_AUDIO_CODECS
endif
ifdef NO_SPEEX
STDCCFLAGS += -DNO_SPEEX
endif
ifdef NOTRACE
STDCCFLAGS += -DPASN_NOPRINTON -DPASN_LEANANDMEAN
endif
ifdef	OH323_SUPPRESS_H235
STDCCFLAGS  += -DOH323_SUPPRESS_H235
endif

ifeq ($(WRAPTRACING),1)
ifeq (,$(WRAPTRACING_LEVEL))
WRAPTRACING_LEVEL=5
endif
CPPFLAGS += -DWRAPTRACING -DWRAPTRACING_LEVEL=$(WRAPTRACING_LEVEL)
endif

PWLIB_VERSION=$(shell if [ -f .pwlib_version ]; then cat .pwlib_version; else echo "UNKNOWN"; fi)
OH323_VERSION=$(shell if [ -f .openh323_version ]; then cat .openh323_version; else echo "UNKNOWN"; fi)
CPPFLAGS += -DPWLIBVERSION=\"$(PWLIB_VERSION)\" \
			-DOPENH323VERSION=\"$(OH323_VERSION)\"
WRAPOBJECTS = wrapper_misc.o asteriskaudio.o wrapendpoint.o wrapconnection.o \
			  wrapper.o wrapcaps.o
WRAPDEPS = $(shell ls *.hxx *.h)

.pwlib_version:
	./check_ver $(PWLIBDIR) pwlib

.openh323_version:
	./check_ver $(OPENH323DIR) openh323

all: .pwlib_version .openh323_version $(WRAPOBJECTS)
	@if [ "$(PWLIB_VERSION)" = "UNKNOWN" ]; then \
		echo "*** Cannot determine the version of PWLIB!"; exit 1; \
	fi
	@if [ "$(OPENH323_VERSION)" = "UNKNOWN" ]; then \
		echo "*** Cannot determine the version of OPENH323!"; exit 1; \
	fi
ifeq ($(WRAPSTAT),1)
	$(AR) rc liboh323wrapd.a $(WRAPOBJECTS)
else
	$(CC) -shared -Wl,-soname,liboh323wrap.so -o liboh323wrap.so $(WRAPOBJECTS)
endif

install:
	if [ ! -d $(DESTDIR)$(OH323WRAPLIBDIR) ]; then \
		$(INSTALL) -d $(DESTDIR)$(OH323WRAPLIBDIR); \
	fi
ifeq ($(WRAPSTAT),1)
	$(INSTALL) liboh323wrapd.a $(DESTDIR)$(OH323WRAPLIBDIR)
else
	$(INSTALL) liboh323wrap.so $(DESTDIR)$(OH323WRAPLIBDIR)
	cd $(DESTDIR)$(OH323WRAPLIBDIR); rm -f ./liboh323wrap.so.1; rm -f ./liboh323wrap.so.1.1
	cd $(DESTDIR)$(OH323WRAPLIBDIR); ln -s liboh323wrap.so liboh323wrap.so.1
	cd $(DESTDIR)$(OH323WRAPLIBDIR); ln -s liboh323wrap.so liboh323wrap.so.1.1
endif

clean:
	rm -f $(WRAPOBJECTS) liboh323wrap* .pwlib_version* .openh323_version*

# Make sure that ASTERISK's channel driver will be re-built.
%.o: %.cxx $(WRAPDEPS)
	$(CPP) $(CPPFLAGS) $(STDCCFLAGS) $(OH323WRAPINCLUDE) -c $< -o $@
	$(TOUCH) ../asterisk-driver/chan_oh323.c

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