Index: build_tools/menuselect-deps.in
===================================================================
--- build_tools/menuselect-deps.in	(revision 323)
+++ build_tools/menuselect-deps.in	(working copy)
@@ -1 +1,2 @@
 MYSQLCLIENT=@PBX_MYSQLCLIENT@
+ASTERISK=@PBX_ASTERISK@
Index: makeopts.in
===================================================================
--- makeopts.in	(revision 323)
+++ makeopts.in	(working copy)
@@ -39,5 +39,7 @@
 MYSQLCLIENT_LIB=@MYSQLCLIENT_LIB@
 MYSQLCLIENT_INCLUDE=@MYSQLCLIENT_INCLUDE@
 
+ASTERISK_INCLUDE=@ASTERISK_INCLUDE@
+
 NCURSES_LIB=@NCURSES_LIB@
 NCURSES_INCLUDE=@NCURSES_INCLUDE@
Index: menuselect-tree
===================================================================
--- menuselect-tree	(revision 323)
+++ menuselect-tree	(working copy)
@@ -4,18 +4,24 @@
         <category name="MENUSELECT_ADDONS" displayname="Asterisk Addon Modules">
 		<member name="app_addon_sql_mysql" remove_on_change="app_addon_sql_mysql.so app_addon_sql_mysql.o" displayname="MySQL Dialplan Application">
 			<depend>mysqlclient</depend>
+			<depend>asterisk</depend>
 		</member>
 		<member name="app_saycountpl" remove_on_change="app_saycountpl.so app_saycountpl.so" displayname="Say Polish Counting Words">
+			<depend>asterisk</depend>
 		</member>
 		<member name="cdr_addon_mysql" remove_on_change="cdr_addon_mysql.so cdr_addon_mysql.o" displayname="MySQL CDR Backend">
 			<depend>mysqlclient</depend>
+			<depend>asterisk</depend>
 		</member>
 		<member name="chan_ooh323" displayname="Objective Systems H.323 Channel Driver">
+			<depend>asterisk</depend>
 		</member>
 		<member name="format_mp3" remove_on_change="formats/format_mp3.o formats/format_mp3.so" displayname="MP3 File Format Handler">
+			<depend>asterisk</depend>
 		</member>
 		<member name="res_config_mysql" remove_on_change="res_config_mysql.so res_config_mysql.o" displayname="MySQL Realtime Interface">
 			<depend>mysqlclient</depend>
+			<depend>asterisk</depend>
 		</member>
 	</category>
 </menu>
Index: configure.ac
===================================================================
--- configure.ac	(revision 323)
+++ configure.ac	(working copy)
@@ -162,6 +162,7 @@
 AST_EXT_LIB_SETUP([CURSES], [curses], [curses])
 AST_EXT_LIB_SETUP([NCURSES], [ncurses], [ncurses])
 AST_EXT_LIB_SETUP([MYSQLCLIENT], [mysqlclient], [mysqlclient])
+AST_EXT_LIB_SETUP([ASTERISK], [asterisk], [asterisk])
 
 AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h])
 
@@ -209,6 +210,42 @@
    exit 1
 fi
 
