show correct message when running configure for the switches which are on by default...
[wxWidgets.git] / acinclude.m4
1 dnl ---------------------------------------------------------------------------
2 dnl
3 dnl Macros for configure.in for wxWindows by Robert Roebling, Phil Blecker,
4 dnl Vadim Zeitlin and Ron Lee
5 dnl
6 dnl This script is under the wxWindows licence.
7 dnl
8 dnl Version: $Id$
9 dnl ---------------------------------------------------------------------------
10
11 dnl ===========================================================================
12 dnl macros to find the a file in the list of include/lib paths
13 dnl ===========================================================================
14
15 dnl ---------------------------------------------------------------------------
16 dnl call WX_PATH_FIND_INCLUDES(search path, header name), sets ac_find_includes
17 dnl to the full name of the file that was found or leaves it empty if not found
18 dnl ---------------------------------------------------------------------------
19 AC_DEFUN([WX_PATH_FIND_INCLUDES],
20 [
21 ac_find_includes=
22 for ac_dir in $1;
23   do
24     if test -f "$ac_dir/$2"; then
25       ac_find_includes=$ac_dir
26       break
27     fi
28   done
29 ])
30
31 dnl ---------------------------------------------------------------------------
32 dnl call WX_PATH_FIND_LIBRARIES(search path, header name), sets ac_find_libraries
33 dnl to the full name of the file that was found or leaves it empty if not found
34 dnl ---------------------------------------------------------------------------
35 AC_DEFUN([WX_PATH_FIND_LIBRARIES],
36 [
37 ac_find_libraries=
38 for ac_dir in $1;
39   do
40     for ac_extension in a so sl dylib; do
41       if test -f "$ac_dir/lib$2.$ac_extension"; then
42         ac_find_libraries=$ac_dir
43         break 2
44       fi
45     done
46   done
47 ])
48
49 dnl ---------------------------------------------------------------------------
50 dnl Path to include, already defined
51 dnl ---------------------------------------------------------------------------
52 AC_DEFUN([WX_INCLUDE_PATH_EXIST],
53 [
54   ac_path_to_include=$1
55   echo "$2" | grep "\-I$1" > /dev/null
56   result=$?
57   if test $result = 0; then
58     ac_path_to_include=""
59   else
60     ac_path_to_include=" -I$1"
61   fi
62 ])
63
64 dnl ---------------------------------------------------------------------------
65 dnl Path to link, already defined
66 dnl ---------------------------------------------------------------------------
67 AC_DEFUN([WX_LINK_PATH_EXIST],
68 [
69   echo "$2" | grep "\-L$1" > /dev/null
70   result=$?
71   if test $result = 0; then
72     ac_path_to_link=""
73   else
74     ac_path_to_link=" -L$1"
75   fi
76 ])
77
78 dnl ===========================================================================
79 dnl C++ features test
80 dnl ===========================================================================
81
82 dnl ---------------------------------------------------------------------------
83 dnl WX_CPP_NEW_HEADERS checks whether the compiler has "new" <iostream> header
84 dnl or only the old <iostream.h> one - it may be generally assumed that if
85 dnl <iostream> exists, the other "new" headers (without .h) exist too.
86 dnl
87 dnl call WX_CPP_NEW_HEADERS(actiof-if-true, action-if-false-or-cross-compiling)
88 dnl ---------------------------------------------------------------------------
89
90 AC_DEFUN([WX_CPP_NEW_HEADERS],
91 [
92   if test "$cross_compiling" = "yes"; then
93     ifelse([$2], , :, [$2])
94   else
95     AC_LANG_SAVE
96     AC_LANG_CPLUSPLUS
97
98     AC_CHECK_HEADERS(iostream)
99
100     if test "$ac_cv_header_iostream" = "yes" ; then
101       ifelse([$1], , :, [$1])
102     else
103       ifelse([$2], , :, [$2])
104     fi
105
106     AC_LANG_RESTORE
107   fi
108 ])
109
110 dnl ---------------------------------------------------------------------------
111 dnl WX_CPP_BOOL checks whether the C++ compiler has a built in bool type
112 dnl
113 dnl call WX_CPP_BOOL - will define HAVE_BOOL if the compiler supports bool
114 dnl ---------------------------------------------------------------------------
115
116 AC_DEFUN([WX_CPP_BOOL],
117 [
118   AC_CACHE_CHECK([if C++ compiler supports bool], wx_cv_cpp_bool,
119   [
120     AC_LANG_SAVE
121     AC_LANG_CPLUSPLUS
122
123     AC_TRY_COMPILE(
124       [
125       ],
126       [
127         bool b = true;
128
129         return 0;
130       ],
131       [
132         wx_cv_cpp_bool=yes
133       ],
134       [
135         wx_cv_cpp_bool=no
136       ]
137     )
138
139     AC_LANG_RESTORE
140   ])
141
142   if test "$wx_cv_cpp_bool" = "yes"; then
143     AC_DEFINE(HAVE_BOOL)
144   fi
145 ])
146
147 dnl ---------------------------------------------------------------------------
148 dnl WX_CPP_EXPLICIT checks whether the C++ compiler support the explicit
149 dnl keyword and defines HAVE_EXPLICIT if this is the case
150 dnl ---------------------------------------------------------------------------
151
152 AC_DEFUN([WX_CPP_EXPLICIT],
153 [
154   AC_CACHE_CHECK([if C++ compiler supports the explicit keyword],
155                  wx_cv_explicit,
156   [
157     AC_LANG_SAVE
158     AC_LANG_CPLUSPLUS
159
160     dnl do the test in 2 steps: first check that the compiler knows about the
161     dnl explicit keyword at all and then verify that it really honours it
162     AC_TRY_COMPILE(
163       [
164         class Foo { public: explicit Foo(int) {} };
165       ],
166       [
167         return 0;
168       ],
169       [
170         AC_TRY_COMPILE(
171             [
172                 class Foo { public: explicit Foo(int) {} };
173                 static void TakeFoo(const Foo& foo) { }
174             ],
175             [
176                 TakeFoo(17);
177                 return 0;
178             ],
179             wx_cv_explicit=no,
180             wx_cv_explicit=yes
181         )
182       ],
183       wx_cv_explicit=no
184     )
185
186     AC_LANG_RESTORE
187   ])
188
189   if test "$wx_cv_explicit" = "yes"; then
190     AC_DEFINE(HAVE_EXPLICIT)
191   fi
192 ])
193
194 dnl ---------------------------------------------------------------------------
195 dnl a slightly better AC_C_BIGENDIAN macro which allows cross-compiling
196 dnl ---------------------------------------------------------------------------
197
198 AC_DEFUN([WX_C_BIGENDIAN],
199 [AC_CACHE_CHECK([whether byte ordering is bigendian], ac_cv_c_bigendian,
200 [ac_cv_c_bigendian=unknown
201 # See if sys/param.h defines the BYTE_ORDER macro.
202 AC_TRY_COMPILE([#include <sys/types.h>
203 #include <sys/param.h>], [
204 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
205  bogus endian macros
206 #endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
207 AC_TRY_COMPILE([#include <sys/types.h>
208 #include <sys/param.h>], [
209 #if BYTE_ORDER != BIG_ENDIAN
210  not big endian
211 #endif], ac_cv_c_bigendian=yes, ac_cv_c_bigendian=no)])
212 if test $ac_cv_c_bigendian = unknown; then
213 AC_TRY_RUN([main () {
214   /* Are we little or big endian?  From Harbison&Steele.  */
215   union
216   {
217     long l;
218     char c[sizeof (long)];
219   } u;
220   u.l = 1;
221   exit (u.c[sizeof (long) - 1] == 1);
222 }], [ac_cv_c_bigendian=no], [ac_cv_c_bigendian=yes], [ac_cv_c_bigendian=unknown])
223 fi])
224 if test $ac_cv_c_bigendian = unknown; then
225   AC_MSG_WARN([Assuming little-endian target machine - this may be overriden by adding the line "ac_cv_c_bigendian=${ac_cv_c_bigendian='yes'}" to config.cache file])
226 fi
227 if test $ac_cv_c_bigendian = yes; then
228   AC_DEFINE(WORDS_BIGENDIAN)
229 fi
230 ])
231
232 dnl ---------------------------------------------------------------------------
233 dnl override AC_ARG_ENABLE/WITH to cache the results in .cache file
234 dnl ---------------------------------------------------------------------------
235
236 AC_DEFUN([WX_ARG_CACHE_INIT],
237         [
238           wx_arg_cache_file="configarg.cache"
239           echo "loading argument cache $wx_arg_cache_file"
240           rm -f ${wx_arg_cache_file}.tmp
241           touch ${wx_arg_cache_file}.tmp
242           touch ${wx_arg_cache_file}
243         ])
244
245 AC_DEFUN([WX_ARG_CACHE_FLUSH],
246         [
247           echo "saving argument cache $wx_arg_cache_file"
248           mv ${wx_arg_cache_file}.tmp ${wx_arg_cache_file}
249         ])
250
251 dnl this macro checks for a three-valued command line --with argument:
252 dnl   possible arguments are 'yes', 'no', 'sys', or 'builtin'
253 dnl usage: WX_ARG_SYS_WITH(option, helpmessage, variable-name)
254 AC_DEFUN([WX_ARG_SYS_WITH],
255         [
256           AC_MSG_CHECKING([for --with-$1])
257           no_cache=0
258           AC_ARG_WITH($1, [$2],
259                       [
260                         if test "$withval" = yes; then
261                           ac_cv_use_$1='$3=yes'
262                         elif test "$withval" = no; then
263                           ac_cv_use_$1='$3=no'
264                         elif test "$withval" = sys; then
265                           ac_cv_use_$1='$3=sys'
266                         elif test "$withval" = builtin; then
267                           ac_cv_use_$1='$3=builtin'
268                         else
269                           AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
270                         fi
271                       ],
272                       [
273                         LINE=`grep "$3" ${wx_arg_cache_file}`
274                         if test "x$LINE" != x ; then
275                           eval "DEFAULT_$LINE"
276                         else
277                           no_cache=1
278                         fi
279
280                         ac_cv_use_$1='$3='$DEFAULT_$3
281                       ])
282
283           eval "$ac_cv_use_$1"
284           if test "$no_cache" != 1; then
285             echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
286           fi
287
288           if test "$$3" = yes; then
289             AC_MSG_RESULT(yes)
290           elif test "$$3" = no; then
291             AC_MSG_RESULT(no)
292           elif test "$$3" = sys; then
293             AC_MSG_RESULT([system version])
294           elif test "$$3" = builtin; then
295             AC_MSG_RESULT([builtin version])
296           else
297             AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
298           fi
299         ])
300
301 dnl this macro checks for a command line argument and caches the result
302 dnl usage: WX_ARG_WITH(option, helpmessage, variable-name)
303 AC_DEFUN([WX_ARG_WITH],
304         [
305           AC_MSG_CHECKING([for --with-$1])
306           no_cache=0
307           AC_ARG_WITH($1, [$2],
308                       [
309                         if test "$withval" = yes; then
310                           ac_cv_use_$1='$3=yes'
311                         else
312                           ac_cv_use_$1='$3=no'
313                         fi
314                       ],
315                       [
316                         LINE=`grep "$3" ${wx_arg_cache_file}`
317                         if test "x$LINE" != x ; then
318                           eval "DEFAULT_$LINE"
319                         else
320                           no_cache=1
321                         fi
322
323                         ac_cv_use_$1='$3='$DEFAULT_$3
324                       ])
325
326           eval "$ac_cv_use_$1"
327           if test "$no_cache" != 1; then
328             echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
329           fi
330
331           if test "$$3" = yes; then
332             AC_MSG_RESULT(yes)
333           else
334             AC_MSG_RESULT(no)
335           fi
336         ])
337
338 dnl like WX_ARG_WITH but uses AC_ARG_ENABLE instead of AC_ARG_WITH
339 dnl usage: WX_ARG_ENABLE(option, helpmessage, variable-name, enablestring)
340 dnl
341 dnl enablestring is a hack and allows to show "checking for --disable-foo"
342 dnl message when running configure instead of the default "checking for
343 dnl --enable-foo" one whih is useful for the options enabled by default
344 AC_DEFUN([WX_ARG_ENABLE],
345         [
346           enablestring=$4
347           AC_MSG_CHECKING([for --${enablestring:-enable}-$1])
348           no_cache=0
349           AC_ARG_ENABLE($1, [$2],
350                         [
351                           if test "$enableval" = yes; then
352                             ac_cv_use_$1='$3=yes'
353                           else
354                             ac_cv_use_$1='$3=no'
355                           fi
356                         ],
357                         [
358                           LINE=`grep "$3" ${wx_arg_cache_file}`
359                           if test "x$LINE" != x ; then
360                             eval "DEFAULT_$LINE"
361                           else
362                             no_cache=1
363                           fi
364
365                           ac_cv_use_$1='$3='$DEFAULT_$3
366                         ])
367
368           eval "$ac_cv_use_$1"
369           if test "$no_cache" != 1; then
370             echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
371           fi
372
373           if test "$$3" = yes; then
374             AC_MSG_RESULT(yes)
375           else
376             AC_MSG_RESULT(no)
377           fi
378         ])
379
380
381
382 dnl ===========================================================================
383 dnl "3rd party" macros included here because they are not widely available
384 dnl ===========================================================================
385
386 dnl ---------------------------------------------------------------------------
387 dnl test for availability of iconv()
388 dnl ---------------------------------------------------------------------------
389
390 dnl From Bruno Haible.
391
392 AC_DEFUN([AM_ICONV],
393 [
394   dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
395   dnl those with the standalone portable GNU libiconv installed).
396
397   AC_ARG_WITH([libiconv-prefix],
398 [  --with-libiconv-prefix=DIR  search for libiconv in DIR/include and DIR/lib], [
399     for dir in `echo "$withval" | tr : ' '`; do
400       if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi
401       if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi
402     done
403    ])
404
405   AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
406     am_cv_func_iconv="no, consider installing GNU libiconv"
407     am_cv_lib_iconv=no
408     AC_TRY_LINK([#include <stdlib.h>
409 #include <iconv.h>],
410       [iconv_t cd = iconv_open("","");
411        iconv(cd,NULL,NULL,NULL,NULL);
412        iconv_close(cd);],
413       am_cv_func_iconv=yes)
414     if test "$am_cv_func_iconv" != yes; then
415       am_save_LIBS="$LIBS"
416       LIBS="$LIBS -liconv"
417       AC_TRY_LINK([#include <stdlib.h>
418 #include <iconv.h>],
419         [iconv_t cd = iconv_open("","");
420          iconv(cd,NULL,NULL,NULL,NULL);
421          iconv_close(cd);],
422         am_cv_lib_iconv=yes
423         am_cv_func_iconv=yes)
424       LIBS="$am_save_LIBS"
425     fi
426   ])
427   if test "$am_cv_func_iconv" = yes; then
428     AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
429     AC_CACHE_CHECK([if iconv needs const], wx_cv_func_iconv_const,
430       AC_TRY_COMPILE([
431 #include <stdlib.h>
432 #include <iconv.h>
433 extern
434 #ifdef __cplusplus
435 "C"
436 #endif
437 #if defined(__STDC__) || defined(__cplusplus)
438 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
439 #else
440 size_t iconv();
441 #endif
442         ],
443         [],
444         wx_cv_func_iconv_const="no",
445         wx_cv_func_iconv_const="yes"
446       )
447     )
448
449     iconv_const=
450     if test "x$wx_cv_func_iconv_const" = "xyes"; then
451         iconv_const="const"
452     fi
453
454     AC_DEFINE_UNQUOTED(ICONV_CONST, $iconv_const,
455       [Define as const if the declaration of iconv() needs const.])
456   fi
457   LIBICONV=
458   if test "$am_cv_lib_iconv" = yes; then
459     LIBICONV="-liconv"
460   fi
461   AC_SUBST(LIBICONV)
462 ])
463
464 dnl ---------------------------------------------------------------------------
465 dnl AC_SYS_LARGEFILE (partly based on the code from autoconf 2.5x)
466 dnl ---------------------------------------------------------------------------
467
468 dnl WX_SYS_LARGEFILE_TEST
469 dnl
470 dnl NB: original autoconf test was checking if compiler supported 6 bit off_t
471 dnl     arithmetic properly but this failed miserably with gcc under Linux
472 dnl     whereas the system still supports 64 bit files, so now simply check
473 dnl     that off_t is big enough
474 define(WX_SYS_LARGEFILE_TEST,
475 [typedef struct {
476     unsigned int field: sizeof(off_t) == 8;
477 } wxlf;
478 ])
479
480
481 dnl WX_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, CACHE-VAR)
482 define(WX_SYS_LARGEFILE_MACRO_VALUE,
483 [
484     AC_CACHE_CHECK([for $1 value needed for large files], [$3],
485         [
486           AC_TRY_COMPILE([#define $1 $2
487                           #include <sys/types.h>],
488                          WX_SYS_LARGEFILE_TEST,
489                          [$3=$2],
490                          [$3=no])
491         ]
492     )
493
494     if test "$$3" != no; then
495         wx_largefile=yes
496         AC_DEFINE_UNQUOTED([$1], [$$3])
497     fi
498 ])
499
500
501 dnl AC_SYS_LARGEFILE
502 dnl ----------------
503 dnl By default, many hosts won't let programs access large files;
504 dnl one must use special compiler options to get large-file access to work.
505 dnl For more details about this brain damage please see:
506 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
507 AC_DEFUN([AC_SYS_LARGEFILE],
508 [AC_ARG_ENABLE(largefile,
509                [  --disable-largefile     omit support for large files])
510 if test "$enable_largefile" != no; then
511     dnl _FILE_OFFSET_BITS==64 is needed for Linux, Solaris, ...
512     dnl _LARGE_FILES -- for AIX
513     wx_largefile=no
514     WX_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64, ac_cv_sys_file_offset_bits)
515     if test "x$wx_largefile" != "xyes"; then
516         WX_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1, ac_cv_sys_large_files)
517     fi
518
519     AC_MSG_CHECKING(if large file support is available)
520     if test "x$wx_largefile" = "xyes"; then
521         AC_DEFINE(HAVE_LARGEFILE_SUPPORT)
522     fi
523     AC_MSG_RESULT($wx_largefile)
524 fi
525 ])