From cad043a68c7be1d1e6c61ce2864787830a3edf9b Mon Sep 17 00:00:00 2001
From: Vittorio Giovara <vittorio.giovara@savoirfairelinux.com>
Date: Fri, 2 May 2014 19:56:27 -0400
Subject: [PATCH] build: hook the contrib system in the build process

Refs: #46617

Change-Id: Ic5c00616d091885410e21cd56168e02890f8df8d
---
 daemon/Makefile.am  |  4 ++-
 daemon/configure.ac | 65 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index 1d955f9fd8..a0b9ec0967 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -25,7 +25,9 @@ EXTRA_DIST = m4/libtool.m4 \
 			 m4/lt~obsolete.m4 \
 			 m4/ltoptions.m4 \
 			 m4/ltsugar.m4 \
-			 m4/ltversion.m4
+			 m4/ltversion.m4 \
+			 ../contrib/bootstrap \
+			 ../contrib/src
 
 coverage:
 	$(AM_V_at)lcov --directory $(top_builddir) --capture --output-file sflphone-coverage.info
diff --git a/daemon/configure.ac b/daemon/configure.ac
index 6ec0fb5486..30d4abd004 100644
--- a/daemon/configure.ac
+++ b/daemon/configure.ac
@@ -73,6 +73,71 @@ AC_COMPILE_IFELSE(
 
 AC_MSG_RESULT([$CLANG])
 
+
+dnl
+dnl  Check for the contrib directory
+dnl
+AC_ARG_WITH(contrib,
+  [AS_HELP_STRING([--with-contrib[=DIR]],
+    [search for 3rd party libraries in DIR/include and DIR/lib])
+])
+AC_MSG_CHECKING([for 3rd party libraries path])
+AS_IF([test -z "${with_contrib}" || test "${with_contrib}" = "yes"], [
+  CONTRIB_DIR="${srcdir}/../contrib/${host}"
+  AS_IF([test ! -d "${CONTRIB_DIR}"], [
+    echo "${CONTRIB_DIR} not found" >&AS_MESSAGE_LOG_FD
+    CONTRIB_DIR="${srcdir}/../contrib/`$CC -dumpmachine`"
+    AS_IF([test ! -d "${CONTRIB_DIR}"], [
+      echo "${CONTRIB_DIR} not found" >&AS_MESSAGE_LOG_FD
+      CONTRIB_DIR=""
+      AC_MSG_RESULT([not found])
+    ])
+  ])
+], [
+  AS_IF([test "${with_contrib}" != "no"], [
+    CONTRIB_DIR="${with_contrib}"
+  ], [
+    CONTRIB_DIR=""
+    AC_MSG_RESULT([disabled])
+  ])
+])
+
+AS_IF([test -n "${CONTRIB_DIR}"], [
+  AS_IF([test -d "${CONTRIB_DIR}/lib"],[
+    CONTRIB_DIR=`cd "${CONTRIB_DIR}" && pwd`
+  ], [
+    echo "${CONTRIB_DIR}/lib not found" >&AS_MESSAGE_LOG_FD
+    CONTRIB_DIR=""
+    AC_MSG_RESULT([not usable])
+  ])
+])
+
+AS_IF([test -n "${CONTRIB_DIR}"], [
+  AC_MSG_RESULT([${CONTRIB_DIR}])
+  export PATH=${CONTRIB_DIR}/bin:$PATH
+  CPPFLAGS="${CPPFLAGS} -I${CONTRIB_DIR}/include"
+  CFLAGS="${CFLAGS} -I${CONTRIB_DIR}/include"
+  CXXFLAGS="${CXXFLAGS} -I${CONTRIB_DIR}/include"
+  OBJCFLAGS="${OBJCFLAGS} -I${CONTRIB_DIR}/include"
+  export PKG_CONFIG_PATH="${CONTRIB_DIR}/lib/pkgconfig:$PKG_CONFIG_PATH"
+  LDFLAGS="${LDFLAGS} -L${CONTRIB_DIR}/lib"
+
+  AS_IF([test "${SYS}" = "darwin"], [
+    export LD_LIBRARY_PATH="${CONTRIB_DIR}/lib:$LD_LIBRARY_PATH"
+    export DYLD_LIBRARY_PATH="${CONTRIB_DIR}/lib:$DYLD_LIBRARY_PATH"
+  ])
+], [
+  AS_IF([test -n "${with_contrib}" && test "${with_contrib}" != "no"], [
+    AC_MSG_ERROR([Third party libraries not found!])
+  ])
+])
+AC_SUBST(CONTRIB_DIR)
+
+dnl Check for uuid development package - name: uuid-dev
+UUID_MIN_VERSION=1.0
+PKG_CHECK_MODULES(UUID, uuid >= ${UUID_MIN_VERSION}, HAVE_UUID=true, HAVE_UUID=false);
+
+
 AC_SEARCH_LIBS([yaml_parser_initialize], [yaml], [AC_SUBST(YAML_LIBS, -lyaml)], [
        AC_MSG_ERROR([Unable to find yaml development files])])
 
-- 
GitLab