From 0dbaee6c927ee5cd7044ee31634651d7e69208b7 Mon Sep 17 00:00:00 2001
From: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
Date: Tue, 18 Nov 2014 14:40:10 -0500
Subject: [PATCH] dbus: don't mess with DBus service paths

Refs #60503

Change-Id: Id92ab9bd40508e3aa97f4129090961491ea845ed
---
 daemon/bin/dbus/Makefile.am                   | 10 +----
 .../bin/dbus/org.sflphone.SFLphone.service.in |  2 +-
 daemon/configure.ac                           |  7 ++-
 daemon/m4/as-ac-expand.m4                     | 43 +++++++++++++++++++
 4 files changed, 52 insertions(+), 10 deletions(-)
 create mode 100644 daemon/m4/as-ac-expand.m4

diff --git a/daemon/bin/dbus/Makefile.am b/daemon/bin/dbus/Makefile.am
index cd7e98575f..dab26e4043 100644
--- a/daemon/bin/dbus/Makefile.am
+++ b/daemon/bin/dbus/Makefile.am
@@ -59,15 +59,9 @@ libclient_dbus_la_CXXFLAGS = -I../ \
 
 # Dbus service file
 servicedir = $(datadir)/dbus-1/services
-service_in_files = org.sflphone.SFLphone.service.in
-service_DATA = $(service_in_files:.service.in=.service)
+service_DATA = org.sflphone.SFLphone.service
 
-# Rule to make the service file with bindir expanded
-$(service_DATA): $(service_in_files) Makefile
-	sed -e "s|libexec|$(libdir)/sflphone|" $<> $@
-
-EXTRA_DIST = $(service_in_files) \
-			 callmanager-introspec.xml \
+EXTRA_DIST = callmanager-introspec.xml \
 			 configurationmanager-introspec.xml \
 			 instance-introspec.xml
 
diff --git a/daemon/bin/dbus/org.sflphone.SFLphone.service.in b/daemon/bin/dbus/org.sflphone.SFLphone.service.in
index b319dd2201..f0d9f4c21d 100644
--- a/daemon/bin/dbus/org.sflphone.SFLphone.service.in
+++ b/daemon/bin/dbus/org.sflphone.SFLphone.service.in
@@ -1,3 +1,3 @@
 [D-BUS Service]
 Name=org.sflphone.SFLphone
-Exec=libexec/sflphoned
+Exec=@LIBEXECDIR@/sflphoned
diff --git a/daemon/configure.ac b/daemon/configure.ac
index d1d39abc33..601cdfb191 100644
--- a/daemon/configure.ac
+++ b/daemon/configure.ac
@@ -318,7 +318,12 @@ AC_ARG_WITH([dbus],
     [with_dbus=yes])
 AS_IF([test "x$with_dbus" = "xyes"], [
        PKG_CHECK_MODULES(DBUSCPP, dbus-c++-1,, AC_MSG_WARN([Missing dbus development files]))
-       AC_CONFIG_FILES([bin/dbus/Makefile])
+
+       AS_AC_EXPAND(LIBEXECDIR, $libexecdir)
+       AC_SUBST(LIBEXECDIR)
+
+       AC_CONFIG_FILES([bin/dbus/Makefile
+                        bin/dbus/org.sflphone.SFLphone.service])
 
        AC_CHECK_PROG(HAVE_DBUSXML2CPP, dbusxx-xml2cpp, true, false)
        if test "x$HAVE_DBUSXML2CPP" = "xfalse"; then
diff --git a/daemon/m4/as-ac-expand.m4 b/daemon/m4/as-ac-expand.m4
new file mode 100644
index 0000000000..d6c9e33060
--- /dev/null
+++ b/daemon/m4/as-ac-expand.m4
@@ -0,0 +1,43 @@
+dnl as-ac-expand.m4 0.2.0
+dnl autostars m4 macro for expanding directories using configure's prefix
+dnl thomas@apestaart.org
+
+dnl AS_AC_EXPAND(VAR, CONFIGURE_VAR)
+dnl example
+dnl AS_AC_EXPAND(SYSCONFDIR, $sysconfdir)
+dnl will set SYSCONFDIR to /usr/local/etc if prefix=/usr/local
+
+AC_DEFUN([AS_AC_EXPAND],
+[
+  EXP_VAR=[$1]
+  FROM_VAR=[$2]
+
+  dnl first expand prefix and exec_prefix if necessary
+  prefix_save=$prefix
+  exec_prefix_save=$exec_prefix
+
+  dnl if no prefix given, then use /usr/local, the default prefix
+  if test "x$prefix" = "xNONE"; then
+    prefix="$ac_default_prefix"
+  fi
+  dnl if no exec_prefix given, then use prefix
+  if test "x$exec_prefix" = "xNONE"; then
+    exec_prefix=$prefix
+  fi
+
+  full_var="$FROM_VAR"
+  dnl loop until it doesn't change anymore
+  while true; do
+    new_full_var="`eval echo $full_var`"
+    if test "x$new_full_var" = "x$full_var"; then break; fi
+    full_var=$new_full_var
+  done
+
+  dnl clean up
+  full_var=$new_full_var
+  AC_SUBST([$1], "$full_var")
+
+  dnl restore prefix and exec_prefix
+  prefix=$prefix_save
+  exec_prefix=$exec_prefix_save
+])
-- 
GitLab