#################################################################################
#
# Makefile
#
# Makefile for the ASTERISK openh323 channel driver
#
# Copyright (c) 2002,2003 InAccess Networks
# Michalis Manousos <manousos@inaccessnetworks.com>
# Dimitris Economou <decon@inaccessnetworks.com>
#
# This file is part of "H323 support for ASTERISK"
#
# "H323 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. 
#
# "H323 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.18 2003/07/25 13:07:19 manousos Exp $
#
#################################################################################

TARGET=chan_oh323.so

ifndef SKIP_SUFFIX
	ifeq ($(WRAPSTAT),1)
		LIBPTPATH=$(word 1,$(shell ls $(PWLIBDIR)/lib/libpt*d.a))
	else
		LIBPTPATH=$(word 1,$(shell ls $(PWLIBDIR)/lib/libpt*r.so))
	endif
	LIBPTNAME=$(subst lib,,$(basename $(notdir $(LIBPTPATH))))
	LIBPTDSUF=$(findstring _d,$(LIBPTNAME))
	LIBPTRSUF=$(findstring _r,$(LIBPTNAME))
	LIBPT=$(subst _d,,$(subst _r,,$(LIBPTNAME)))
else
	LIBPTPATH=$(word 1,$(shell ls $(PWLIBDIR)/lib/libpt*.so))
	LIBPTNAME=$(subst lib,,$(basename $(notdir $(LIBPTPATH))))
	LIBPTDSUF=
	LIBPTRSUF=
	LIBPT=$(subst _d,,$(subst _r,,$(LIBPTNAME)))
endif

ifndef SKIP_SUFFIX
	ifeq ($(WRAPSTAT),1)
		LIBH323PATH=$(word 1,$(shell ls $(OPENH323DIR)/lib/libh323*d.a))
	else
		ifdef NOTRACE
			LIBH323PATH=$(word 1,$(shell ls $(OPENH323DIR)/lib/libh323*n.so))
		else
			LIBH323PATH=$(word 1,$(shell ls $(OPENH323DIR)/lib/libh323*r.so))
		endif
	endif
	LIBH323NAME=$(subst lib,,$(basename $(notdir $(LIBH323PATH))))
	LIBH323DSUF=$(findstring _d,$(LIBH323NAME))
	ifdef NOTRACE
		LIBH323RSUF=$(findstring _n,$(LIBH323NAME))
	else
		LIBH323RSUF=$(findstring _r,$(LIBH323NAME))
	endif
	LIBH323=$(subst _n,,$(subst _d,,$(subst _r,,$(LIBH323NAME))))
else
	LIBH323PATH=$(word 1,$(shell ls $(OPENH323DIR)/lib/libh323*.so))
	LIBH323NAME=$(subst lib,,$(basename $(notdir $(LIBH323PATH))))
	LIBH323DSUF=
	LIBH323RSUF=
	LIBH323=$(subst _n,,$(subst _d,,$(subst _r,,$(LIBH323NAME))))
endif

DRVDEPS=$(shell ls *.h)

all: chan_oh323.so

install:
	if [ ! -d $(DESTDIR)$(ASTERISKMODDIR) ]; then \
		$(INSTALL) -d $(DESTDIR)$(ASTERISKMODDIR); \
	fi
	$(INSTALL) chan_oh323.so $(DESTDIR)$(ASTERISKMODDIR)
	if [ ! -d $(DESTDIR)$(ASTERISKETCDIR) ]; then \
		$(INSTALL) -d $(DESTDIR)$(ASTERISKETCDIR); \
	fi
	if [ ! -f $(DESTDIR)$(ASTERISKETCDIR)/oh323.conf ]; then \
		$(INSTALL) oh323.conf.sample $(DESTDIR)$(ASTERISKETCDIR)/oh323.conf; \
	fi

clean:
	rm -f *.o *.so

chan_oh323.so: chan_oh323.o
	@if [ ! -f "$(LIBPTPATH)" ]; then \
		echo "ERROR: No PWLIB library found!"; exit 1; \
	fi
	@if [ ! -f "$(LIBH323PATH)" ]; then \
		echo "ERROR: No OPENH323 library found!"; exit 1; \
	fi
ifeq ($(WRAPSTAT),1)
	$(CC) -shared -Xlinker -x -g -o $@ $< \
	-L../wrapper -loh323wrapd \
	-L$(OPENH323DIR)/lib -l$(LIBH323)$(LIBH323DSUF) \
	-L$(PWLIBDIR)/lib -l$(LIBPT)$(LIBPTDSUF) \
	-lstdc++ -lpthread -ldl -L$(SSLLIBDIR) -lcrypto -lssl 
else
	$(CC) -shared -Xlinker -x -g -o $@ $< \
	-L../wrapper -loh323wrap \
	-L$(OPENH323DIR)/lib -l$(LIBH323)$(LIBH323RSUF) \
	-L$(PWLIBDIR)/lib -l$(LIBPT)$(LIBPTRSUF) \
	-lstdc++ -lpthread -ldl -L$(SSLLIBDIR) -lcrypto -lssl 
endif

chan_oh323.o: chan_oh323.c $(DRVDEPS)
	$(CC) $(CFLAGS) $(ASTERISKINCLUDE) -g -c -o $@ $<

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