Thrift-1715: Allow excluding libraries in fb303 configure
Client: fb303
Patch: Harsh J

Updated patch to allow for excluding all avaliable lang libraries using the
--without-<lib> configure flag. Configure output added to notify user of
result

Building C++ Library ......... : yes
Building Java Library ........ : yes
Building Python Library ...... : yes
Building PHP Library ......... : yes
diff --git a/contrib/fb303/Makefile.am b/contrib/fb303/Makefile.am
index de7fbb6..e773e52 100644
--- a/contrib/fb303/Makefile.am
+++ b/contrib/fb303/Makefile.am
@@ -21,11 +21,26 @@
 
 @PRODUCT_MK@
 
-SUBDIRS = . cpp py
+SUBDIRS = .
+
+if WITH_CPP
+SUBDIRS += cpp
+endif
+
+if WITH_JAVA
+SUBDIRS += java
+endif
+
+if WITH_PHP
+SUBDIRS += php
+endif
+
+if WITH_PYTHON
+SUBDIRS += py
+endif
 
 BUILT_SOURCES =
 
-
 clean-local: clean-common
 
 @GLOBAL_FOOTER_MK@
diff --git a/contrib/fb303/aclocal/ax_javac_and_java.m4 b/contrib/fb303/aclocal/ax_javac_and_java.m4
new file mode 100644
index 0000000..fdb4bf0
--- /dev/null
+++ b/contrib/fb303/aclocal/ax_javac_and_java.m4
@@ -0,0 +1,121 @@
+dnl @synopsis AX_JAVAC_AND_JAVA
+dnl @synopsis AX_CHECK_JAVA_CLASS(CLASSNAME)
+dnl
+dnl Test for the presence of a JDK, and (optionally) specific classes.
+dnl
+dnl If "JAVA" is defined in the environment, that will be the only
+dnl java command tested.  Otherwise, a hard-coded list will be used.
+dnl Similarly for "JAVAC".
+dnl
+dnl AX_JAVAC_AND_JAVA does not currenly support testing for a particular
+dnl Java version, testing for only one of "java" and "javac", or
+dnl compiling or running user-provided Java code.
+dnl
+dnl After AX_JAVAC_AND_JAVA runs, the shell variables "success" and
+dnl "ax_javac_and_java" are set to "yes" or "no", and "JAVAC" and
+dnl "JAVA" are set to the appropriate commands.
+dnl
+dnl AX_CHECK_JAVA_CLASS must be run after AX_JAVAC_AND_JAVA.
+dnl It tests for the presence of a class based on a fully-qualified name.
+dnl It sets the shell variable "success" to "yes" or "no".
+dnl
+dnl @category Java
+dnl @version 2009-02-09
+dnl @license AllPermissive
+dnl
+dnl Copyright (C) 2009 David Reiss
+dnl Copying and distribution of this file, with or without modification,
+dnl are permitted in any medium without royalty provided the copyright
+dnl notice and this notice are preserved.
+
+
+AC_DEFUN([AX_JAVAC_AND_JAVA],
+         [
+
+          dnl Hard-coded default commands to test.
+          JAVAC_PROGS="javac,jikes,gcj -C"
+          JAVA_PROGS="java,kaffe"
+
+          dnl Allow the user to specify an alternative.
+          if test -n "$JAVAC" ; then
+            JAVAC_PROGS="$JAVAC"
+          fi
+          if test -n "$JAVA" ; then
+            JAVA_PROGS="$JAVA"
+          fi
+
+          AC_MSG_CHECKING(for javac and java)
+
+          echo "public class configtest_ax_javac_and_java { public static void main(String args@<:@@:>@) { } }" > configtest_ax_javac_and_java.java
+          success=no
+          oIFS="$IFS"
+
+          IFS=","
+          for JAVAC in $JAVAC_PROGS ; do
+            IFS="$oIFS"
+
+            echo "Running \"$JAVAC configtest_ax_javac_and_java.java\"" >&AS_MESSAGE_LOG_FD
+            if $JAVAC configtest_ax_javac_and_java.java >&AS_MESSAGE_LOG_FD 2>&1 ; then
+
+              IFS=","
+              for JAVA in $JAVA_PROGS ; do
+                IFS="$oIFS"
+
+                echo "Running \"$JAVA configtest_ax_javac_and_java\"" >&AS_MESSAGE_LOG_FD
+                if $JAVA configtest_ax_javac_and_java >&AS_MESSAGE_LOG_FD 2>&1 ; then
+                  success=yes
+                  break 2
+                fi
+
+              done
+
+            fi
+
+          done
+
+          rm -f configtest_ax_javac_and_java.java configtest_ax_javac_and_java.class
+
+          if test "$success" != "yes" ; then
+            AC_MSG_RESULT(no)
+            JAVAC=""
+            JAVA=""
+          else
+            AC_MSG_RESULT(yes)
+          fi
+
+          ax_javac_and_java="$success"
+
+          ])
+
+
+AC_DEFUN([AX_CHECK_JAVA_CLASS],
+         [
+          AC_MSG_CHECKING(for Java class [$1])
+
+          echo "import $1; public class configtest_ax_javac_and_java { public static void main(String args@<:@@:>@) { } }" > configtest_ax_javac_and_java.java
+
+          echo "Running \"$JAVAC configtest_ax_javac_and_java.java\"" >&AS_MESSAGE_LOG_FD
+          if $JAVAC configtest_ax_javac_and_java.java >&AS_MESSAGE_LOG_FD 2>&1 ; then
+            AC_MSG_RESULT(yes)
+            success=yes
+          else
+            AC_MSG_RESULT(no)
+            success=no
+          fi
+
+          rm -f configtest_ax_javac_and_java.java configtest_ax_javac_and_java.class
+          ])
+
+
+AC_DEFUN([AX_CHECK_ANT_VERSION],
+         [
+          AC_MSG_CHECKING(for ant version > $2)
+          ANT_VALID=`expr $($1 -version 2>/dev/null | sed -n 's/.*version \(@<:@0-9\.@:>@*\).*/\1/p') \>= $2`
+          if test "x$ANT_VALID" = "x1" ; then
+            AC_MSG_RESULT(yes)
+          else
+            AC_MSG_RESULT(no)
+            ANT=""
+          fi
+          ])
+
diff --git a/contrib/fb303/aclocal/ax_thrift_internal.m4 b/contrib/fb303/aclocal/ax_thrift_internal.m4
new file mode 100644
index 0000000..8c0e3cb
--- /dev/null
+++ b/contrib/fb303/aclocal/ax_thrift_internal.m4
@@ -0,0 +1,28 @@
+dnl @synopsis AX_THRIFT_GEN(SHORT_LANGUAGE, LONG_LANGUAGE, DEFAULT)
+dnl @synopsis AX_THRIFT_LIB(SHORT_LANGUAGE, LONG_LANGUAGE, DEFAULT)
+dnl
+dnl Allow a particular language generator to be disabled.
+dnl Allow a particular language library to be disabled.
+dnl
+dnl These macros have poor error handling and are poorly documented.
+dnl They are intended only for internal use by the Thrift compiler.
+dnl
+dnl @version 2008-02-20
+dnl @license AllPermissive
+dnl
+dnl Copyright (C) 2009 David Reiss
+dnl Copying and distribution of this file, with or without modification,
+dnl are permitted in any medium without royalty provided the copyright
+dnl notice and this notice are preserved.
+
+AC_DEFUN([AX_THRIFT_LIB],
+         [
+          AC_ARG_WITH($1,
+                      AC_HELP_STRING([--with-$1], [build the $2 library @<:@default=$3@:>@]),
+                      [with_$1="$withval"],
+                      [with_$1=$3]
+                      )
+          have_$1=no
+          dnl What we do here is going to vary from library to library,
+          dnl so we can't really generalize (yet!).
+         ])
diff --git a/contrib/fb303/configure.ac b/contrib/fb303/configure.ac
index c94e252..5b99f2a 100644
--- a/contrib/fb303/configure.ac
+++ b/contrib/fb303/configure.ac
@@ -71,8 +71,47 @@
 # Example: sets $(thrift_home) variable with default path set to /usr/local.
 FB_WITH_PATH([thrift_home], [thriftpath], [/usr/local])
 
