From c5b63ec5af0e742e434c73a9110cb9839925b1c6 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sun, 31 Jan 2010 17:06:24 +0100
Subject: [PATCH] Let configure automatically infer path to installed Dovecot
 and don't rely on installed libtool .la files anymore (patch by Timo
 Sirainen).

---
 configure.in                      | 32 +++++++++++++++----------------
 src/managesieve-login/Makefile.am |  9 +++++----
 src/managesieve/Makefile.am       |  8 +++-----
 src/sieve-tools/Makefile.am       | 13 ++++++-------
 src/testsuite/Makefile.am         |  8 +++-----
 5 files changed, 33 insertions(+), 37 deletions(-)

diff --git a/configure.in b/configure.in
index b3a6a6279..90c0ca77f 100644
--- a/configure.in
+++ b/configure.in
@@ -22,22 +22,8 @@ AC_PROG_LIBTOOL
 
 AC_ARG_WITH(dovecot,
 [AC_HELP_STRING([--with-dovecot=DIR], [Dovecot base directory [../dovecot]])],
-	dovecotdir="$withval",
-	dovecotdir=../dovecot-2.0
+	dovecotdir="$withval"
 )
-old=`pwd`
-cd $dovecotdir
-dovecotdir=`pwd`
-cd $old
-AC_SUBST(dovecotdir)
-
-if ! test -f "$dovecotdir/dovecot-config"; then
-  echo
-  echo "dovecot-config not found from $dovecotdir, use --with-dovecot=PATH"
-  echo "to give path to compiled Dovecot sources or to a directory with the"
-  echo "installed dovecot-config file."
-  AC_MSG_ERROR([dovecot-config not found])
-fi
 
 # Extensions under development
 #
@@ -92,9 +78,19 @@ AC_ARG_WITH(managesieve,
         want_managesieve=yes)
 AM_CONDITIONAL(BUILD_MANAGESIEVE, test "$want_managesieve" = "yes")
 
+if test "$dovecotdir" = ""; then
+  test "x$prefix" = xNONE && prefix=$ac_default_prefix
+  dovecotdir=$prefix/lib/dovecot
+fi
+if ! test -f "$dovecotdir/dovecot-config"; then
+  echo
+  echo "dovecot-config not found from $dovecotdir, use --with-dovecot=PATH"
+  echo "to give path to compiled Dovecot sources or to a directory with the"
+  echo "installed dovecot-config file."
+  AC_MSG_ERROR([dovecot-config not found])
+fi
 eval `cat $dovecotdir/dovecot-config`
 
-AC_SUBST(MODULE_LIBS)
 AC_SUBST(moduledir)
 AC_SUBST(dovecot_pkgincludedir)
 AC_SUBST(dovecot_pkglibexecdir)
@@ -105,6 +101,10 @@ AC_SUBST(LIBDOVECOT)
 AC_SUBST(LIBDOVECOT_STORAGE)
 AC_SUBST(LIBDOVECOT_LOGIN)
 
+AC_SUBST(LIBDOVECOT_DEPS)
+AC_SUBST(LIBDOVECOT_STORAGE_DEPS)
+AC_SUBST(LIBDOVECOT_LOGIN_DEPS)
+
 AC_SUBST(LIBDOVECOT_INCLUDE)
 AC_SUBST(LIBDOVECOT_LDA_INCLUDE)
 AC_SUBST(LIBDOVECOT_SERVICE_INCLUDE)
diff --git a/src/managesieve-login/Makefile.am b/src/managesieve-login/Makefile.am
index 204c9220c..8a60a72f6 100644
--- a/src/managesieve-login/Makefile.am
+++ b/src/managesieve-login/Makefile.am
@@ -17,11 +17,12 @@ settings_LTLIBRARIES = \
 libmanagesieve_login_settings_la_SOURCES = \
 	managesieve-login-settings.c
 
-managesieve_login_LDADD = \
+libs = \
 	managesieve-login-settings.lo \
-	$(top_srcdir)/src/lib-managesieve/libmanagesieve.a \
-	$(LIBDOVECOT_LOGIN) \
-	$(LIBDOVECOT)
+	$(top_srcdir)/src/lib-managesieve/libmanagesieve.a
+
+managesieve_login_LDADD = $(libs) $(LIBDOVECOT_LOGIN) $(LIBDOVECOT)
+managesieve_login_DEPENDENCIES = $(libs) $(LIBDOVECOT_LOGIN_DEPS) $(LIBDOVECOT_DEPS)
 
 managesieve_login_SOURCES = \
 	client.c \
