2 dnl FC_CHECK_X_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
3 dnl ACTION-IF-NOT-FOUND]])
5 dnl This macro is intended to search for X11-related libraries. It takes the
6 dnl following variables for input:
7 dnl X_LIBS -- prefixed to all linker lines
8 dnl X_EXTRA_LIBS -- suffixed to all linker lines
9 dnl LIBS -- suffixed to all linker lines (after X_EXTRA_LIBS)
10 dnl Thus, the trial linker line will be "$X_LIBS -l$1 $X_EXTRA_LIBS $LIBS".
12 dnl The following variables are output:
13 dnl X_EXTRA_LIBS -- contains "-l$1 $X_EXTRA_LIBS" if the link succeeds
15 dnl Thus, the intended usage of this macro is something like this:
17 dnl X_LIBS="$X_LIBS $X_PRE_LIBS"
18 dnl dnl Is it just me or is AC_PATH_XTRA broken?
19 dnl FC_CHECK_X_LIB(X11, XOpenDisplay, , AC_MSG_ERROR("Need X11"))
20 dnl FC_CHECK_X_LIB(Xext, XShapeCombineMask)
22 dnl LIBS="$X_LIBS $X_EXTRA_LIBS $LIBS"
24 AC_DEFUN([FC_CHECK_X_LIB], [
25 AC_MSG_CHECKING([for $2 in X library -l$1])
27 dnl Use a cache variable name containing both the library and function name,
28 dnl because the test really is for library $1 defining function $2, not
29 dnl just for library $1. Separate tests with the same $1 and different $2s
30 dnl may have different results.
32 ac_lib_var=`echo $1['_']$2 | $SED 'y%./+-%__p_%'`
33 AC_CACHE_VAL(ac_cv_lib_$ac_lib_var,
35 LIBS="$X_LIBS -l$1 $X_EXTRA_LIBS $LIBS"
36 AC_LINK_IFELSE([AC_LANG_PROGRAM([
41 /* We use char because int might match the return type of a gcc2
42 builtin and then its argument prototype would still apply. */
45 ], [[$2()]])],[eval "ac_cv_lib_$ac_lib_var=yes"],[eval "ac_cv_lib_$ac_lib_var=no"])
48 if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
52 ac_tr_lib=HAVE_LIB`echo $1 | $SED -e 's/[^a-zA-Z0-9_]/_/g' \
53 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
56 # The HAVE_LIBX** values are defined in FC_CHECK_X_LIB, but we need an
57 # AH_TEMPLATE for them so that autoheader will know about them.
58 AH_TEMPLATE([HAVE_LIBX11], [Define if the X11 lib is available])
59 AH_TEMPLATE([HAVE_LIBXEXT], [Define if the Xext lib is available])
60 AH_TEMPLATE([HAVE_LIBXT], [Define if the Xt lib is available])
61 AH_TEMPLATE([HAVE_LIBXMU], [Define if the Xmu lib is available])
62 AH_TEMPLATE([HAVE_LIBXPM], [Define if the Xpm lib is available])
63 AH_TEMPLATE([HAVE_LIBXAW], [Define if the Xaw lib is to be used])
64 AH_TEMPLATE([HAVE_LIBXAW3D], [Define if the Xaw3d lib is to be used])
65 if (test $ac_tr_lib = HAVE_LIBX11 \
66 || test $ac_tr_lib = HAVE_LIBXEXT \
67 || test $ac_tr_lib = HAVE_LIBXT \
68 || test $ac_tr_lib = HAVE_LIBXMU \
69 || test $ac_tr_lib = HAVE_LIBXPM \
70 || test $ac_tr_lib = HAVE_LIBXAW \
71 || test $ac_tr_lib = HAVE_LIBXAW3D); then
72 AC_DEFINE_UNQUOTED([$ac_tr_lib], [1], [Have $ac_tr_lib])
73 X_EXTRA_LIBS="-l$1 $X_EXTRA_LIBS"
75 AC_MSG_ERROR([Invalid define of $ac_tr_lib in $1])
85 dnl FC_EXPAND_DIR(VARNAME, DIR)
86 dnl expands occurrences of ${prefix} and ${exec_prefix} in the given DIR,
87 dnl and assigns the resulting string to VARNAME
88 dnl example: FC_EXPAND_DIR(LOCALEDIR, "$datadir/locale")
89 dnl eg, then: AC_DEFINE_UNQUOTED(LOCALEDIR, "$LOCALEDIR")
90 dnl by Alexandre Oliva
91 dnl from http://www.cygnus.com/ml/automake/1998-Aug/0040.html
92 AC_DEFUN([FC_EXPAND_DIR], [
95 test "x$prefix" = xNONE && prefix="$ac_default_prefix"
96 test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
103 dnl Allow user to specify extra include/lib paths for Xpm, with
104 dnl --with-xpm=prefix --with-xpm-lib=dir --with-xpm-include=dir
105 dnl The latter two override the prefix form.
106 dnl Sets variables xpm_libdir and xpm_incdir
107 dnl If user supplies a path, use that.
108 dnl If user specifies "no", set that, meaning "no extra path"
109 dnl If user specifies "yes" (default), then use /usr/local if it looks
110 dnl likely, else set to "no".
111 dnl Doesn't do any cache stuff.
113 AC_DEFUN([FC_XPM_PATHS],
114 [AC_MSG_CHECKING(extra paths for Xpm)
115 dnl General Xpm prefix:
116 dnl "no" means no prefix is required, "yes" means try /usr/local
117 AC_ARG_WITH([xpm-prefix],
118 AS_HELP_STRING([--with-xpm-prefix=DIR], [Xpm files are in DIR/lib and DIR/include, or use the following to set them separately]),
119 [xpm_prefix="$withval"], [xpm_prefix="yes"])
121 if test "$xpm_prefix" = "yes" || test "$xpm_prefix" = "no"; then
122 xpm_libdir="$xpm_prefix"
123 xpm_incdir="$xpm_prefix"
125 xpm_libdir="$xpm_prefix/lib"
126 xpm_incdir="$xpm_prefix/include"
129 dnl May override general Xpm prefix with explicit individual paths:
130 AC_ARG_WITH([xpm-lib],
131 AS_HELP_STRING([--with-xpm-lib=DIR], [Xpm library is in DIR]),
132 [xpm_libdir="$withval"])
134 AC_ARG_WITH([xpm-include],
135 AS_HELP_STRING([--with-xpm-include=DIR], [Xpm header file is in DIR (that is, DIR/X11/xpm.h)]),
136 [xpm_incdir="$withval"])
138 dnl If xpm-lib path was not specified, try /usr/local/lib if that
139 dnl looks likely; we don't actually try to link.
140 fc_xpm_default=/usr/local
141 if test "$xpm_libdir" = "yes"; then
143 fc_xpm_default_lib="$fc_xpm_default/lib"
144 for fc_extension in a so sl; do
145 if test -r $fc_xpm_default_lib/libXpm.$fc_extension; then
146 xpm_libdir=$fc_xpm_default_lib
151 dnl Likewise for xpm-include with /usr/local/include;
152 dnl we don't actually try to include.
153 if test "$xpm_incdir" = "yes"; then
155 fc_xpm_default_inc="$fc_xpm_default/include"
156 if test -r $fc_xpm_default_inc/X11/xpm.h; then
157 xpm_incdir=$fc_xpm_default_inc
158 elif test -r $fc_xpm_default_inc/xpm.h; then
159 xpm_incdir=$fc_xpm_default_inc
163 AC_MSG_RESULT([library $xpm_libdir, include $xpm_incdir])
167 dnl FC_CHECK_X_PROTO_DEFINE(DEFINED-VARIABLE)
169 dnl This macro determines the value of the given defined
170 dnl variable needed by Xfuncproto.h in order to compile correctly.
172 dnl Typical DEFINED-VARIABLEs are:
176 dnl The following variables are output:
177 dnl fc_x_proto_value -- contains the value to which
178 dnl the DEFINED-VARIABLE is set,
179 dnl or "" if it has no known value.
182 dnl FC_CHECK_X_PROTO_DEFINE(FUNCPROTO)
183 dnl if test -n "$fc_x_proto_value"; then
184 dnl AC_DEFINE_UNQUOTED(FUNCPROTO, $fc_x_proto_value)
187 AC_DEFUN([FC_CHECK_X_PROTO_DEFINE],
188 [AC_REQUIRE([FC_CHECK_X_PROTO_FETCH])dnl
189 AC_MSG_CHECKING(for Xfuncproto control definition $1)
190 # Search for the requested defined variable; return it's value:
192 for fc_x_define in $fc_x_proto_defines; do
194 eval `echo $fc_x_define | $SED -e 's/=/ ; fc_x_val=/' | $SED -e 's/^/fc_x_var=/'`
195 if test "x$fc_x_var" = "x$1"; then
196 fc_x_proto_value=$fc_x_val
200 if test -n "$fc_x_proto_value"; then
201 AC_MSG_RESULT([yes: $fc_x_proto_value])
207 dnl FC_CHECK_X_PROTO_FETCH
209 dnl This macro fetches the Xfuncproto control definitions.
210 dnl (Intended to be called once from FC_CHECK_X_PROTO_DEFINE.)
212 dnl The following variables are output:
213 dnl fc_x_proto_defines -- contains the list of defines of
214 dnl Xfuncproto control definitions
215 dnl (defines may or may not include
216 dnl the -D prefix, or an =VAL part).
219 dnl AC_REQUIRE([FC_CHECK_X_PROTO_FETCH])
221 AC_DEFUN([FC_CHECK_X_PROTO_FETCH],
222 [AC_REQUIRE([AC_PATH_X])dnl
223 AC_MSG_CHECKING(whether Xfuncproto was supplied)
224 dnl May override determined defines with explicit argument:
225 AC_ARG_WITH([x-funcproto],
226 AS_HELP_STRING([--with-x-funcproto=DEFS], [Xfuncproto control definitions are DEFS (e.g.: --with-x-funcproto='FUNCPROTO=15 NARROWPROTO'])dnl
229 if test "x$with_x_funcproto" = "x"; then
232 if mkdir conftestdir; then
234 # Make sure to not put "make" in the Imakefile rules, since we grep it out.
235 cat > Imakefile <<'EOF'
237 @echo 'fc_x_proto_defines=" ${PROTO_DEFINES}"'
239 if (xmkmf) >/dev/null 2>/dev/null && test -f Makefile; then
240 # GNU make sometimes prints "make[1]: Entering...", which would confuse us.
241 eval `${MAKE-make} fcfindpd 2>/dev/null | grep -v make | $SED -e 's/ -D/ /g'`
242 AC_MSG_RESULT([no, found: $fc_x_proto_defines])
246 dnl Oops -- no/bad xmkmf... Time to go a-guessing...
250 dnl First, guess something for FUNCPROTO:
251 AC_MSG_CHECKING([for compilable FUNCPROTO definition])
252 dnl Try in order of preference...
253 for fc_x_value in 15 11 3 1 ""; do
254 FC_CHECK_X_PROTO_FUNCPROTO_COMPILE($fc_x_value)
255 if test "x$fc_x_proto_FUNCPROTO" != "xno"; then
259 if test "x$fc_x_proto_FUNCPROTO" != "xno"; then
260 fc_x_proto_defines="$fc_x_proto_defines FUNCPROTO=$fc_x_proto_FUNCPROTO"
261 AC_MSG_RESULT([yes, determined: $fc_x_proto_FUNCPROTO])
263 AC_MSG_RESULT([no, cannot determine])
265 dnl Second, guess something for NARROWPROTO:
266 AC_MSG_CHECKING([for workable NARROWPROTO definition])
267 dnl Try in order of preference...
268 for fc_x_value in 1 ""; do
269 FC_CHECK_X_PROTO_NARROWPROTO_WORKS($fc_x_value)
270 if test "x$fc_x_proto_NARROWPROTO" != "xno"; then
274 if test "x$fc_x_proto_NARROWPROTO" != "xno"; then
275 fc_x_proto_defines="$fc_x_proto_defines NARROWPROTO=$fc_x_proto_NARROWPROTO"
276 AC_MSG_RESULT([yes, determined: $fc_x_proto_NARROWPROTO])
278 AC_MSG_RESULT([no, cannot determine])
280 AC_MSG_CHECKING(whether Xfuncproto was determined)
281 if test -n "$fc_x_proto_defines"; then
282 AC_MSG_RESULT([yes: $fc_x_proto_defines])
288 AC_MSG_RESULT([no, examination failed])
291 fc_x_proto_defines=$with_x_funcproto
292 AC_MSG_RESULT([yes, given: $fc_x_proto_defines])
296 dnl FC_CHECK_X_PROTO_FUNCPROTO_COMPILE(FUNCPROTO-VALUE)
298 dnl This macro determines whether or not Xfuncproto.h will
299 dnl compile given a value to use for the FUNCPROTO definition.
301 dnl Typical FUNCPROTO-VALUEs are:
304 dnl The following variables are output:
305 dnl fc_x_proto_FUNCPROTO -- contains the passed-in
306 dnl FUNCPROTO-VALUE if Xfuncproto.h
307 dnl compiled, or "no" if it did not.
310 dnl FC_CHECK_X_PROTO_FUNCPROTO_COMPILE($fc_x_value)
311 dnl if test "x$fc_x_proto_FUNCPROTO" != "xno"; then
312 dnl echo Compile using FUNCPROTO=$fc_x_proto_FUNCPROTO
315 AC_DEFUN([FC_CHECK_X_PROTO_FUNCPROTO_COMPILE],
316 [AC_REQUIRE([AC_PATH_XTRA])dnl
318 fc_x_proto_FUNCPROTO=no
319 if test "x$1" = "x"; then
320 fc_x_compile="#undef FUNCPROTO"
322 fc_x_compile="#define FUNCPROTO $1"
324 fc_x_save_CFLAGS="$CFLAGS"
325 CFLAGS="$CFLAGS $X_CFLAGS"
326 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
328 #include <X11/Xfuncproto.h>
331 ]])],[fc_x_proto_FUNCPROTO=$1],[])
332 CFLAGS="$fc_x_save_CFLAGS"
336 dnl FC_CHECK_X_PROTO_NARROWPROTO_WORKS(NARROWPROTO-VALUE)
338 dnl This macro determines whether or not NARROWPROTO is required
339 dnl to get a typical X function (XawScrollbarSetThumb) to work.
341 dnl Typical NARROWPROTO-VALUEs are:
344 dnl The following variables are required for input:
345 dnl fc_x_proto_FUNCPROTO -- the value to use for FUNCPROTO.
347 dnl The following variables are output:
348 dnl fc_x_proto_NARROWPROTO -- contains the passed-in
349 dnl NARROWPROTO-VALUE if the test
350 dnl worked, or "no" if it did not.
353 dnl FC_CHECK_X_PROTO_NARROWPROTO_WORKS($fc_x_value)
354 dnl if test "x$fc_x_proto_NARROWPROTO" != "xno"; then
355 dnl echo Compile using NARROWPROTO=$fc_x_proto_NARROWPROTO
358 AC_DEFUN([FC_CHECK_X_PROTO_NARROWPROTO_WORKS],
359 [AC_REQUIRE([AC_PATH_XTRA])dnl
361 fc_x_proto_NARROWPROTO=no
362 if test "x$1" = "x"; then
363 fc_x_works="#undef NARROWPROTO"
365 fc_x_works="#define NARROWPROTO $1"
367 if test "x$fc_x_proto_FUNCPROTO" = "x"; then
368 fc_x_compile="#define FUNCPROTO 1"
370 fc_x_compile="#define FUNCPROTO $fc_x_proto_FUNCPROTO"
372 fc_x_save_CFLAGS="$CFLAGS"
373 CFLAGS="$CFLAGS $X_CFLAGS $X_LIBS $X_PRE_LIBS -lXaw -lXt -lX11 $X_EXTRA_LIBS"
374 AC_RUN_IFELSE([AC_LANG_SOURCE([[
377 #include <X11/Xfuncproto.h>
378 #include <X11/Intrinsic.h>
379 #include <X11/StringDefs.h>
380 #include <X11/Xaw/Scrollbar.h>
381 #define TOP_VAL 0.125
382 #define SHOWN_VAL 0.25
383 int main (int argc, char ** argv)
390 float * top = (float *)(&topbuf);
391 float * shown = (float *)(&shownbuf);
403 XtVaCreateManagedWidget
406 scrollbarWidgetClass,
410 XawScrollbarSetThumb (scrollbar, TOP_VAL, SHOWN_VAL);
418 if ((*top == TOP_VAL) && (*shown == SHOWN_VAL))
428 ]])],[fc_x_proto_NARROWPROTO=$1],[],[:])
429 CFLAGS="$fc_x_save_CFLAGS"