From 742fa9e316a10403ba7321596cc58eac63867f13 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Mon, 20 Apr 2015 10:55:17 -0700 Subject: [PATCH] Fix compile with two gflags Summary: If the system has gflags with both `google` and `gflags` namespaces installed, we try to define GFLAGS as two things. This breaks the compile. Fix: Use `else if` -- try compiling with `google` namespace only if compile with `gflags` failed Test Plan: build_tools/build_detect_platform correctly identifies gflags Reviewers: lgalanis Reviewed By: lgalanis Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D37389 --- build_tools/build_detect_platform | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/build_tools/build_detect_platform b/build_tools/build_detect_platform index 8b12f3ba0..2ecf07aca 100755 --- a/build_tools/build_detect_platform +++ b/build_tools/build_detect_platform @@ -200,29 +200,19 @@ EOF JAVA_LDFLAGS="$JAVA_LDFLAGS -lsnappy" fi - # Test whether gflags library is installed # http://code.google.com/p/gflags/ # check if the namespace is gflags - $CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null < - using namespace gflags; - int main() {} -EOF - if [ "$?" = 0 ]; then + if echo "#include \nusing namespace gflags;\nint main() {}" | \ + $CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null; then COMMON_FLAGS="$COMMON_FLAGS -DGFLAGS=gflags" PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lgflags" - fi - - # check if namespace is google - $CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null < - using namespace google; - int main() {} -EOF - if [ "$?" = 0 ]; then - COMMON_FLAGS="$COMMON_FLAGS -DGFLAGS=google" - PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lgflags" + else + if echo "#include \nusing namespace google;\nint main() {}" | \ + $CXX $CFLAGS -x c++ - -o /dev/null ; then + COMMON_FLAGS="$COMMON_FLAGS -DGFLAGS=google" + PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lgflags" + fi fi # Test whether zlib library is installed