Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:19:53

0001 #!/bin/sh
0002 
0003 # These variables are automatically filled in by the configure script.
0004 name="@PACKAGE_TARNAME@"
0005 version="@PACKAGE_VERSION@"
0006 
0007 show_usage()
0008 {
0009   echo "Usage: gmock-config [OPTIONS...]"
0010 }
0011 
0012 show_help()
0013 {
0014   show_usage
0015   cat <<\EOF
0016 
0017 The `gmock-config' script provides access to the necessary compile and linking
0018 flags to connect with Google C++ Mocking Framework, both in a build prior to
0019 installation, and on the system proper after installation. The installation
0020 overrides may be issued in combination with any other queries, but will only
0021 affect installation queries if called on a built but not installed gmock. The
0022 installation queries may not be issued with any other types of queries, and
0023 only one installation query may be made at a time. The version queries and
0024 compiler flag queries may be combined as desired but not mixed. Different
0025 version queries are always combined with logical "and" semantics, and only the
0026 last of any particular query is used while all previous ones ignored. All
0027 versions must be specified as a sequence of numbers separated by periods.
0028 Compiler flag queries output the union of the sets of flags when combined.
0029 
0030  Examples:
0031   gmock-config --min-version=1.0 || echo "Insufficient Google Mock version."
0032 
0033   g++ $(gmock-config --cppflags --cxxflags) -o foo.o -c foo.cpp
0034   g++ $(gmock-config --ldflags --libs) -o foo foo.o
0035 
0036   # When using a built but not installed Google Mock:
0037   g++ $(../../my_gmock_build/scripts/gmock-config ...) ...
0038 
0039   # When using an installed Google Mock, but with installation overrides:
0040   export GMOCK_PREFIX="/opt"
0041   g++ $(gmock-config --libdir="/opt/lib64" ...) ...
0042 
0043  Help:
0044   --usage                    brief usage information
0045   --help                     display this help message
0046 
0047  Installation Overrides:
0048   --prefix=<dir>             overrides the installation prefix
0049   --exec-prefix=<dir>        overrides the executable installation prefix
0050   --libdir=<dir>             overrides the library installation prefix
0051   --includedir=<dir>         overrides the header file installation prefix
0052 
0053  Installation Queries:
0054   --prefix                   installation prefix
0055   --exec-prefix              executable installation prefix
0056   --libdir                   library installation directory
0057   --includedir               header file installation directory
0058   --version                  the version of the Google Mock installation
0059 
0060  Version Queries:
0061   --min-version=VERSION      return 0 if the version is at least VERSION
0062   --exact-version=VERSION    return 0 if the version is exactly VERSION
0063   --max-version=VERSION      return 0 if the version is at most VERSION
0064 
0065  Compilation Flag Queries:
0066   --cppflags                 compile flags specific to the C-like preprocessors
0067   --cxxflags                 compile flags appropriate for C++ programs
0068   --ldflags                  linker flags
0069   --libs                     libraries for linking
0070 
0071 EOF
0072 }
0073 
0074 # This function bounds our version with a min and a max. It uses some clever
0075 # POSIX-compliant variable expansion to portably do all the work in the shell
0076 # and avoid any dependency on a particular "sed" or "awk" implementation.
0077 # Notable is that it will only ever compare the first 3 components of versions.
0078 # Further components will be cleanly stripped off. All versions must be
0079 # unadorned, so "v1.0" will *not* work. The minimum version must be in $1, and
0080 # the max in $2. TODO(chandlerc@google.com): If this ever breaks, we should
0081 # investigate expanding this via autom4te from AS_VERSION_COMPARE rather than
0082 # continuing to maintain our own shell version.
0083 check_versions()
0084 {
0085   major_version=${version%%.*}
0086   minor_version="0"
0087   point_version="0"
0088   if test "${version#*.}" != "${version}"; then
0089     minor_version=${version#*.}
0090     minor_version=${minor_version%%.*}
0091   fi
0092   if test "${version#*.*.}" != "${version}"; then
0093     point_version=${version#*.*.}
0094     point_version=${point_version%%.*}
0095   fi
0096 
0097   min_version="$1"
0098   min_major_version=${min_version%%.*}
0099   min_minor_version="0"
0100   min_point_version="0"
0101   if test "${min_version#*.}" != "${min_version}"; then
0102     min_minor_version=${min_version#*.}
0103     min_minor_version=${min_minor_version%%.*}
0104   fi
0105   if test "${min_version#*.*.}" != "${min_version}"; then
0106     min_point_version=${min_version#*.*.}
0107     min_point_version=${min_point_version%%.*}
0108   fi
0109 
0110   max_version="$2"
0111   max_major_version=${max_version%%.*}
0112   max_minor_version="0"
0113   max_point_version="0"
0114   if test "${max_version#*.}" != "${max_version}"; then
0115     max_minor_version=${max_version#*.}
0116     max_minor_version=${max_minor_version%%.*}
0117   fi
0118   if test "${max_version#*.*.}" != "${max_version}"; then
0119     max_point_version=${max_version#*.*.}
0120     max_point_version=${max_point_version%%.*}
0121   fi
0122 
0123   test $(($major_version)) -lt $(($min_major_version)) && exit 1
0124   if test $(($major_version)) -eq $(($min_major_version)); then
0125     test $(($minor_version)) -lt $(($min_minor_version)) && exit 1
0126     if test $(($minor_version)) -eq $(($min_minor_version)); then
0127       test $(($point_version)) -lt $(($min_point_version)) && exit 1
0128     fi
0129   fi
0130 
0131   test $(($major_version)) -gt $(($max_major_version)) && exit 1
0132   if test $(($major_version)) -eq $(($max_major_version)); then
0133     test $(($minor_version)) -gt $(($max_minor_version)) && exit 1
0134     if test $(($minor_version)) -eq $(($max_minor_version)); then
0135       test $(($point_version)) -gt $(($max_point_version)) && exit 1
0136     fi
0137   fi
0138 
0139   exit 0
0140 }
0141 
0142 # Show the usage line when no arguments are specified.
0143 if test $# -eq 0; then
0144   show_usage
0145   exit 1
0146 fi
0147 
0148 while test $# -gt 0; do
0149   case $1 in
0150     --usage)          show_usage;         exit 0;;
0151     --help)           show_help;          exit 0;;
0152 
0153     # Installation overrides
0154     --prefix=*)       GMOCK_PREFIX=${1#--prefix=};;
0155     --exec-prefix=*)  GMOCK_EXEC_PREFIX=${1#--exec-prefix=};;
0156     --libdir=*)       GMOCK_LIBDIR=${1#--libdir=};;
0157     --includedir=*)   GMOCK_INCLUDEDIR=${1#--includedir=};;
0158 
0159     # Installation queries
0160     --prefix|--exec-prefix|--libdir|--includedir|--version)
0161       if test -n "${do_query}"; then
0162         show_usage
0163         exit 1
0164       fi
0165       do_query=${1#--}
0166       ;;
0167 
0168     # Version checking
0169     --min-version=*)
0170       do_check_versions=yes
0171       min_version=${1#--min-version=}
0172       ;;
0173     --max-version=*)
0174       do_check_versions=yes
0175       max_version=${1#--max-version=}
0176       ;;
0177     --exact-version=*)
0178       do_check_versions=yes
0179       exact_version=${1#--exact-version=}
0180       ;;
0181 
0182     # Compiler flag output
0183     --cppflags)       echo_cppflags=yes;;
0184     --cxxflags)       echo_cxxflags=yes;;
0185     --ldflags)        echo_ldflags=yes;;
0186     --libs)           echo_libs=yes;;
0187 
0188     # Everything else is an error
0189     *)                show_usage;         exit 1;;
0190   esac
0191   shift
0192 done
0193 
0194 # These have defaults filled in by the configure script but can also be
0195 # overridden by environment variables or command line parameters.
0196 prefix="${GMOCK_PREFIX:-@prefix@}"
0197 exec_prefix="${GMOCK_EXEC_PREFIX:-@exec_prefix@}"
0198 libdir="${GMOCK_LIBDIR:-@libdir@}"
0199 includedir="${GMOCK_INCLUDEDIR:-@includedir@}"
0200 
0201 # We try and detect if our binary is not located at its installed location. If
0202 # it's not, we provide variables pointing to the source and build tree rather
0203 # than to the install tree. We also locate Google Test using the configured
0204 # gtest-config script rather than searching the PATH and our bindir for one.
0205 # This allows building against a just-built gmock rather than an installed
0206 # gmock.
0207 bindir="@bindir@"
0208 this_relative_bindir=`dirname $0`
0209 this_bindir=`cd ${this_relative_bindir}; pwd -P`
0210 if test "${this_bindir}" = "${this_bindir%${bindir}}"; then
0211   # The path to the script doesn't end in the bindir sequence from Autoconf,
0212   # assume that we are in a build tree.
0213   build_dir=`dirname ${this_bindir}`
0214   src_dir=`cd ${this_bindir}/@top_srcdir@; pwd -P`
0215 
0216   # TODO(chandlerc@google.com): This is a dangerous dependency on libtool, we
0217   # should work to remove it, and/or remove libtool altogether, replacing it
0218   # with direct references to the library and a link path.
0219   gmock_libs="${build_dir}/lib/libgmock.la"
0220   gmock_ldflags=""
0221 
0222   # We provide hooks to include from either the source or build dir, where the
0223   # build dir is always preferred. This will potentially allow us to write
0224   # build rules for generated headers and have them automatically be preferred
0225   # over provided versions.
0226   gmock_cppflags="-I${build_dir}/include -I${src_dir}/include"
0227   gmock_cxxflags=""
0228 
0229   # Directly invoke the gtest-config script used during the build process.
0230   gtest_config="@GTEST_CONFIG@"
0231 else
0232   # We're using an installed gmock, although it may be staged under some
0233   # prefix. Assume (as our own libraries do) that we can resolve the prefix,
0234   # and are present in the dynamic link paths.
0235   gmock_ldflags="-L${libdir}"
0236   gmock_libs="-l${name}"
0237   gmock_cppflags="-I${includedir}"
0238   gmock_cxxflags=""
0239 
0240   # We also prefer any gtest-config script installed in our prefix. Lacking
0241   # one, we look in the PATH for one.
0242   gtest_config="${bindir}/gtest-config"
0243   if test ! -x "${gtest_config}"; then
0244     gtest_config=`which gtest-config`
0245   fi
0246 fi
0247 
0248 # Ensure that we have located a Google Test to link against.
0249 if ! test -x "${gtest_config}"; then
0250   echo "Unable to locate Google Test, check your Google Mock configuration" \
0251        "and installation" >&2
0252   exit 1
0253 elif ! "${gtest_config}" "--exact-version=@GTEST_VERSION@"; then
0254   echo "The Google Test found is not the same version as Google Mock was " \
0255        "built against" >&2
0256   exit 1
0257 fi
0258 
0259 # Add the necessary Google Test bits into the various flag variables
0260 gmock_cppflags="${gmock_cppflags} `${gtest_config} --cppflags`"
0261 gmock_cxxflags="${gmock_cxxflags} `${gtest_config} --cxxflags`"
0262 gmock_ldflags="${gmock_ldflags} `${gtest_config} --ldflags`"
0263 gmock_libs="${gmock_libs} `${gtest_config} --libs`"
0264 
0265 # Do an installation query if requested.
0266 if test -n "$do_query"; then
0267   case $do_query in
0268     prefix)           echo $prefix;       exit 0;;
0269     exec-prefix)      echo $exec_prefix;  exit 0;;
0270     libdir)           echo $libdir;       exit 0;;
0271     includedir)       echo $includedir;   exit 0;;
0272     version)          echo $version;      exit 0;;
0273     *)                show_usage;         exit 1;;
0274   esac
0275 fi
0276 
0277 # Do a version check if requested.
0278 if test "$do_check_versions" = "yes"; then
0279   # Make sure we didn't receive a bad combination of parameters.
0280   test "$echo_cppflags" = "yes" && show_usage && exit 1
0281   test "$echo_cxxflags" = "yes" && show_usage && exit 1
0282   test "$echo_ldflags" = "yes"  && show_usage && exit 1
0283   test "$echo_libs" = "yes"     && show_usage && exit 1
0284 
0285   if test "$exact_version" != ""; then
0286     check_versions $exact_version $exact_version
0287     # unreachable
0288   else
0289     check_versions ${min_version:-0.0.0} ${max_version:-9999.9999.9999}
0290     # unreachable
0291   fi
0292 fi
0293 
0294 # Do the output in the correct order so that these can be used in-line of
0295 # a compiler invocation.
0296 output=""
0297 test "$echo_cppflags" = "yes" && output="$output $gmock_cppflags"
0298 test "$echo_cxxflags" = "yes" && output="$output $gmock_cxxflags"
0299 test "$echo_ldflags" = "yes"  && output="$output $gmock_ldflags"
0300 test "$echo_libs" = "yes"     && output="$output $gmock_libs"
0301 echo $output
0302 
0303 exit 0