diff --git a/src/managesieve/Makefile.am b/src/managesieve/Makefile.am
index 24ee047dd..aac7c1628 100644
--- a/src/managesieve/Makefile.am
+++ b/src/managesieve/Makefile.am
@@ -25,13 +25,11 @@ libs = \
 	managesieve-settings.lo \
 	$(top_srcdir)/src/lib-managesieve/libmanagesieve.a \
 	$(top_srcdir)/src/lib-sievestorage/libsievestorage.a \
-	$(top_srcdir)/src/lib-sieve/libdovecot-sieve.la \
-	$(LIBDOVECOT_STORAGE) \
-	$(LIBDOVECOT)
+	$(top_srcdir)/src/lib-sieve/libdovecot-sieve.la
 
-managesieve_LDADD = $(libs) $(MODULE_LIBS) 
+managesieve_LDADD = $(libs) $(LIBDOVECOT_STORAGE) $(LIBDOVECOT)
 
-managesieve_DEPENDENCIES = $(libs)
+managesieve_DEPENDENCIES = $(libs) $(LIBDOVECOT_STORAGE_DEPS) $(LIBDOVECOT_DEPS)
 
 cmds = \
 	cmd-capability.c \
diff --git a/src/sieve-tools/Makefile.am b/src/sieve-tools/Makefile.am
index 612a5d4be..e394264b5 100644
--- a/src/sieve-tools/Makefile.am
+++ b/src/sieve-tools/Makefile.am
@@ -17,17 +17,16 @@ AM_CPPFLAGS = \
 libs = \
 	$(top_srcdir)/src/lib-sieve/libdovecot-sieve.la \
 	$(top_srcdir)/src/lib-sieve-tool/libsieve-tool.la \
-	$(LIBDOVECOT_STORAGE) \
-	$(LIBDOVECOT) \
 	./debug/libsieve_ext_debug.la
 
-libs_ldadd = $(libs) $(MODULE_LIBS)
+libs_ldadd = $(libs) $(LIBDOVECOT_STORAGE) $(LIBDOVECOT)
+libs_deps = $(libs) $(LIBDOVECOT_STORAGE_DEPS) $(LIBDOVECOT_DEPS)
 
 # Sieve Compile Tool
 
 sievec_LDFLAGS = -export-dynamic
 sievec_LDADD = $(libs_ldadd)
-sievec_DEPENDENCIES = $(libs)
+sievec_DEPENDENCIES = $(libs_deps)
 
 sievec_SOURCES = \
 	sievec.c 
@@ -36,7 +35,7 @@ sievec_SOURCES = \
 
 sieved_LDFLAGS = -export-dynamic
 sieved_LDADD = $(libs_ldadd)
-sieved_DEPENDENCIES = $(libs)
+sieved_DEPENDENCIES = $(libs_deps)
 
 sieved_SOURCES = \
 	sieved.c 
@@ -45,7 +44,7 @@ sieved_SOURCES = \
 
 sieve_test_LDFLAGS = -export-dynamic
 sieve_test_LDADD = $(libs_ldadd)
-sieve_test_DEPENDENCIES = $(libs)
+sieve_test_DEPENDENCIES = $(libs_deps)
 
 sieve_test_SOURCES = \
 	sieve-test.c 
@@ -56,7 +55,7 @@ sieve_test_SOURCES = \
 
 sieve_filter_LDFLAGS = -export-dynamic
 sieve_filter_LDADD = $(libs_ldadd)
-sieve_filter_DEPENDENCIES = $(libs)
+sieve_filter_DEPENDENCIES = $(libs_deps)
 
 sieve_filter_SOURCES = \
 	sieve-filter.c 
diff --git a/src/testsuite/Makefile.am b/src/testsuite/Makefile.am
index 82b7d7351..605bff4b5 100644
--- a/src/testsuite/Makefile.am
+++ b/src/testsuite/Makefile.am
@@ -11,12 +11,10 @@ testsuite_LDFLAGS = -export-dynamic
 
 libs = \
 	$(top_srcdir)/src/lib-sieve/libdovecot-sieve.la \
-	$(top_srcdir)/src/lib-sieve-tool/libsieve-tool.la \
-	$(LIBDOVECOT_STORAGE) \
-	$(LIBDOVECOT)
+	$(top_srcdir)/src/lib-sieve-tool/libsieve-tool.la
 
-testsuite_LDADD = $(libs) $(MODULE_LIBS)
-testsuite_DEPENDENCIES = $(libs)
+testsuite_LDADD = $(libs) $(LIBDOVECOT_STORAGE) $(LIBDOVECOT)
+testsuite_DEPENDENCIES = $(libs) $(LIBDOVECOT_STORAGE_DEPS) $(LIBDOVECOT_DEPS)
 
 commands = \
 	cmd-test.c \
-- 
GitLab