1#!/bin/sh 2 3# These variables are automatically filled in by the configure script. 4name="@PACKAGE_TARNAME@" 5version="@PACKAGE_VERSION@" 6 7show_usage() 8{ 9 echo "Usage: gmock-config [OPTIONS...]" 10} 11 12show_help() 13{ 14 show_usage 15 cat <<\EOF 16 17The `gmock-config' script provides access to the necessary compile and linking 18flags to connect with Google C++ Mocking Framework, both in a build prior to 19installation, and on the system proper after installation. The installation 20overrides may be issued in combination with any other queries, but will only 21affect installation queries if called on a built but not installed gmock. The 22installation queries may not be issued with any other types of queries, and 23only one installation query may be made at a time. The version queries and 24compiler flag queries may be combined as desired but not mixed. Different 25version queries are always combined with logical "and" semantics, and only the 26last of any particular query is used while all previous ones ignored. All 27versions must be specified as a sequence of numbers separated by periods. 28Compiler flag queries output the union of the sets of flags when combined. 29 30 Examples: 31 gmock-config --min-version=1.0 || echo "Insufficient Google Mock version." 32 33 g++ $(gmock-config --cppflags --cxxflags) -o foo.o -c foo.cpp 34 g++ $(gmock-config --ldflags --libs) -o foo foo.o 35 36 # When using a built but not installed Google Mock: 37 g++ $(../../my_gmock_build/scripts/gmock-config ...) ... 38 39 # When using an installed Google Mock, but with installation overrides: 40 export GMOCK_PREFIX="/opt" 41 g++ $(gmock-config --libdir="/opt/lib64" ...) ... 42 43 Help: 44 --usage brief usage information 45 --help display this help message 46 47 Installation Overrides: 48 --prefix=<dir> overrides the installation prefix 49 --exec-prefix=<dir> overrides the executable installation prefix 50 --libdir=<dir> overrides the library installation prefix 51 --includedir=<dir> overrides the header file installation prefix 52 53 Installation Queries: 54 --prefix installation prefix 55 --exec-prefix executable installation prefix 56 --libdir library installation directory 57 --includedir header file installation directory 58 --version the version of the Google Mock installation 59 60 Version Queries: 61 --min-version=VERSION return 0 if the version is at least VERSION 62 --exact-version=VERSION return 0 if the version is exactly VERSION 63 --max-version=VERSION return 0 if the version is at most VERSION 64 65 Compilation Flag Queries: 66 --cppflags compile flags specific to the C-like preprocessors 67 --cxxflags compile flags appropriate for C++ programs 68 --ldflags linker flags 69 --libs libraries for linking 70 71EOF 72} 73 74# This function bounds our version with a min and a max. It uses some clever 75# POSIX-compliant variable expansion to portably do all the work in the shell 76# and avoid any dependency on a particular "sed" or "awk" implementation. 77# Notable is that it will only ever compare the first 3 components of versions. 78# Further components will be cleanly stripped off. All versions must be 79# unadorned, so "v1.0" will *not* work. The minimum version must be in $1, and 80# the max in $2. TODO(chandlerc@google.com): If this ever breaks, we should 81# investigate expanding this via autom4te from AS_VERSION_COMPARE rather than 82# continuing to maintain our own shell version. 83check_versions() 84{ 85 major_version=${version%%.*} 86 minor_version="0" 87 point_version="0" 88 if test "${version#*.}" != "${version}"; then 89 minor_version=${version#*.} 90 minor_version=${minor_version%%.*} 91 fi 92 if test "${version#*.*.}" != "${version}"; then 93 point_version=${version#*.*.} 94 point_version=${point_version%%.*} 95 fi 96 97 min_version="$1" 98 min_major_version=${min_version%%.*} 99 min_minor_version="0" 100 min_point_version="0" 101 if test "${min_version#*.}" != "${min_version}"; then 102 min_minor_version=${min_version#*.} 103 min_minor_version=${min_minor_version%%.*} 104 fi 105 if test "${min_version#*.*.}" != "${min_version}"; then 106 min_point_version=${min_version#*.*.} 107 min_point_version=${min_point_version%%.*} 108 fi 109 110 max_version="$2" 111 max_major_version=${max_version%%.*} 112 max_minor_version="0" 113 max_point_version="0" 114 if test "${max_version#*.}" != "${max_version}"; then 115 max_minor_version=${max_version#*.} 116 max_minor_version=${max_minor_version%%.*} 117 fi 118 if test "${max_version#*.*.}" != "${max_version}"; then 119 max_point_version=${max_version#*.*.} 120 max_point_version=${max_point_version%%.*} 121 fi 122 123 test $(($major_version)) -lt $(($min_major_version)) && exit 1 124 if test $(($major_version)) -eq $(($min_major_version)); then 125 test $(($minor_version)) -lt $(($min_minor_version)) && exit 1 126 if test $(($minor_version)) -eq $(($min_minor_version)); then 127 test $(($point_version)) -lt $(($min_point_version)) && exit 1 128 fi 129 fi 130 131 test $(($major_version)) -gt $(($max_major_version)) && exit 1 132 if test $(($major_version)) -eq $(($max_major_version)); then 133 test $(($minor_version)) -gt $(($max_minor_version)) && exit 1 134 if test $(($minor_version)) -eq $(($max_minor_version)); then 135 test $(($point_version)) -gt $(($max_point_version)) && exit 1 136 fi 137 fi 138 139 exit 0 140} 141 142# Show the usage line when no arguments are specified. 143if test $# -eq 0; then 144 show_usage 145 exit 1 146fi 147 148while test $# -gt 0; do 149 case $1 in 150 --usage) show_usage; exit 0;; 151 --help) show_help; exit 0;; 152 153 # Installation overrides 154 --prefix=*) GMOCK_PREFIX=${1#--prefix=};; 155 --exec-prefix=*) GMOCK_EXEC_PREFIX=${1#--exec-prefix=};; 156 --libdir=*) GMOCK_LIBDIR=${1#--libdir=};; 157 --includedir=*) GMOCK_INCLUDEDIR=${1#--includedir=};; 158 159 # Installation queries 160 --prefix|--exec-prefix|--libdir|--includedir|--version) 161 if test -n "${do_query}"; then 162 show_usage 163 exit 1 164 fi 165 do_query=${1#--} 166 ;; 167 168 # Version checking 169 --min-version=*) 170 do_check_versions=yes 171 min_version=${1#--min-version=} 172 ;; 173 --max-version=*) 174 do_check_versions=yes 175 max_version=${1#--max-version=} 176 ;; 177 --exact-version=*) 178 do_check_versions=yes 179 exact_version=${1#--exact-version=} 180 ;; 181 182 # Compiler flag output 183 --cppflags) echo_cppflags=yes;; 184 --cxxflags) echo_cxxflags=yes;; 185 --ldflags) echo_ldflags=yes;; 186 --libs) echo_libs=yes;; 187 188 # Everything else is an error 189 *) show_usage; exit 1;; 190 esac 191 shift 192done 193 194# These have defaults filled in by the configure script but can also be 195# overridden by environment variables or command line parameters. 196prefix="${GMOCK_PREFIX:-@prefix@}" 197exec_prefix="${GMOCK_EXEC_PREFIX:-@exec_prefix@}" 198libdir="${GMOCK_LIBDIR:-@libdir@}" 199includedir="${GMOCK_INCLUDEDIR:-@includedir@}" 200 201# We try and detect if our binary is not located at its installed location. If 202# it's not, we provide variables pointing to the source and build tree rather 203# than to the install tree. We also locate Google Test using the configured 204# gtest-config script rather than searching the PATH and our bindir for one. 205# This allows building against a just-built gmock rather than an installed 206# gmock. 207bindir="@bindir@" 208this_relative_bindir=`dirname $0` 209this_bindir=`cd ${this_relative_bindir}; pwd -P` 210if test "${this_bindir}" = "${this_bindir%${bindir}}"; then 211 # The path to the script doesn't end in the bindir sequence from Autoconf, 212 # assume that we are in a build tree. 213 build_dir=`dirname ${this_bindir}` 214 src_dir=`cd ${this_bindir}/@top_srcdir@; pwd -P` 215 216 # TODO(chandlerc@google.com): This is a dangerous dependency on libtool, we 217 # should work to remove it, and/or remove libtool altogether, replacing it 218 # with direct references to the library and a link path. 219 gmock_libs="${build_dir}/lib/libgmock.la" 220 gmock_ldflags="" 221 222 # We provide hooks to include from either the source or build dir, where the 223 # build dir is always preferred. This will potentially allow us to write 224 # build rules for generated headers and have them automatically be preferred 225 # over provided versions. 226 gmock_cppflags="-I${build_dir}/include -I${src_dir}/include" 227 gmock_cxxflags="" 228 229 # Directly invoke the gtest-config script used during the build process. 230 gtest_config="@GTEST_CONFIG@" 231else 232 # We're using an installed gmock, although it may be staged under some 233 # prefix. Assume (as our own libraries do) that we can resolve the prefix, 234 # and are present in the dynamic link paths. 235 gmock_ldflags="-L${libdir}" 236 gmock_libs="-l${name}" 237 gmock_cppflags="-I${includedir}" 238 gmock_cxxflags="" 239 240 # We also prefer any gtest-config script installed in our prefix. Lacking 241 # one, we look in the PATH for one. 242 gtest_config="${bindir}/gtest-config" 243 if test ! -x "${gtest_config}"; then 244 gtest_config=`which gtest-config` 245 fi 246fi 247 248# Ensure that we have located a Google Test to link against. 249if ! test -x "${gtest_config}"; then 250 echo "Unable to locate Google Test, check your Google Mock configuration" \ 251 "and installation" >&2 252 exit 1 253elif ! "${gtest_config}" "--exact-version=@GTEST_VERSION@"; then 254 echo "The Google Test found is not the same version as Google Mock was " \ 255 "built against" >&2 256 exit 1 257fi 258 259# Add the necessary Google Test bits into the various flag variables 260gmock_cppflags="${gmock_cppflags} `${gtest_config} --cppflags`" 261gmock_cxxflags="${gmock_cxxflags} `${gtest_config} --cxxflags`" 262gmock_ldflags="${gmock_ldflags} `${gtest_config} --ldflags`" 263gmock_libs="${gmock_libs} `${gtest_config} --libs`" 264 265# Do an installation query if requested. 266if test -n "$do_query"; then 267 case $do_query in 268 prefix) echo $prefix; exit 0;; 269 exec-prefix) echo $exec_prefix; exit 0;; 270 libdir) echo $libdir; exit 0;; 271 includedir) echo $includedir; exit 0;; 272 version) echo $version; exit 0;; 273 *) show_usage; exit 1;; 274 esac 275fi 276 277# Do a version check if requested. 278if test "$do_check_versions" = "yes"; then 279 # Make sure we didn't receive a bad combination of parameters. 280 test "$echo_cppflags" = "yes" && show_usage && exit 1 281 test "$echo_cxxflags" = "yes" && show_usage && exit 1 282 test "$echo_ldflags" = "yes" && show_usage && exit 1 283 test "$echo_libs" = "yes" && show_usage && exit 1 284 285 if test "$exact_version" != ""; then 286 check_versions $exact_version $exact_version 287 # unreachable 288 else 289 check_versions ${min_version:-0.0.0} ${max_version:-9999.9999.9999} 290 # unreachable 291 fi 292fi 293 294# Do the output in the correct order so that these can be used in-line of 295# a compiler invocation. 296output="" 297test "$echo_cppflags" = "yes" && output="$output $gmock_cppflags" 298test "$echo_cxxflags" = "yes" && output="$output $gmock_cxxflags" 299test "$echo_ldflags" = "yes" && output="$output $gmock_ldflags" 300test "$echo_libs" = "yes" && output="$output $gmock_libs" 301echo $output 302 303exit 0 304