+if test "${USE_ASTERISK}" != "no"; then
+   AC_MSG_CHECKING(for asterisk.h)
+   saved_cppflags="${CPPFLAGS}"
+   if test "x${ASTERISK_DIR}" != "x"; then
+      CPPFLAGS="${CPPFLAGS} -I${ASTERISK_DIR}/include"
+   fi
+   AC_COMPILE_IFELSE(
+	[
+	AC_LANG_PROGRAM(
+	[#include <asterisk.h>],
+	[])
+	],
+	[	AC_MSG_RESULT(yes) 
+		ac_cv_asterisk_h="yes" 
+	],
+	[	AC_MSG_RESULT(no) 
+		ac_cv_asterisk_h="no" 
+	]
+	)
+   CPPFLAGS="${saved_cppflags}"
+   if test "${ac_cv_asterisk_h}" = "yes"; then
+	if test "${ASTERISK_DIR}" != ""; then
+	   ASTERISK_INCLUDE="-I${ASTERISK_DIR}/include"
+	fi
+	PBX_ASTERISK=1
+	AC_DEFINE([HAVE_ASTERISK], 1, [Define if your system has the Asterisk headers.])
+   elif test ! -z "${ASTERISK_MANDATORY}"; 
+   then
+      AC_MSG_NOTICE([***])
+      AC_MSG_NOTICE([*** The Asterisk installation on this system appears to be broken.])
+      AC_MSG_NOTICE([*** Either correct the installation, or run configure])
+      AC_MSG_NOTICE([*** including --without-asterisk.])
+      exit 1
+   fi
+fi
+
 AC_CONFIG_FILES([build_tools/menuselect-deps makeopts])
 AC_OUTPUT
 
Index: asterisk-ooh323c/Makefile.in
===================================================================
--- asterisk-ooh323c/Makefile.in	(revision 323)
+++ asterisk-ooh323c/Makefile.in	(working copy)
@@ -88,7 +88,7 @@
 am__quote = @am__quote@
 install_sh = @install_sh@
 AUTOMAKE_OPTIONS = gnu
-CFLAGS = @OOH323CFLAGS@
+CFLAGS = $(ASTERISK_INCLUDE) @OOH323CFLAGS@
 lib_LTLIBRARIES = libchan_h323.la
 libchan_h323_la_LDFLAGS = -L$(top_builddir)/ooh323c/src -version-info 1:1:0
 libchan_h323_la_SOURCES = src/chan_h323.h src/chan_h323.c src/ooh323cDriver.h src/ooh323cDriver.c ooh323c/src/ooCmdChannel.h ooh323c/src/ooCmdChannel.c ooh323c/src/ooLogChan.h ooh323c/src/ooLogChan.c ooh323c/src/ooUtils.c ooh323c/src/ooUtils.h ooh323c/src/ooGkClient.h ooh323c/src/ooGkClient.c ooh323c/src/context.c ooh323c/src/ooCommon.h ooh323c/src/ooDateTime.h ooh323c/src/ooDateTime.c ooh323c/src/decode.c ooh323c/src/dlist.c ooh323c/src/encode.c ooh323c/src/errmgmt.c ooh323c/src/memheap.c ooh323c/src/memheap.h ooh323c/src/ooasn1.h  ooh323c/src/ootrace.h ooh323c/src/ootrace.c ooh323c/src/oochannels.c ooh323c/src/oochannels.h ooh323c/src/ooh245.c ooh323c/src/ooh245.h ooh323c/src/oohdr.h ooh323c/src/ooper.h ooh323c/src/ooports.c ooh323c/src/ooports.h ooh323c/src/ooq931.c ooh323c/src/ooq931.h ooh323c/src/ooCapability.c ooh323c/src/ooCapability.h ooh323c/src/ooSocket.c ooh323c/src/ooSocket.h ooh323c/src/ootypes.h ooh323c/src/perutil.c ooh323c/src/eventHandler.c ooh323c/src/eventHandler.h ooh323c/src/ooCalls.c ooh323c/src/ooCalls.h ooh323c/src/ooStackCmds.c ooh323c/src/ooStackCmds.h ooh323c/src/ooh323.c ooh323c/src/ooh323.h ooh323c/src/ooh323ep.c ooh323c/src/ooh323ep.h ooh323c/src/printHandler.c ooh323c/src/printHandler.h ooh323c/src/rtctype.c ooh323c/src/rtctype.h ooh323c/src/ooTimer.c ooh323c/src/ooTimer.h ooh323c/src/h323/H235-SECURITY-MESSAGESDec.c ooh323c/src/h323/H235-SECURITY-MESSAGESEnc.c ooh323c/src/h323/H235-SECURITY-MESSAGES.h ooh323c/src/h323/H323-MESSAGES.c ooh323c/src/h323/H323-MESSAGESDec.c ooh323c/src/h323/H323-MESSAGESEnc.c ooh323c/src/h323/H323-MESSAGES.h ooh323c/src/h323/MULTIMEDIA-SYSTEM-CONTROL.c ooh323c/src/h323/MULTIMEDIA-SYSTEM-CONTROLDec.c ooh323c/src/h323/MULTIMEDIA-SYSTEM-CONTROLEnc.c ooh323c/src/h323/MULTIMEDIA-SYSTEM-CONTROL.h
Index: asterisk-ooh323c/configure.in
===================================================================
--- asterisk-ooh323c/configure.in	(revision 323)
+++ asterisk-ooh323c/configure.in	(working copy)
@@ -34,7 +34,6 @@
 
 dnl not required as using libtool AC_PROG_RANLIB
 AC_HEADER_STDC
-AC_CHECK_FILE(/usr/include/asterisk/channel.h,, AC_MSG_ERROR([No asterisk installation found]))
 AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h netdb.h netinet/in.h stddef.h stdlib.h string.h sys/socket.h unistd.h sys/ioctl.h])
 
 
Index: asterisk-ooh323c/Makefile.am
===================================================================
--- asterisk-ooh323c/Makefile.am	(revision 323)
+++ asterisk-ooh323c/Makefile.am	(working copy)
@@ -1,5 +1,5 @@
 AUTOMAKE_OPTIONS = gnu
-CFLAGS = @OOH323CFLAGS@
+CFLAGS = $(ASTERISK_INCLUDE) @OOH323CFLAGS@
 INSTALLPREFIX=@OOASTINSTALL@
 lib_LTLIBRARIES = libchan_h323.la
 libchan_h323_la_LDFLAGS = -L$(top_builddir)/ooh323c/src -version-info 1:1:0
Index: format_mp3/Makefile
===================================================================
--- format_mp3/Makefile	(revision 323)
+++ format_mp3/Makefile	(working copy)
@@ -1,8 +1,7 @@
-INSTALLTO=$(DESTDIR)/usr/lib/asterisk/modules
 MODS=format_mp3.so
 MP3OBJS=common.o dct64_i386.o decode_ntom.o layer3.o tabinit.o interface.o format_mp3.o
 
-CFLAGS=-pipe -fPIC -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG) $(INCLUDE) -D_REENTRANT -D_GNU_SOURCE #-DMAKE_VALGRIND_HAPPY
+CFLAGS=$(ASTERISK_INCLUDE) -pipe -fPIC -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations $(DEBUG) $(INCLUDE) -D_REENTRANT -D_GNU_SOURCE #-DMAKE_VALGRIND_HAPPY
 
 OSARCH=$(shell uname -s)
 
@@ -72,9 +71,9 @@
 	rm -f *.o *.so *~
 
 install: all
-	/bin/cp -f format_mp3.so $(INSTALLTO)
+	$(INSTALL) -m 755 format_mp3.so $(DESTDIR)$(MODULES_DIR)
 
 autoload: all
 	asterisk -rx "unload format_mp3.so"
-	/bin/cp -f format_mp3.so $(INSTALLTO)
+	$(INSTALL) -m 755 format_mp3.so $(DESTDIR)$(MODULES_DIR)
 	asterisk -rx "load format_mp3.so"
Index: Makefile
===================================================================
--- Makefile	(revision 323)
+++ Makefile	(working copy)
@@ -129,6 +129,8 @@
 include .depend
 endif
 
+CFLAGS+=$(ASTERISK_INCLUDE)
+
 cdr_addon_mysql.o: cdr_addon_mysql.c
 	$(CC) -g -c $(CFLAGS) -o $@ $<
 
