Do not return NULL as boolean from wonder_is_lost() nor wonder_is_built()
[freeciv.git] / m4 / x.m4
blob5309dfc04b510f86477801cdedc345dbdeaac847
2 dnl FC_CHECK_X_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
3 dnl   ACTION-IF-NOT-FOUND]])
4 dnl
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".
11 dnl
12 dnl The following variables are output:
13 dnl   X_EXTRA_LIBS      -- contains "-l$1 $X_EXTRA_LIBS" if the link succeeds
14 dnl
15 dnl Thus, the intended usage of this macro is something like this:
16 dnl   AC_PATH_XTRA
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)
21 dnl     [etc.]
22 dnl   LIBS="$X_LIBS $X_EXTRA_LIBS $LIBS"
23 dnl
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,
34   [ac_save_LIBS="$LIBS"
35    LIBS="$X_LIBS -l$1 $X_EXTRA_LIBS $LIBS"
36    AC_LINK_IFELSE([AC_LANG_PROGRAM([
37     ifelse($2, main, ,
38      #ifdef __cplusplus
39        extern "C"
40       #endif
41      /* We use char because int might match the return type of a gcc2
42       builtin and then its argument prototype would still apply.  */
43       char $2();
44     )
45    ], [[$2()]])],[eval "ac_cv_lib_$ac_lib_var=yes"],[eval "ac_cv_lib_$ac_lib_var=no"])
46    LIBS="$ac_save_LIBS"
47   ])dnl
48  if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
49   AC_MSG_RESULT(yes)
50   ifelse([$3], ,
51    [changequote(, )dnl
52     ac_tr_lib=HAVE_LIB`echo $1 | $SED -e 's/[^a-zA-Z0-9_]/_/g' \
53     -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
54     changequote([, ])dnl
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"
74     else
75       AC_MSG_ERROR([Invalid define of $ac_tr_lib in $1])
76     fi
77    ], [$3])
78  else
79   AC_MSG_RESULT(no)
80  ifelse([$4], , , [$4
81  ])dnl
82  fi
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], [
93         $1=$2
94         $1=`(
95             test "x$prefix" = xNONE && prefix="$ac_default_prefix"
96             test "x$exec_prefix" = xNONE && exec_prefix="${prefix}"
97             eval echo \""[$]$1"\"
98         )`
102 dnl FC_XPM_PATHS
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"
124 else
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
142     xpm_libdir="no"
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
147             break
148         fi
149     done
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
154     xpm_incdir="no"
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
160         xpm_h_no_x11=yes
161     fi
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:
173 dnl   FUNCPROTO
174 dnl   NARROWPROTO
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.
181 dnl Example use:
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)
185 dnl   fi
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:
191 fc_x_proto_value=
192 for fc_x_define in $fc_x_proto_defines; do
193   fc_x_val=1
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
197     break
198   fi
199 done
200 if test -n "$fc_x_proto_value"; then
201   AC_MSG_RESULT([yes: $fc_x_proto_value])
202 else
203   AC_MSG_RESULT([no])
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).
218 dnl Example use:
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
230   fc_x_proto_defines=
231   rm -fr conftestdir
232   if mkdir conftestdir; then
233     cd conftestdir
234     # Make sure to not put "make" in the Imakefile rules, since we grep it out.
235     cat > Imakefile <<'EOF'
236 fcfindpd:
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])
243       cd ..
244       rm -fr conftestdir
245     else
246       dnl Oops -- no/bad xmkmf... Time to go a-guessing...
247       AC_MSG_RESULT([no])
248       cd ..
249       rm -fr conftestdir
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
256           break
257         fi
258       done
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])
262       else
263         AC_MSG_RESULT([no, cannot determine])
264       fi
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
271           break
272         fi
273       done
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])
277       else
278         AC_MSG_RESULT([no, cannot determine])
279       fi
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])
283       else
284         AC_MSG_RESULT([no])
285       fi
286     fi
287   else
288     AC_MSG_RESULT([no, examination failed])
289   fi
290 else
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:
302 dnl   15, 11, 3, 1, ""
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.
309 dnl Example use:
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
313 dnl   fi
315 AC_DEFUN([FC_CHECK_X_PROTO_FUNCPROTO_COMPILE],
316 [AC_REQUIRE([AC_PATH_XTRA])dnl
317 AC_LANG_PUSH([C])
318 fc_x_proto_FUNCPROTO=no
319 if test "x$1" = "x"; then
320   fc_x_compile="#undef FUNCPROTO"
321 else
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([[
327 $fc_x_compile
328 #include <X11/Xfuncproto.h>
329   ]], [[
330 exit (0)
331   ]])],[fc_x_proto_FUNCPROTO=$1],[])
332 CFLAGS="$fc_x_save_CFLAGS"
333 AC_LANG_POP([C])
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:
342 dnl   1, ""
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.
352 dnl Example use:
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
356 dnl   fi
358 AC_DEFUN([FC_CHECK_X_PROTO_NARROWPROTO_WORKS],
359 [AC_REQUIRE([AC_PATH_XTRA])dnl
360 AC_LANG_PUSH([C])
361 fc_x_proto_NARROWPROTO=no
362 if test "x$1" = "x"; then
363   fc_x_works="#undef NARROWPROTO"
364 else
365   fc_x_works="#define NARROWPROTO $1"
367 if test "x$fc_x_proto_FUNCPROTO" = "x"; then
368   fc_x_compile="#define FUNCPROTO 1"
369 else
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([[
375 $fc_x_works
376 $fc_x_compile
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)
385   Widget toplevel;
386   XtAppContext appcon;
387   Widget scrollbar;
388   double topbuf;
389   double shownbuf;
390   float * top = (float *)(&topbuf);
391   float * shown = (float *)(&shownbuf);
392   toplevel =
393     XtAppInitialize
394     (
395      &appcon,
396      "FcXTest",
397      NULL, 0,
398      &argc, argv,
399      NULL,
400      NULL, 0
401     );
402   scrollbar =
403     XtVaCreateManagedWidget
404     (
405      "my_scrollbar",
406      scrollbarWidgetClass,
407      toplevel,
408      NULL
409     );
410   XawScrollbarSetThumb (scrollbar, TOP_VAL, SHOWN_VAL);
411   XtVaGetValues
412   (
413    scrollbar,
414    XtNtopOfThumb, top,
415    XtNshown, shown,
416    NULL
417   );
418   if ((*top == TOP_VAL) && (*shown == SHOWN_VAL))
419     {
420       exit (0);
421     }
422   else
423     {
424       exit (1);
425     }
426   return (0);
428   ]])],[fc_x_proto_NARROWPROTO=$1],[],[:])
429 CFLAGS="$fc_x_save_CFLAGS"
430 AC_LANG_POP([C])