HTRACE-219. Add -Dleveldb.prefix and -Djsonc.prefix build options (cmccabe)

(cherry picked from commit a7cea5b5c8a1a262e16da276750436e518cc7da9)
diff --git a/htrace-c/pom.xml b/htrace-c/pom.xml
index 6efe766..1254acd 100644
--- a/htrace-c/pom.xml
+++ b/htrace-c/pom.xml
@@ -33,6 +33,7 @@
 
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <jsonc.prefix></jsonc.prefix>
   </properties>
 
   <profiles>
@@ -77,7 +78,7 @@
                   <target>
                     <mkdir dir="${project.build.directory}/build"/>
                     <exec executable="cmake" dir="${project.build.directory}/build" failonerror="true">
-                      <arg line="${basedir}/src -DCMAKE_INSTALL_PREFIX=${project.build.directory}/install"/>
+                      <arg line="${basedir}/src -DCMAKE_INSTALL_PREFIX=${project.build.directory}/install -DJSON_C_PREFIX=${jsonc.prefix}"/>
                     </exec>
                     <exec executable="make" dir="${project.build.directory}/build" failonerror="true">
                       <arg line="install VERBOSE=1"/>
diff --git a/htrace-c/src/CMakeLists.txt b/htrace-c/src/CMakeLists.txt
index 986d865..24c042f 100644
--- a/htrace-c/src/CMakeLists.txt
+++ b/htrace-c/src/CMakeLists.txt
@@ -51,9 +51,9 @@
 find_package(PkgConfig)
 pkg_check_modules(PC_JSON-C QUIET json-c)
 find_path(JSON_C_INCLUDE_DIR "json.h"
-    HINTS ${PC_JSON-C_INCLUDEDIR} ${PC_JSON-C_INCLUDE_DIRS} PATH_SUFFIXES json-c json)
+    HINTS ${JSON_C_PREFIX} ${PC_JSON-C_INCLUDEDIR} ${PC_JSON-C_INCLUDE_DIRS} PATH_SUFFIXES json-c json)
 find_library(JSON_C_LIBRARY NAMES json-c json libjson
-    HINTS ${PC_JSON-C_LIBDIR} ${PC_JSON-C_LIBRARY_DIRS})
+    HINTS ${JSON_C_PREFIX}${PC_JSON-C_LIBDIR} ${PC_JSON-C_LIBRARY_DIRS})
 IF(JSON_C_INCLUDE_DIR AND JSON_C_LIBRARY)
 ELSE(JSON_C_INCLUDE_DIR AND JSON_C_LIBRARY)
     MESSAGE(FATAL_ERROR "Failed to find libjson-c. Try installing libjson-c with apt-get or yum, or install it manually from http://oss.metaparadigm.com/json-c/")
diff --git a/htrace-htraced/go/gobuild.sh b/htrace-htraced/go/gobuild.sh
index 121d55b..ae4b67b 100755
--- a/htrace-htraced/go/gobuild.sh
+++ b/htrace-htraced/go/gobuild.sh
@@ -66,19 +66,25 @@
 fi
 
 # Check for libleveldb.so
-if [ -x "/sbin/ldconfig" ]; then
-    # Suse requires ldconfig to be run via the absolute path
-    ldconfig=/sbin/ldconfig
+if [ -n "$LEVELDB_PREFIX" ]; then
+    echo "using LEVELDB_PREFIX=$LEVELDB_PREFIX"
+    export CGO_CFLAGS="-I${LEVELDB_PREFIX}/include"
+    export CGO_LDFLAGS="-L${LEVELDB_PREFIX}"
 else
-    which ldconfig &> /dev/null
-    [ $? -eq 0 ] && ldconfig=ldconfig
-fi
-if [ -n "${ldconfig}" ]; then
-    if "${ldconfig}" -p | grep -q libleveldb; then
-        :
+    if [ -x "/sbin/ldconfig" ]; then
+        # Suse requires ldconfig to be run via the absolute path
+        ldconfig=/sbin/ldconfig
     else
-        echo "You must install the leveldb-devel package (or distro-specific equivalent.)"
-        exit 1
+        which ldconfig &> /dev/null
+        [ $? -eq 0 ] && ldconfig=ldconfig
+    fi
+    if [ -n "${ldconfig}" ]; then
+        if "${ldconfig}" -p | grep -q libleveldb; then
+            :
+        else
+            echo "You must install the leveldb-devel package (or distro-specific equivalent.)"
+            exit 1
+        fi
     fi
 fi
 
diff --git a/htrace-htraced/pom.xml b/htrace-htraced/pom.xml
index d775850..48d702a 100644
--- a/htrace-htraced/pom.xml
+++ b/htrace-htraced/pom.xml
@@ -28,8 +28,8 @@
 
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <leveldb.prefix></leveldb.prefix>
   </properties>
-
   <build>
     <plugins>
       <plugin>
@@ -113,6 +113,7 @@
                       dir="${basedir}//go/"
                       failonerror="true">
                   <env key="RELEASE_VERSION" value="${project.version}"/>
+                  <env key="LEVELDB_PREFIX" value="${leveldb.prefix}"/>
                 </exec>
               </tasks>
             </configuration>