>From 8bbb7a71be6baf19fc03b4ff0dbc5c0842255e1b Mon Sep 17 00:00:00 2001
From: Mathias Hasselmann <mathias.hasselmann@gmx.de>
Date: Tue, 27 Nov 2007 10:25:47 +0100
Subject: [PATCH] Update the build system to provide Avahi support.

* configure.in: Add --with-avahi switch. Check for avahi-client pkg-config
* package. Add AVAHI_CFLAGS, AVAHI_LIBS variables. Add USE_AVAHI guard.
* src/Makefile.global.in: Add AVAHI_CFLAGS, AVAHI_LIBS variables.
* src/backend/Makefile: Add AVAHI_CFLAGS and AVAHI_LIBS to CFLAGS and LIBS.
* src/include/pg_config.h.in: Add USE_AVAHI guard.

Signed-off-by: Mathias Hasselmann <mathias@openismus.com>
---
 configure.in               |   18 +++++++++++++++++-
 src/Makefile.global.in     |    2 ++
 src/backend/Makefile       |    3 +++
 src/include/pg_config.h.in |    3 +++
 4 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/configure.in b/configure.in
index 9858852..abec4ad 100644
--- a/configure.in
+++ b/configure.in
@@ -523,6 +523,17 @@ AC_SUBST(with_ldap)
 
 
 #
+# Avahi
+#
+AC_MSG_CHECKING([whether to build with Avahi support])
+PGAC_ARG_BOOL(with, avahi, no,
+              [  --with-avahi            build with Avahi support],
+              [AC_DEFINE([USE_AVAHI], 1, [Define to 1 to build with Avahi support. (--with-avahi)])])
+AC_MSG_RESULT([$with_avahi])
+AC_SUBST(with_avahi)
+
+
+#
 # Bonjour
 #
 AC_MSG_CHECKING([whether to build with Bonjour support])
@@ -905,8 +916,13 @@ if test "$with_ldap" = yes ; then
   fi
 fi
 
+if test "$with_avahi" = yes ; then
+  PKG_CHECK_MODULES([AVAHI], [avahi-client >= 0.6.10])
+fi
+
 if test "$with_bonjour" = yes ; then
-  AC_CHECK_HEADER(DNSServiceDiscovery/DNSServiceDiscovery.h, [], [AC_MSG_ERROR([header file <DNSServiceDiscovery/DNSServiceDiscovery.h> is required for Bonjour])])
+  AC_CHECK_HEADER(DNSServiceDiscovery/DNSServiceDiscovery.h, [],
+                  [AC_MSG_ERROR([header file <DNSServiceDiscovery/DNSServiceDiscovery.h> is required for Bonjour])])
 fi
 
 # for contrib/uuid-ossp
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index aa41ee9..2eb7756 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -191,6 +191,8 @@ have_docbook	= @have_docbook@
 DOCBOOKSTYLE	= @DOCBOOKSTYLE@
 COLLATEINDEX	= @COLLATEINDEX@
 
+AVAHI_CFLAGS		= @AVAHI_CFLAGS@
+AVAHI_LIBS		= @AVAHI_LIBS@
 
 ##########################################################################
 #
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 9d2dbe6..3dbdd71 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -32,6 +32,9 @@ LIBS := $(filter-out -lpgport, $(LIBS)) $(LDAP_LIBS_BE)
 # The backend doesn't need everything that's in LIBS, however
 LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS))
 
+CFLAGS += $(AVAHI_CFLAGS)
+LIBS += $(AVAHI_LIBS)
+
 ##########################################################################
 
 all: submake-libpgport postgres $(POSTGRES_IMP)
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index e147e86..e1b5b95 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -659,6 +659,9 @@
 /* Define to 1 to build with assertion checks. (--enable-cassert) */
 #undef USE_ASSERT_CHECKING
 
+/* Define to 1 to build with Avahi support. (--with-avahi) */
+#undef USE_AVAHI
+
 /* Define to 1 to build with Bonjour support. (--with-bonjour) */
 #undef USE_BONJOUR
 
-- 
1.5.2.5