-# Require boost 1.33.1 or later
-AX_BOOST_BASE([1.33.1])
+AX_THRIFT_LIB(cpp, [C++], yes)
+have_cpp=no
+if test "$with_cpp" = "yes"; then
+  # Require boost 1.40.0 or later
+  AX_BOOST_BASE([1.40.0])
+  if test "x$succeeded" = "xyes"; then
+    have_cpp="yes"
+  fi
+fi
+AM_CONDITIONAL([WITH_CPP], [test "$have_cpp" = "yes"])
+
+AX_THRIFT_LIB(java, [Java], yes)
+if test "$with_java" = "yes"; then
+  AX_JAVAC_AND_JAVA
+  AC_PATH_PROG([ANT], [ant])
+  AX_CHECK_ANT_VERSION($ANT, 1.7)
+  AC_SUBST(CLASSPATH)
+  AC_SUBST(ANT_FLAGS)
+  if test "x$JAVAC" != "x" && test "x$JAVAC" != "x" && test "x$ANT" != "x" ; then
+    have_java="yes"
+  fi
+fi
+AM_CONDITIONAL(WITH_JAVA, [test "$have_java" = "yes"])
+
+AX_THRIFT_LIB(php, [PHP], yes)
+if test "$with_php" = "yes"; then
+  AC_PATH_PROG([PHP], [php])
+  if test "x$PHP" != "x" && test "x$PHP" != "x:" ; then
+    have_php="yes"
+  fi
+fi
+AM_CONDITIONAL(WITH_PHP, [test "$have_php" = "yes"])
+
+AX_THRIFT_LIB(python, [Python], yes)
+if test "$with_python" = "yes"; then
+  AM_PATH_PYTHON(2.4,, :)
+  if test "x$PYTHON" != "x" && test "x$PYTHON" != "x:" ; then
+    have_python="yes"
+  fi
+fi
+AM_CONDITIONAL(WITH_PYTHON, [test "$have_python" = "yes"])
 
 # Generates Makefile from Makefile.am. Modify when new subdirs are added.
 # Change Makefile.am also to add subdirectly.
@@ -92,6 +131,11 @@
 ######### FINISH ############################################################
 
 echo "EXTERNAL_PATH $EXTERNAL_PATH"
+echo
+echo "Building C++ Library ......... : $have_cpp"
+echo "Building Java Library ........ : $have_java"
+echo "Building Python Library ...... : $have_python"
+echo "Building PHP Library ......... : $have_php"
 
 
 #