File: vmtools.m4

package info (click to toggle)
open-vm-tools 1%3A8.4.2-261024-1
  • links: PTS, VCS
  • area: contrib
  • in suites: squeeze
  • size: 20,368 kB
  • ctags: 30,043
  • sloc: ansic: 164,785; sh: 10,713; cpp: 6,525; makefile: 3,386
file content (267 lines) | stat: -rw-r--r-- 9,924 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
################################################################################
### Copyright 2009 VMware, Inc.  All rights reserved.
###
### VMware-specific macros for use with autoconf.
###
###
### This program is free software; you can redistribute it and/or modify
### it under the terms of version 2 of the GNU General Public License as
### published by the Free Software Foundation.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with this program; if not, write to the Free Software
### Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
################################################################################

#
# AC_VMW_CHECK_LIB(library, lvar, pkgname, lconfig, version, header, function,
#                  [action-if-found],
#                  [action-if-not-found])
#
# Checks for the existence of a library using three different methods, in the
# following order:
#
#     - user defined CUSTOM_(LIB)_CPPFLAGS and CUSTOM_(LIB)_LIBS variables.
#     - pkg-config
#     - the library's custom "config"
#
# If a library is successfully detected, the (LIB)_CPPFLAGS and (LIB)_LIBS
# variables are set to contain the appropriate flags, and these variables are
# exported using AC_SUBST. The parameters to the macro are:
#
#  library ($1): the library name; this is used for testing whether we can link
#                to the library (with AC_CHECK_LIB), and also to modify the user
#                provided CUSTOM_(LIB)_LIBS variable to make sure the library is
#                available in the linker flags.
#  lvar ($2): root name of the variables holding the libraries CPPFLAGS / LIBS;
#             e.g., FOO means that FOO_CPPFLAGS will be set, and CUSTOM_FOO_CPPFLAGS
#             used with AC_CHECK_HEADER.
#  pkgname ($3): pkg-config name of the library.
#  lconfig ($4): library's custom "config" program for figuring out compiler and
#                linker flags (optional).
#  version ($5): minimum version of the library when using pkg-config (optional).
#  header ($6): header file (when not using pkg-config; see AC_CHECK_HEADER; optional).
#  function ($7): function (when not using pkg-config; see AC_CHECK_LIB; optional).
#  action-if-found ($8): what to execute when successfully found the library.
#  action-if-not-found ($9): what to execute when the library was not found.
#
AC_DEFUN([AC_VMW_CHECK_LIB],[
   AC_REQUIRE([AC_CHECK_LIB]) dnl
   AC_REQUIRE([AC_CHECK_HEADER]) dnl

   if test -z "$1"; then
      AC_MSG_ERROR(['library' parameter is required.'])
   fi
   if test -z "$2"; then
      AC_MSG_ERROR(['lvar' parameter is required.'])
   fi

   ac_vmw_have_lib=0
   ac_vmw_have_lib_func=0
   ac_vmw_have_lib_header=0
   ac_vmw_custom_libs=

   #
   # First, try any user-defined CUSTOM_* flags.
   #
   if test -n "${CUSTOM_$2_CPPFLAGS}" || test -n "${CUSTOM_$2_LIBS}"; then
      ac_vmw_custom_libs="${CUSTOM_$2_LIBS} -l$1"
      if test -n "$6"; then
         ORIGINAL_CPPFLAGS="$CPPFLAGS"
         CPPFLAGS="${CUSTOM_$2_CPPFLAGS} $CPPFLAGS"

         AC_CHECK_HEADER([$6],
                         [ac_vmw_have_lib_header=1])

         CPPFLAGS="$ORIGINAL_CPPFLAGS"
      else
         ac_vmw_have_lib_header=1
      fi

      # Check a specific function in the library if requested.
      # If it hasn't, just pick a random function from libc, just to make
      # sure the linker can find the library being tested.
      if test $ac_vmw_have_lib_header -eq 1; then
         if test -n "$7"; then
            ac_vmw_function=$7
         else
            ac_vmw_function=strlen
         fi
         AC_CHECK_LIB(
            [$1],
            [$ac_vmw_function],
            [ac_vmw_have_lib_func=1],
            [],
            [$ac_vmw_custom_libs])
      fi

      if test $ac_vmw_have_lib_func -eq 1 && test $ac_vmw_have_lib_header -eq 1; then
         $2_CPPFLAGS="${CUSTOM_$2_CPPFLAGS}"
         $2_LIBS="$ac_vmw_custom_libs"
         ac_vmw_have_lib=1
      fi
   fi

   # If that didn't work, try with pkg-config.
   if test $ac_vmw_have_lib -eq 0 && test "$HAVE_PKG_CONFIG" = "yes" && test -n "$3"; then
      if test -n "$5"; then
         AC_MSG_CHECKING([for $3 >= $5 (via pkg-config)])
         if pkg-config --exists '$3 >= $5'; then
            ac_vmw_have_lib=1
         fi
      else
         AC_MSG_CHECKING([for $3 (via pkg-config)])
         if pkg-config --exists '$3'; then
            ac_vmw_have_lib=1
         fi
      fi

      if test $ac_vmw_have_lib -eq 1; then
         # Sometimes pkg-config might fail; for example, "pkg-config gtk+-2.0 --cflags"
         # fails on OpenSolaris B71. So be pessimistic.
         ac_vmw_cppflags="`pkg-config --cflags $3`"
         ac_vmw_ret1=$?
         ac_vmw_libs="`pkg-config --libs $3`"
         ac_vmw_ret2=$?
         if test $ac_vmw_ret1 -eq 0 && test $ac_vmw_ret2 -eq 0; then
            AC_MSG_RESULT([yes])
            $2_CPPFLAGS="$ac_vmw_cppflags"
            $2_LIBS="$ac_vmw_libs"
         else
            AC_MSG_RESULT([no])
         fi
      else
         AC_MSG_RESULT([no])
      fi
   fi

   # If we still haven't found the lib, try with the library's custom "config" script.
   # Before checking, flush the AC_PATH_PROG cached variable.
   unset ac_cv_path_ac_vmw_lib_cfg
   unset ac_vmw_lib_cfg
   if test $ac_vmw_have_lib -eq 0 && test -n "$4"; then
      AC_PATH_PROG([ac_vmw_lib_cfg], [$4], [no])
      if test "$ac_vmw_lib_cfg" != "no"; then
         # XXX: icu-config does not follow the "--cflags" and "--libs" convention,
         # so single it out here to avoid having to replicate all the rest of the
         # logic elsewhere.
         if test `basename "$ac_vmw_lib_cfg"` = "icu-config"; then
            $2_CPPFLAGS="`$ac_vmw_lib_cfg --cppflags`"
            $2_LIBS="`$ac_vmw_lib_cfg --ldflags`"
         else
            $2_CPPFLAGS="`$ac_vmw_lib_cfg --cflags`"
            $2_LIBS="`$ac_vmw_lib_cfg --libs`"
         fi
         ac_vmw_have_lib=1
      fi
   fi

   # Finish by executing the user provided action. The call to "true" is needed
   # because the actions are optional, and we need something inside the block.
   if test $ac_vmw_have_lib -eq 1; then
      AC_SUBST([$2_CPPFLAGS])
      AC_SUBST([$2_LIBS])
      true
      $8
   else
      true
      $9
   fi
])


#
# AC_VMW_CHECK_LIBXX(library, lvar, pkgname, lconfig, version, header, function,
#                    [action-if-found],
#                    [action-if-not-found])
#
# Similar to AC_VMW_CHECK_LIB, but for C++ libraries.
#
# XXX: Getting automake to choose between the C linker and the C++ linker
# depending on whether we're linking any C++ library was a royal pain in the
# ass. The classic way to do this is to define an optional source file for a
# program with an extension of .cxx, using nodist_EXTRA_fooprogram_SOURCES. This
# causes automake's linker detection algorithm to see a C++ source file and
# automatically set up the C++ linker and link line for us. Unfortunately, said
# linker detection doesn't obey conditionals, which means that it'd always pick
# the C++ linker, regardless of whether it's linking to a C++ library or not.
# Instead, we are forced to manually set the correct linker in fooprogram_LINK.
# However, since none of our programs actually contain C++ code, automake
# doesn't make the CXXLINK variable (which contains the linker as well as all
# link flags) available to us, so we must hard-code the entire link line into
# fooprogram_LINK. Not exactly a futureproof solution...
#
# Additional references on this problem:
# http://sources.redhat.com/ml/automake/1999-10/msg00101.html
# http://lists.gnu.org/archive/html/bug-automake/2008-04/msg00010.html
# http://www.gnu.org/software/automake/manual/automake.html#Libtool-Convenience-Libraries
# http://www.gnu.org/software/automake/manual/automake.html#C_002b_002b-Support
#
AC_DEFUN([AC_VMW_CHECK_LIBXX],[
   AC_REQUIRE([AC_VMW_CHECK_LIB])
   AC_LANG_PUSH([C++])
   AC_VMW_CHECK_LIB([$1], [$2], [$3], [$4], [$5], [$6], [$7], [$8], [$9])
   AC_LANG_POP([C++])
])


#
# AC_VMW_CHECK_X11_LIB(library, header, function, action-if-not-found)
#
# Special handling for X11 library checking. This macro checks that both the
# library provides the given function, and that the header exists, making use
# of COMMON_XLIBS when linking. On success, it modifies COMMON_XLIBS to include
# the library.
#
# library  ($1):   library name (value passed to ld with -l)
# header   ($2):   header file to look for, may be empty.
# function ($3):   function to look for in the library.
# action-if-not-found ($4): code to execute if failed to find the library.
#
#
AC_DEFUN([AC_VMW_CHECK_X11_LIB],[
   have_header=1
   if test -n "$2"; then
      AC_CHECK_HEADER(
         [X11/extensions/scrnsaver.h],
         [],
         [
          $have_header=0;
          ${action-if-not-found}
         ],
         [])
   fi

   if test $have_header = 1; then
      AC_CHECK_LIB(
         [$1],
         [$3],
         [COMMON_XLIBS="-l$1 $COMMON_XLIBS"],
         [${action-if-not-found}],
         [$COMMON_XLIBS])
   fi
])


#
# AC_VMW_LIB_ERROR(library, disable)
#
# Wrapper around AC_MSG_ERROR to print a standard message about missing libraries.
#
#     library ($1): name of missing library.
#     disable ($2): configure argument to disable usage of the library.
#     feature ($3): optional name of feature to be disabled; defaults to 'library'.
#
AC_DEFUN([AC_VMW_LIB_ERROR],[
   feature="$3"
   if test -z "$feature"; then
      feature="$1"
   fi
   AC_MSG_ERROR([Cannot find $1 library. Please configure without $feature (using --without-$2), or install the $1 libraries and devel package(s).])
])