155e0765ngie#!/bin/sh
255e0765ngie
355e0765ngie# These variables are automatically filled in by the configure script.
455e0765ngiename="@PACKAGE_TARNAME@"
555e0765ngieversion="@PACKAGE_VERSION@"
655e0765ngie
755e0765ngieshow_usage()
855e0765ngie{
955e0765ngie  echo "Usage: gtest-config [OPTIONS...]"
1055e0765ngie}
1155e0765ngie
1255e0765ngieshow_help()
1355e0765ngie{
1455e0765ngie  show_usage
1555e0765ngie  cat <<\EOF
1655e0765ngie
1755e0765ngieThe `gtest-config' script provides access to the necessary compile and linking
1855e0765ngieflags to connect with Google C++ Testing Framework, both in a build prior to
1955e0765ngieinstallation, and on the system proper after installation. The installation
2055e0765ngieoverrides may be issued in combination with any other queries, but will only
2155e0765ngieaffect installation queries if called on a built but not installed gtest. The
2255e0765ngieinstallation queries may not be issued with any other types of queries, and
2355e0765ngieonly one installation query may be made at a time. The version queries and
2455e0765ngiecompiler flag queries may be combined as desired but not mixed. Different
2555e0765ngieversion queries are always combined with logical "and" semantics, and only the
2655e0765ngielast of any particular query is used while all previous ones ignored. All
2755e0765ngieversions must be specified as a sequence of numbers separated by periods.
2855e0765ngieCompiler flag queries output the union of the sets of flags when combined.
2955e0765ngie
3055e0765ngie Examples:
3155e0765ngie  gtest-config --min-version=1.0 || echo "Insufficient Google Test version."
3255e0765ngie
3355e0765ngie  g++ $(gtest-config --cppflags --cxxflags) -o foo.o -c foo.cpp
3455e0765ngie  g++ $(gtest-config --ldflags --libs) -o foo foo.o
3555e0765ngie
3655e0765ngie  # When using a built but not installed Google Test:
3755e0765ngie  g++ $(../../my_gtest_build/scripts/gtest-config ...) ...
3855e0765ngie
3955e0765ngie  # When using an installed Google Test, but with installation overrides:
4055e0765ngie  export GTEST_PREFIX="/opt"
4155e0765ngie  g++ $(gtest-config --libdir="/opt/lib64" ...) ...
4255e0765ngie
4355e0765ngie Help:
4455e0765ngie  --usage                    brief usage information
4555e0765ngie  --help                     display this help message
4655e0765ngie
4755e0765ngie Installation Overrides:
4855e0765ngie  --prefix=<dir>             overrides the installation prefix
4955e0765ngie  --exec-prefix=<dir>        overrides the executable installation prefix
5055e0765ngie  --libdir=<dir>             overrides the library installation prefix
5155e0765ngie  --includedir=<dir>         overrides the header file installation prefix
5255e0765ngie
5355e0765ngie Installation Queries:
5455e0765ngie  --prefix                   installation prefix
5555e0765ngie  --exec-prefix              executable installation prefix
5655e0765ngie  --libdir                   library installation directory
5755e0765ngie  --includedir               header file installation directory
5855e0765ngie  --version                  the version of the Google Test installation
5955e0765ngie
6055e0765ngie Version Queries:
6155e0765ngie  --min-version=VERSION      return 0 if the version is at least VERSION
6255e0765ngie  --exact-version=VERSION    return 0 if the version is exactly VERSION
6355e0765ngie  --max-version=VERSION      return 0 if the version is at most VERSION
6455e0765ngie
6555e0765ngie Compilation Flag Queries:
6655e0765ngie  --cppflags                 compile flags specific to the C-like preprocessors
6755e0765ngie  --cxxflags                 compile flags appropriate for C++ programs
6855e0765ngie  --ldflags                  linker flags
6955e0765ngie  --libs                     libraries for linking
7055e0765ngie
7155e0765ngieEOF
7255e0765ngie}
7355e0765ngie
7455e0765ngie# This function bounds our version with a min and a max. It uses some clever
7555e0765ngie# POSIX-compliant variable expansion to portably do all the work in the shell
7655e0765ngie# and avoid any dependency on a particular "sed" or "awk" implementation.
7755e0765ngie# Notable is that it will only ever compare the first 3 components of versions.
7855e0765ngie# Further components will be cleanly stripped off. All versions must be
7955e0765ngie# unadorned, so "v1.0" will *not* work. The minimum version must be in $1, and
8055e0765ngie# the max in $2. TODO(chandlerc@google.com): If this ever breaks, we should
8155e0765ngie# investigate expanding this via autom4te from AS_VERSION_COMPARE rather than
8255e0765ngie# continuing to maintain our own shell version.
8355e0765ngiecheck_versions()
8455e0765ngie{
8555e0765ngie  major_version=${version%%.*}
8655e0765ngie  minor_version="0"
8755e0765ngie  point_version="0"
8855e0765ngie  if test "${version#*.}" != "${version}"; then
8955e0765ngie    minor_version=${version#*.}
9055e0765ngie    minor_version=${minor_version%%.*}
9155e0765ngie  fi
9255e0765ngie  if test "${version#*.*.}" != "${version}"; then
9355e0765ngie    point_version=${version#*.*.}
9455e0765ngie    point_version=${point_version%%.*}
9555e0765ngie  fi
9655e0765ngie
9755e0765ngie  min_version="$1"
9855e0765ngie  min_major_version=${min_version%%.*}
9955e0765ngie  min_minor_version="0"
10055e0765ngie  min_point_version="0"
10155e0765ngie  if test "${min_version#*.}" != "${min_version}"; then
10255e0765ngie    min_minor_version=${min_version#*.}
10355e0765ngie    min_minor_version=${min_minor_version%%.*}
10455e0765ngie  fi
10555e0765ngie  if test "${min_version#*.*.}" != "${min_version}"; then
10655e0765ngie    min_point_version=${min_version#*.*.}
10755e0765ngie    min_point_version=${min_point_version%%.*}
10855e0765ngie  fi
10955e0765ngie
11055e0765ngie  max_version="$2"
11155e0765ngie  max_major_version=${max_version%%.*}
11255e0765ngie  max_minor_version="0"
11355e0765ngie  max_point_version="0"
11455e0765ngie  if test "${max_version#*.}" != "${max_version}"; then
11555e0765ngie    max_minor_version=${max_version#*.}
11655e0765ngie    max_minor_version=${max_minor_version%%.*}
11755e0765ngie  fi
11855e0765ngie  if test "${max_version#*.*.}" != "${max_version}"; then
11955e0765ngie    max_point_version=${max_version#*.*.}
12055e0765ngie    max_point_version=${max_point_version%%.*}
12155e0765ngie  fi
12255e0765ngie
12355e0765ngie  test $(($major_version)) -lt $(($min_major_version)) && exit 1
12455e0765ngie  if test $(($major_version)) -eq $(($min_major_version)); then
12555e0765ngie    test $(($minor_version)) -lt $(($min_minor_version)) && exit 1
12655e0765ngie    if test $(($minor_version)) -eq $(($min_minor_version)); then
12755e0765ngie      test $(($point_version)) -lt $(($min_point_version)) && exit 1
12855e0765ngie    fi
12955e0765ngie  fi
13055e0765ngie
13155e0765ngie  test $(($major_version)) -gt $(($max_major_version)) && exit 1
13255e0765ngie  if test $(($major_version)) -eq $(($max_major_version)); then
13355e0765ngie    test $(($minor_version)) -gt $(($max_minor_version)) && exit 1
13455e0765ngie    if test $(($minor_version)) -eq $(($max_minor_version)); then
13555e0765ngie      test $(($point_version)) -gt $(($max_point_version)) && exit 1
13655e0765ngie    fi
13755e0765ngie  fi
13855e0765ngie
13955e0765ngie  exit 0
14055e0765ngie}
14155e0765ngie
14255e0765ngie# Show the usage line when no arguments are specified.
14355e0765ngieif test $# -eq 0; then
14455e0765ngie  show_usage
14555e0765ngie  exit 1
14655e0765ngiefi
14755e0765ngie
14855e0765ngiewhile test $# -gt 0; do
14955e0765ngie  case $1 in
15055e0765ngie    --usage)          show_usage;         exit 0;;
15155e0765ngie    --help)           show_help;          exit 0;;
15255e0765ngie
15355e0765ngie    # Installation overrides
15455e0765ngie    --prefix=*)       GTEST_PREFIX=${1#--prefix=};;
15555e0765ngie    --exec-prefix=*)  GTEST_EXEC_PREFIX=${1#--exec-prefix=};;
15655e0765ngie    --libdir=*)       GTEST_LIBDIR=${1#--libdir=};;
15755e0765ngie    --includedir=*)   GTEST_INCLUDEDIR=${1#--includedir=};;
15855e0765ngie
15955e0765ngie    # Installation queries
16055e0765ngie    --prefix|--exec-prefix|--libdir|--includedir|--version)
16155e0765ngie      if test -n "${do_query}"; then
16255e0765ngie        show_usage
16355e0765ngie        exit 1
16455e0765ngie      fi
16555e0765ngie      do_query=${1#--}
16655e0765ngie      ;;
16755e0765ngie
16855e0765ngie    # Version checking
16955e0765ngie    --min-version=*)
17055e0765ngie      do_check_versions=yes
17155e0765ngie      min_version=${1#--min-version=}
17255e0765ngie      ;;
17355e0765ngie    --max-version=*)
17455e0765ngie      do_check_versions=yes
17555e0765ngie      max_version=${1#--max-version=}
17655e0765ngie      ;;
17755e0765ngie    --exact-version=*)
17855e0765ngie      do_check_versions=yes
17955e0765ngie      exact_version=${1#--exact-version=}
18055e0765ngie      ;;
18155e0765ngie
18255e0765ngie    # Compiler flag output
18355e0765ngie    --cppflags)       echo_cppflags=yes;;
18455e0765ngie    --cxxflags)       echo_cxxflags=yes;;
18555e0765ngie    --ldflags)        echo_ldflags=yes;;
18655e0765ngie    --libs)           echo_libs=yes;;
18755e0765ngie
18855e0765ngie    # Everything else is an error
18955e0765ngie    *)                show_usage;         exit 1;;
19055e0765ngie  esac
19155e0765ngie  shift
19255e0765ngiedone
19355e0765ngie
19455e0765ngie# These have defaults filled in by the configure script but can also be
19555e0765ngie# overridden by environment variables or command line parameters.
19655e0765ngieprefix="${GTEST_PREFIX:-@prefix@}"
19755e0765ngieexec_prefix="${GTEST_EXEC_PREFIX:-@exec_prefix@}"
19855e0765ngielibdir="${GTEST_LIBDIR:-@libdir@}"
19955e0765ngieincludedir="${GTEST_INCLUDEDIR:-@includedir@}"
20055e0765ngie
20155e0765ngie# We try and detect if our binary is not located at its installed location. If
20255e0765ngie# it's not, we provide variables pointing to the source and build tree rather
20355e0765ngie# than to the install tree. This allows building against a just-built gtest
20455e0765ngie# rather than an installed gtest.
20555e0765ngiebindir="@bindir@"
20655e0765ngiethis_relative_bindir=`dirname $0`
20755e0765ngiethis_bindir=`cd ${this_relative_bindir}; pwd -P`
20855e0765ngieif test "${this_bindir}" = "${this_bindir%${bindir}}"; then
20955e0765ngie  # The path to the script doesn't end in the bindir sequence from Autoconf,
21055e0765ngie  # assume that we are in a build tree.
21155e0765ngie  build_dir=`dirname ${this_bindir}`
21255e0765ngie  src_dir=`cd ${this_bindir}; cd @top_srcdir@; pwd -P`
21355e0765ngie
21455e0765ngie  # TODO(chandlerc@google.com): This is a dangerous dependency on libtool, we
21555e0765ngie  # should work to remove it, and/or remove libtool altogether, replacing it
21655e0765ngie  # with direct references to the library and a link path.
21755e0765ngie  gtest_libs="${build_dir}/lib/libgtest.la @PTHREAD_CFLAGS@ @PTHREAD_LIBS@"
21855e0765ngie  gtest_ldflags=""
21955e0765ngie
22055e0765ngie  # We provide hooks to include from either the source or build dir, where the
22155e0765ngie  # build dir is always preferred. This will potentially allow us to write
22255e0765ngie  # build rules for generated headers and have them automatically be preferred
22355e0765ngie  # over provided versions.
22455e0765ngie  gtest_cppflags="-I${build_dir}/include -I${src_dir}/include"
22555e0765ngie  gtest_cxxflags="@PTHREAD_CFLAGS@"
22655e0765ngieelse
22755e0765ngie  # We're using an installed gtest, although it may be staged under some
22855e0765ngie  # prefix. Assume (as our own libraries do) that we can resolve the prefix,
22955e0765ngie  # and are present in the dynamic link paths.
23055e0765ngie  gtest_ldflags="-L${libdir}"
23155e0765ngie  gtest_libs="-l${name} @PTHREAD_CFLAGS@ @PTHREAD_LIBS@"
23255e0765ngie  gtest_cppflags="-I${includedir}"
23355e0765ngie  gtest_cxxflags="@PTHREAD_CFLAGS@"
23455e0765ngiefi
23555e0765ngie
23655e0765ngie# Do an installation query if requested.
23755e0765ngieif test -n "$do_query"; then
23855e0765ngie  case $do_query in
23955e0765ngie    prefix)           echo $prefix;       exit 0;;
24055e0765ngie    exec-prefix)      echo $exec_prefix;  exit 0;;
24155e0765ngie    libdir)           echo $libdir;       exit 0;;
24255e0765ngie    includedir)       echo $includedir;   exit 0;;
24355e0765ngie    version)          echo $version;      exit 0;;
24455e0765ngie    *)                show_usage;         exit 1;;
24555e0765ngie  esac
24655e0765ngiefi
24755e0765ngie
24855e0765ngie# Do a version check if requested.
24955e0765ngieif test "$do_check_versions" = "yes"; then
25055e0765ngie  # Make sure we didn't receive a bad combination of parameters.
25155e0765ngie  test "$echo_cppflags" = "yes" && show_usage && exit 1
25255e0765ngie  test "$echo_cxxflags" = "yes" && show_usage && exit 1
25355e0765ngie  test "$echo_ldflags" = "yes"  && show_usage && exit 1
25455e0765ngie  test "$echo_libs" = "yes"     && show_usage && exit 1
25555e0765ngie
25655e0765ngie  if test "$exact_version" != ""; then
25755e0765ngie    check_versions $exact_version $exact_version
25855e0765ngie    # unreachable
25955e0765ngie  else
26055e0765ngie    check_versions ${min_version:-0.0.0} ${max_version:-9999.9999.9999}
26155e0765ngie    # unreachable
26255e0765ngie  fi
26355e0765ngiefi
26455e0765ngie
26555e0765ngie# Do the output in the correct order so that these can be used in-line of
26655e0765ngie# a compiler invocation.
26755e0765ngieoutput=""
26855e0765ngietest "$echo_cppflags" = "yes" && output="$output $gtest_cppflags"
26955e0765ngietest "$echo_cxxflags" = "yes" && output="$output $gtest_cxxflags"
27055e0765ngietest "$echo_ldflags" = "yes"  && output="$output $gtest_ldflags"
27155e0765ngietest "$echo_libs" = "yes"     && output="$output $gtest_libs"
27255e0765ngieecho $output
27355e0765ngie
27455e0765ngieexit 0
275