#################################################################################
#
# Makefile
#
# Makefile for the OpenH323 wrapper library and the ASTERISK channel
# driver module.
#
# Copyright (c) 2002-2005 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.48.2.5 2005/01/21 16:33:47 manousos Exp $
#
#################################################################################

# Export all variables to child processes
.EXPORT_ALL_VARIABLES:

#################################################################################
###### START OF USER CONFIGURABLE PARAMETERS 

#
# Install everything under this directory. If this is empty, then everything
# will be installed under /
#
DESTDIR=

#
# Set PWLIBDIR variable to the directory containing the sources of 
# PWlib library. 
#
# Note: You must build the 'pwlib' library before trying to 
# compile asterisk-oh323. Do not use the installed library of your
# distribution. It won't work.
#
PWLIBDIR=/root/src/oh323/pwlib

#
# Set OPENH323LIBDIR variable to the directory containing the sources of
# OpenH323 library. 
#
# Note: You must build the 'openh323' library before trying to 
# compile asterisk-oh323. Do not use the installed library of your
# distribution. It won't work.
#
OPENH323DIR=/root/src/oh323/openh323

#
# Set ASTERISKINCDIR variable to the directory containing the include files of
# Asterisk PBX.
#
ASTERISKINCDIR=/root/src/asterisk/include

#
# Set ASTERISKMODDIR variable to the directory where ASTERISK's modules reside.
# The "chan_oh323.so" driver will be installed in this directory.
#
# Note: This directory is created under $DESTDIR.
#
ASTERISKMODDIR=/usr/lib/asterisk/modules

#
# Set ASTERISKETCDIR variable to the directory where ASTERISK's configuration
# files reside. The "oh323.conf" file will be installed in this directory.
#
# Note: This directory is created under $DESTDIR.
#
ASTERISKETCDIR=/etc/asterisk

#
# Set OH323WRAPLIBDIR variable to the directory where oh323wrap library
# will be installed. You SHOULD add this directory to your 
# LD_LIBRARY_PATH shell variable, or to the /etc/ld.so.conf
# file and run "ldconfig" after the installation of asterisk-oh323.
#
# Note: This directory is created under $DESTDIR.
#
OH323WRAPLIBDIR=/usr/local/lib

#
# Set WRAPTRACING to 1 to enable tracing information from the OpenH323Wrap
# library or to 0 to disable it.
#
WRAPTRACING=1

#
# Set OH323STAT to 1 to build the OH323 Asterisk channel driver
# with statically linked OpenH323/Pwlib/oh323wrap libraries. 
#
# Note: Turn this flag on if you don't want problems in runtime where the
# channel driver links with different libraries than these used during
# compilation (e.g. if you have installed a distro specific OpenH323/Pwlib).
# With this flag on the channel driver is huge, in size, but Asterisk boots
# faster!
#
OH323STAT=1

#
# Set OH323BUILDTYPE to 'debug', 'opt' or 'optnotrace' to select the
# build type. This should match the build type of the libraries 
# (OpenH323/Pwlib).
#
#OH323BUILDTYPE=debug
OH323BUILDTYPE=opt
#OH323BUILDTYPE=optnotrace

#
# Define options that were used during Asterisk compilation
#
#DEBUG_THREADS=1
#DO_CRASH=1
#DETECT_DEADLOCKS=1

#
# Extra compilation options. Here you should add the options
# PWLIB, OPENH323 were compiled with.
#
#NOVIDEO=1
#NO_SPEEX=1
#NOAUDIOCODECS=1
#NOTRACE=1
#NO_IPv6=1
#P_PTHREADS=1

#HAS_OH323MODS=1

#SKIP_SUFFIX=1
#LIBPT_BASE=libpt
#LIBH323_BASE=libh323

#SKIP_EXTLIBS=1
#EXTLIBS=

###### END OF USER CONFIGURABLE PARAMETERS 
#################################################################################

#
# Definition of variables and toolchain
#
SHELL := /bin/sh
SUBDIRS = wrapper asterisk-driver
.PHONY: all build install clean subdirs_build subdir_install subdir_clean \
		rpm rpm_clean help $(SUBDIRS)
CC = gcc
CPP = g++
MAKE = make
INSTALL = install
TOUCH = touch
AR = ar
STRIP = strip
STRIPFLAGS=
OH323WRAPINCLUDE= \
				 -I$(PWLIBDIR)/include \
				 -I$(OPENH323DIR)/include \
				 -I$(OPENH323DIR)/include/openh323 \
				 -I../asterisk-driver
ifdef	NOTRACE
OH323BUILDTYPE = optnotrace
endif
ifeq	($(OH323BUILDTYPE),optnotrace)
OPENH323USERFLAGS := NOTRACE=1
endif
CPPFLAGS = -Wall -x c++ -Os
ASTERISKINCLUDE = -I$(ASTERISKINCDIR) -I../wrapper
CFLAGS = -Wall
ifdef	HAS_OH323MODS
CPPFLAGS += -DHAS_OH323MODS
CFLAGS += -DHAS_OH323MODS
endif

ifdef DEBUG_THREADS
CFLAGS += -DDEBUG_THREADS
endif
ifdef DO_CRASH
CFLAGS += -DDO_CRASH
endif
ifdef DETECT_DEADLOCKS
CFLAGS += -DDETECT_DEADLOCKS
endif

#
# Rules
#
build: subdirs_build
 
strip: subdirs_strip
 
install: subdirs_build subdirs_install
 
clean: subdirs_clean rpm_clean

all: subdirs_build subdirs_strip subdirs_install

subdirs_build:
	for x in $(SUBDIRS); do $(MAKE) -C $$x build || exit 1 ; done
 
subdirs_strip:
	for x in $(SUBDIRS); do $(MAKE) -C $$x strip || exit 1 ; done
 
subdirs_install:
	for x in $(SUBDIRS); do $(MAKE) -C $$x install || exit 1 ; done

subdirs_clean:
	for x in $(SUBDIRS); do $(MAKE) -C $$x clean || exit 1 ; done

rpm:
	$(MAKE) -C rpm rpm

rpm_clean:
	$(MAKE) -C rpm rpm_clean

help:
	@echo "Available targets for 'asterisk-oh323' :"
	@echo "  make            Build the binaries (channel driver/wrapper library)"
	@echo "  make build      The same as a simple 'make'"
	@echo "  make strip      Strip the built binaries to save space"
	@echo "  make install    Install the built binaries"
	@echo "  make all        Build, strip and install the binaries"
	@echo "  make clean      Delete temporary, object and built binaries"

