michael@0: #!/bin/sh michael@0: michael@0: # These variables are automatically filled in by the configure script. michael@0: name="@PACKAGE_TARNAME@" michael@0: version="@PACKAGE_VERSION@" michael@0: michael@0: show_usage() michael@0: { michael@0: echo "Usage: gtest-config [OPTIONS...]" michael@0: } michael@0: michael@0: show_help() michael@0: { michael@0: show_usage michael@0: cat <<\EOF michael@0: michael@0: The `gtest-config' script provides access to the necessary compile and linking michael@0: flags to connect with Google C++ Testing Framework, both in a build prior to michael@0: installation, and on the system proper after installation. The installation michael@0: overrides may be issued in combination with any other queries, but will only michael@0: affect installation queries if called on a built but not installed gtest. The michael@0: installation queries may not be issued with any other types of queries, and michael@0: only one installation query may be made at a time. The version queries and michael@0: compiler flag queries may be combined as desired but not mixed. Different michael@0: version queries are always combined with logical "and" semantics, and only the michael@0: last of any particular query is used while all previous ones ignored. All michael@0: versions must be specified as a sequence of numbers separated by periods. michael@0: Compiler flag queries output the union of the sets of flags when combined. michael@0: michael@0: Examples: michael@0: gtest-config --min-version=1.0 || echo "Insufficient Google Test version." michael@0: michael@0: g++ $(gtest-config --cppflags --cxxflags) -o foo.o -c foo.cpp michael@0: g++ $(gtest-config --ldflags --libs) -o foo foo.o michael@0: michael@0: # When using a built but not installed Google Test: michael@0: g++ $(../../my_gtest_build/scripts/gtest-config ...) ... michael@0: michael@0: # When using an installed Google Test, but with installation overrides: michael@0: export GTEST_PREFIX="/opt" michael@0: g++ $(gtest-config --libdir="/opt/lib64" ...) ... michael@0: michael@0: Help: michael@0: --usage brief usage information michael@0: --help display this help message michael@0: michael@0: Installation Overrides: michael@0: --prefix= overrides the installation prefix michael@0: --exec-prefix= overrides the executable installation prefix michael@0: --libdir= overrides the library installation prefix michael@0: --includedir= overrides the header file installation prefix michael@0: michael@0: Installation Queries: michael@0: --prefix installation prefix michael@0: --exec-prefix executable installation prefix michael@0: --libdir library installation directory michael@0: --includedir header file installation directory michael@0: --version the version of the Google Test installation michael@0: michael@0: Version Queries: michael@0: --min-version=VERSION return 0 if the version is at least VERSION michael@0: --exact-version=VERSION return 0 if the version is exactly VERSION michael@0: --max-version=VERSION return 0 if the version is at most VERSION michael@0: michael@0: Compilation Flag Queries: michael@0: --cppflags compile flags specific to the C-like preprocessors michael@0: --cxxflags compile flags appropriate for C++ programs michael@0: --ldflags linker flags michael@0: --libs libraries for linking michael@0: michael@0: EOF michael@0: } michael@0: michael@0: # This function bounds our version with a min and a max. It uses some clever michael@0: # POSIX-compliant variable expansion to portably do all the work in the shell michael@0: # and avoid any dependency on a particular "sed" or "awk" implementation. michael@0: # Notable is that it will only ever compare the first 3 components of versions. michael@0: # Further components will be cleanly stripped off. All versions must be michael@0: # unadorned, so "v1.0" will *not* work. The minimum version must be in $1, and michael@0: # the max in $2. TODO(chandlerc@google.com): If this ever breaks, we should michael@0: # investigate expanding this via autom4te from AS_VERSION_COMPARE rather than michael@0: # continuing to maintain our own shell version. michael@0: check_versions() michael@0: { michael@0: major_version=${version%%.*} michael@0: minor_version="0" michael@0: point_version="0" michael@0: if test "${version#*.}" != "${version}"; then michael@0: minor_version=${version#*.} michael@0: minor_version=${minor_version%%.*} michael@0: fi michael@0: if test "${version#*.*.}" != "${version}"; then michael@0: point_version=${version#*.*.} michael@0: point_version=${point_version%%.*} michael@0: fi michael@0: michael@0: min_version="$1" michael@0: min_major_version=${min_version%%.*} michael@0: min_minor_version="0" michael@0: min_point_version="0" michael@0: if test "${min_version#*.}" != "${min_version}"; then michael@0: min_minor_version=${min_version#*.} michael@0: min_minor_version=${min_minor_version%%.*} michael@0: fi michael@0: if test "${min_version#*.*.}" != "${min_version}"; then michael@0: min_point_version=${min_version#*.*.} michael@0: min_point_version=${min_point_version%%.*} michael@0: fi michael@0: michael@0: max_version="$2" michael@0: max_major_version=${max_version%%.*} michael@0: max_minor_version="0" michael@0: max_point_version="0" michael@0: if test "${max_version#*.}" != "${max_version}"; then michael@0: max_minor_version=${max_version#*.} michael@0: max_minor_version=${max_minor_version%%.*} michael@0: fi michael@0: if test "${max_version#*.*.}" != "${max_version}"; then michael@0: max_point_version=${max_version#*.*.} michael@0: max_point_version=${max_point_version%%.*} michael@0: fi michael@0: michael@0: test $(($major_version)) -lt $(($min_major_version)) && exit 1 michael@0: if test $(($major_version)) -eq $(($min_major_version)); then michael@0: test $(($minor_version)) -lt $(($min_minor_version)) && exit 1 michael@0: if test $(($minor_version)) -eq $(($min_minor_version)); then michael@0: test $(($point_version)) -lt $(($min_point_version)) && exit 1 michael@0: fi michael@0: fi michael@0: michael@0: test $(($major_version)) -gt $(($max_major_version)) && exit 1 michael@0: if test $(($major_version)) -eq $(($max_major_version)); then michael@0: test $(($minor_version)) -gt $(($max_minor_version)) && exit 1 michael@0: if test $(($minor_version)) -eq $(($max_minor_version)); then michael@0: test $(($point_version)) -gt $(($max_point_version)) && exit 1 michael@0: fi michael@0: fi michael@0: michael@0: exit 0 michael@0: } michael@0: michael@0: # Show the usage line when no arguments are specified. michael@0: if test $# -eq 0; then michael@0: show_usage michael@0: exit 1 michael@0: fi michael@0: michael@0: while test $# -gt 0; do michael@0: case $1 in michael@0: --usage) show_usage; exit 0;; michael@0: --help) show_help; exit 0;; michael@0: michael@0: # Installation overrides michael@0: --prefix=*) GTEST_PREFIX=${1#--prefix=};; michael@0: --exec-prefix=*) GTEST_EXEC_PREFIX=${1#--exec-prefix=};; michael@0: --libdir=*) GTEST_LIBDIR=${1#--libdir=};; michael@0: --includedir=*) GTEST_INCLUDEDIR=${1#--includedir=};; michael@0: michael@0: # Installation queries michael@0: --prefix|--exec-prefix|--libdir|--includedir|--version) michael@0: if test -n "${do_query}"; then michael@0: show_usage michael@0: exit 1 michael@0: fi michael@0: do_query=${1#--} michael@0: ;; michael@0: michael@0: # Version checking michael@0: --min-version=*) michael@0: do_check_versions=yes michael@0: min_version=${1#--min-version=} michael@0: ;; michael@0: --max-version=*) michael@0: do_check_versions=yes michael@0: max_version=${1#--max-version=} michael@0: ;; michael@0: --exact-version=*) michael@0: do_check_versions=yes michael@0: exact_version=${1#--exact-version=} michael@0: ;; michael@0: michael@0: # Compiler flag output michael@0: --cppflags) echo_cppflags=yes;; michael@0: --cxxflags) echo_cxxflags=yes;; michael@0: --ldflags) echo_ldflags=yes;; michael@0: --libs) echo_libs=yes;; michael@0: michael@0: # Everything else is an error michael@0: *) show_usage; exit 1;; michael@0: esac michael@0: shift michael@0: done michael@0: michael@0: # These have defaults filled in by the configure script but can also be michael@0: # overridden by environment variables or command line parameters. michael@0: prefix="${GTEST_PREFIX:-@prefix@}" michael@0: exec_prefix="${GTEST_EXEC_PREFIX:-@exec_prefix@}" michael@0: libdir="${GTEST_LIBDIR:-@libdir@}" michael@0: includedir="${GTEST_INCLUDEDIR:-@includedir@}" michael@0: michael@0: # We try and detect if our binary is not located at its installed location. If michael@0: # it's not, we provide variables pointing to the source and build tree rather michael@0: # than to the install tree. This allows building against a just-built gtest michael@0: # rather than an installed gtest. michael@0: bindir="@bindir@" michael@0: this_relative_bindir=`dirname $0` michael@0: this_bindir=`cd ${this_relative_bindir}; pwd -P` michael@0: if test "${this_bindir}" = "${this_bindir%${bindir}}"; then michael@0: # The path to the script doesn't end in the bindir sequence from Autoconf, michael@0: # assume that we are in a build tree. michael@0: build_dir=`dirname ${this_bindir}` michael@0: src_dir=`cd ${this_bindir}/@top_srcdir@; pwd -P` michael@0: michael@0: # TODO(chandlerc@google.com): This is a dangerous dependency on libtool, we michael@0: # should work to remove it, and/or remove libtool altogether, replacing it michael@0: # with direct references to the library and a link path. michael@0: gtest_libs="${build_dir}/lib/libgtest.la @PTHREAD_CFLAGS@ @PTHREAD_LIBS@" michael@0: gtest_ldflags="" michael@0: michael@0: # We provide hooks to include from either the source or build dir, where the michael@0: # build dir is always preferred. This will potentially allow us to write michael@0: # build rules for generated headers and have them automatically be preferred michael@0: # over provided versions. michael@0: gtest_cppflags="-I${build_dir}/include -I${src_dir}/include" michael@0: gtest_cxxflags="@PTHREAD_CFLAGS@" michael@0: else michael@0: # We're using an installed gtest, although it may be staged under some michael@0: # prefix. Assume (as our own libraries do) that we can resolve the prefix, michael@0: # and are present in the dynamic link paths. michael@0: gtest_ldflags="-L${libdir}" michael@0: gtest_libs="-l${name} @PTHREAD_CFLAGS@ @PTHREAD_LIBS@" michael@0: gtest_cppflags="-I${includedir}" michael@0: gtest_cxxflags="@PTHREAD_CFLAGS@" michael@0: fi michael@0: michael@0: # Do an installation query if requested. michael@0: if test -n "$do_query"; then michael@0: case $do_query in michael@0: prefix) echo $prefix; exit 0;; michael@0: exec-prefix) echo $exec_prefix; exit 0;; michael@0: libdir) echo $libdir; exit 0;; michael@0: includedir) echo $includedir; exit 0;; michael@0: version) echo $version; exit 0;; michael@0: *) show_usage; exit 1;; michael@0: esac michael@0: fi michael@0: michael@0: # Do a version check if requested. michael@0: if test "$do_check_versions" = "yes"; then michael@0: # Make sure we didn't receive a bad combination of parameters. michael@0: test "$echo_cppflags" = "yes" && show_usage && exit 1 michael@0: test "$echo_cxxflags" = "yes" && show_usage && exit 1 michael@0: test "$echo_ldflags" = "yes" && show_usage && exit 1 michael@0: test "$echo_libs" = "yes" && show_usage && exit 1 michael@0: michael@0: if test "$exact_version" != ""; then michael@0: check_versions $exact_version $exact_version michael@0: # unreachable michael@0: else michael@0: check_versions ${min_version:-0.0.0} ${max_version:-9999.9999.9999} michael@0: # unreachable michael@0: fi michael@0: fi michael@0: michael@0: # Do the output in the correct order so that these can be used in-line of michael@0: # a compiler invocation. michael@0: output="" michael@0: test "$echo_cppflags" = "yes" && output="$output $gtest_cppflags" michael@0: test "$echo_cxxflags" = "yes" && output="$output $gtest_cxxflags" michael@0: test "$echo_ldflags" = "yes" && output="$output $gtest_ldflags" michael@0: test "$echo_libs" = "yes" && output="$output $gtest_libs" michael@0: echo $output michael@0: michael@0: exit 0