1 dnl ---------------------------------------------------------------------------
3 dnl Macros for configure.in for wxWindows by Robert Roebling, Phil Blecker,
4 dnl Vadim Zeitlin and Ron Lee
6 dnl This script is under the wxWindows licence.
9 dnl ---------------------------------------------------------------------------
11 dnl ===========================================================================
12 dnl macros to find the a file in the list of include/lib paths
13 dnl ===========================================================================
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],
22 for ac_dir in $1 /usr/include;
24 if test -f "$ac_dir/$2"; then
25 ac_find_includes=$ac_dir
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],
38 for ac_dir in $1 /usr/lib;
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
49 dnl ---------------------------------------------------------------------------
50 dnl Path to include, already defined
51 dnl ---------------------------------------------------------------------------
52 AC_DEFUN([WX_INCLUDE_PATH_EXIST],
54 dnl never add -I/usr/include to the CPPFLAGS
55 if test "x$1" = "x/usr/include"; then
58 echo "$2" | grep "\-I$1" > /dev/null
60 if test $result = 0; then
63 ac_path_to_include=" -I$1"
68 dnl ---------------------------------------------------------------------------
69 dnl Path to link, already defined
70 dnl ---------------------------------------------------------------------------
71 AC_DEFUN([WX_LINK_PATH_EXIST],
73 echo "$2" | grep "\-L$1" > /dev/null
75 if test $result = 0; then
78 ac_path_to_link=" -L$1"
82 dnl ===========================================================================
84 dnl ===========================================================================
86 dnl ---------------------------------------------------------------------------
87 dnl WX_CPP_NEW_HEADERS checks whether the compiler has "new" <iostream> header
88 dnl or only the old <iostream.h> one - it may be generally assumed that if
89 dnl <iostream> exists, the other "new" headers (without .h) exist too.
91 dnl call WX_CPP_NEW_HEADERS(actiof-if-true, action-if-false)
92 dnl ---------------------------------------------------------------------------
94 AC_DEFUN([WX_CPP_NEW_HEADERS],
99 AC_CHECK_HEADERS(iostream)
101 if test "$ac_cv_header_iostream" = "yes" ; then
102 ifelse([$1], , :, [$1])
104 ifelse([$2], , :, [$2])
110 dnl ---------------------------------------------------------------------------
111 dnl WX_CPP_BOOL checks whether the C++ compiler has a built in bool type
113 dnl call WX_CPP_BOOL - will define HAVE_BOOL if the compiler supports bool
114 dnl ---------------------------------------------------------------------------
116 AC_DEFUN([WX_CPP_BOOL],
118 AC_CACHE_CHECK([if C++ compiler supports bool], wx_cv_cpp_bool,
142 if test "$wx_cv_cpp_bool" = "yes"; then
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 ---------------------------------------------------------------------------
152 AC_DEFUN([WX_CPP_EXPLICIT],
154 AC_CACHE_CHECK([if C++ compiler supports the explicit keyword],
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
164 class Foo { public: explicit Foo(int) {} };
172 class Foo { public: explicit Foo(int) {} };
173 static void TakeFoo(const Foo& foo) { }
189 if test "$wx_cv_explicit" = "yes"; then
190 AC_DEFINE(HAVE_EXPLICIT)
194 dnl ---------------------------------------------------------------------------
195 dnl a slightly better AC_C_BIGENDIAN macro which allows cross-compiling
196 dnl ---------------------------------------------------------------------------
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
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
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. */
218 char c[sizeof (long)];
221 exit (u.c[sizeof (long) - 1] == 1);
222 }], [ac_cv_c_bigendian=no], [ac_cv_c_bigendian=yes], [ac_cv_c_bigendian=unknown])
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])
227 if test $ac_cv_c_bigendian = yes; then
228 AC_DEFINE(WORDS_BIGENDIAN)
232 dnl ---------------------------------------------------------------------------
233 dnl override AC_ARG_ENABLE/WITH to cache the results in .cache file
234 dnl ---------------------------------------------------------------------------
236 AC_DEFUN([WX_ARG_CACHE_INIT],
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}
245 AC_DEFUN([WX_ARG_CACHE_FLUSH],
247 echo "saving argument cache $wx_arg_cache_file"
248 mv ${wx_arg_cache_file}.tmp ${wx_arg_cache_file}
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],
256 AC_MSG_CHECKING([for --with-$1])
258 AC_ARG_WITH($1, [$2],
260 if test "$withval" = yes; then
261 ac_cv_use_$1='$3=yes'
262 elif test "$withval" = no; then
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'
269 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
273 LINE=`grep "$3" ${wx_arg_cache_file}`
274 if test "x$LINE" != x ; then
280 ac_cv_use_$1='$3='$DEFAULT_$3
284 if test "$no_cache" != 1; then
285 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
288 if test "$$3" = yes; then
290 elif test "$$3" = no; then
292 elif test "$$3" = sys; then
293 AC_MSG_RESULT([system version])
294 elif test "$$3" = builtin; then
295 AC_MSG_RESULT([builtin version])
297 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
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],
305 AC_MSG_CHECKING([for --with-$1])
307 AC_ARG_WITH($1, [$2],
309 if test "$withval" = yes; then
310 ac_cv_use_$1='$3=yes'
316 LINE=`grep "$3" ${wx_arg_cache_file}`
317 if test "x$LINE" != x ; then
323 ac_cv_use_$1='$3='$DEFAULT_$3
327 if test "$no_cache" != 1; then
328 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
331 if test "$$3" = yes; then
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)
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],
347 AC_MSG_CHECKING([for --${enablestring:-enable}-$1])
349 AC_ARG_ENABLE($1, [$2],
351 if test "$enableval" = yes; then
352 ac_cv_use_$1='$3=yes'
358 LINE=`grep "$3" ${wx_arg_cache_file}`
359 if test "x$LINE" != x ; then
365 ac_cv_use_$1='$3='$DEFAULT_$3
369 if test "$no_cache" != 1; then
370 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
373 if test "$$3" = yes; then
381 dnl ===========================================================================
382 dnl Linker features test
383 dnl ===========================================================================
385 dnl ---------------------------------------------------------------------------
386 dnl WX_VERSIONED_SYMBOLS checks whether the linker can create versioned
387 dnl symbols. If it can, sets LDFLAGS_VERSIONING to $CXX flags needed to use
388 dnl version script file named versionfile
390 dnl call WX_VERSIONED_SYMBOLS(versionfile)
391 dnl ---------------------------------------------------------------------------
392 AC_DEFUN([WX_VERSIONED_SYMBOLS],
396 dnl FIXME - doesn't work, Solaris linker doesn't accept wildcards
398 dnl dnl Check for known non-gcc cases:
399 dnl case "${host}" in
401 dnl if test "x$GCC" != "xyes" ; then
402 dnl LDFLAGS_VERSIONING="-M $1"
403 dnl found_versioning=yes
408 dnl Generic check for GCC or GCC-like behaviour (Intel C++, GCC):
409 if test $found_versioning = no ; then
410 AC_CACHE_CHECK([if the linker accepts --version-script], wx_cv_version_script,
412 echo "VER_1 { *; };" >conftest.sym
413 echo "int main() { return 0; }" >conftest.cpp
416 $CXX -o conftest.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
417 -Wl,--version-script,conftest.sym >/dev/null 2>conftest.stderr]) ; then
418 if test -s conftest.stderr ; then
419 wx_cv_version_script=no
421 wx_cv_version_script=yes
424 wx_cv_version_script=no
426 rm -f conftest.output conftest.stderr conftest.sym conftest.cpp
428 if test $wx_cv_version_script = yes ; then
429 LDFLAGS_VERSIONING="-Wl,--version-script,$1"
435 dnl ===========================================================================
436 dnl "3rd party" macros included here because they are not widely available
437 dnl ===========================================================================
439 dnl ---------------------------------------------------------------------------
440 dnl test for availability of iconv()
441 dnl ---------------------------------------------------------------------------
443 dnl From Bruno Haible.
447 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
448 dnl those with the standalone portable GNU libiconv installed).
450 AC_ARG_WITH([libiconv-prefix],
451 [ --with-libiconv-prefix=DIR search for libiconv in DIR/include and DIR/lib], [
452 for dir in `echo "$withval" | tr : ' '`; do
453 if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi
454 if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi
458 AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
459 am_cv_func_iconv="no, consider installing GNU libiconv"
461 AC_TRY_LINK([#include <stdlib.h>
463 [iconv_t cd = iconv_open("","");
464 iconv(cd,NULL,NULL,NULL,NULL);
466 am_cv_func_iconv=yes)
467 if test "$am_cv_func_iconv" != yes; then
470 AC_TRY_LINK([#include <stdlib.h>
472 [iconv_t cd = iconv_open("","");
473 iconv(cd,NULL,NULL,NULL,NULL);
476 am_cv_func_iconv=yes)
480 if test "$am_cv_func_iconv" = yes; then
481 AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
482 AC_CACHE_CHECK([if iconv needs const], wx_cv_func_iconv_const,
490 #if defined(__STDC__) || defined(__cplusplus)
491 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
497 wx_cv_func_iconv_const="no",
498 wx_cv_func_iconv_const="yes"
503 if test "x$wx_cv_func_iconv_const" = "xyes"; then
507 AC_DEFINE_UNQUOTED(ICONV_CONST, $iconv_const,
508 [Define as const if the declaration of iconv() needs const.])
511 if test "$am_cv_lib_iconv" = yes; then
517 dnl ---------------------------------------------------------------------------
518 dnl AC_SYS_LARGEFILE (partly based on the code from autoconf 2.5x)
519 dnl ---------------------------------------------------------------------------
521 dnl WX_SYS_LARGEFILE_TEST
523 dnl NB: original autoconf test was checking if compiler supported 6 bit off_t
524 dnl arithmetic properly but this failed miserably with gcc under Linux
525 dnl whereas the system still supports 64 bit files, so now simply check
526 dnl that off_t is big enough
527 define(WX_SYS_LARGEFILE_TEST,
529 unsigned int field: sizeof(off_t) == 8;
534 dnl WX_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, CACHE-VAR)
535 define(WX_SYS_LARGEFILE_MACRO_VALUE,
537 AC_CACHE_CHECK([for $1 value needed for large files], [$3],
539 AC_TRY_COMPILE([#define $1 $2
540 #include <sys/types.h>],
541 WX_SYS_LARGEFILE_TEST,
547 if test "$$3" != no; then
549 AC_DEFINE_UNQUOTED([$1], [$$3])
556 dnl By default, many hosts won't let programs access large files;
557 dnl one must use special compiler options to get large-file access to work.
558 dnl For more details about this brain damage please see:
559 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
560 AC_DEFUN([AC_SYS_LARGEFILE],
561 [AC_ARG_ENABLE(largefile,
562 [ --disable-largefile omit support for large files])
563 if test "$enable_largefile" != no; then
564 dnl _FILE_OFFSET_BITS==64 is needed for Linux, Solaris, ...
565 dnl _LARGE_FILES -- for AIX
567 WX_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64, ac_cv_sys_file_offset_bits)
568 if test "x$wx_largefile" != "xyes"; then
569 WX_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1, ac_cv_sys_large_files)
572 AC_MSG_CHECKING(if large file support is available)
573 if test "x$wx_largefile" = "xyes"; then
574 AC_DEFINE(HAVE_LARGEFILE_SUPPORT)
576 AC_MSG_RESULT($wx_largefile)
581 dnl Available from the GNU Autoconf Macro Archive at:
582 dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_const_cast.html
584 AC_DEFUN([AC_CXX_CONST_CAST],
585 [AC_CACHE_CHECK(whether the compiler supports const_cast<>,
586 ac_cv_cxx_const_cast,
589 AC_TRY_COMPILE(,[int x = 0;const int& y = x;int& z = const_cast<int&>(y);return z;],
590 ac_cv_cxx_const_cast=yes, ac_cv_cxx_const_cast=no)
593 if test "$ac_cv_cxx_const_cast" = yes; then
594 AC_DEFINE(HAVE_CONST_CAST,,[define if the compiler supports const_cast<>])
598 dnl and http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_static_cast.html
599 AC_DEFUN([AC_CXX_STATIC_CAST],
600 [AC_CACHE_CHECK(whether the compiler supports static_cast<>,
601 ac_cv_cxx_static_cast,
604 AC_TRY_COMPILE([#include <typeinfo>
605 class Base { public : Base () {} virtual void f () = 0; };
606 class Derived : public Base { public : Derived () {} virtual void f () {} };
607 int g (Derived&) { return 0; }],[
608 Derived d; Base& b = d; Derived& s = static_cast<Derived&> (b); return g (s);],
609 ac_cv_cxx_static_cast=yes, ac_cv_cxx_static_cast=no)
612 if test "$ac_cv_cxx_static_cast" = yes; then
613 AC_DEFINE(HAVE_STATIC_CAST,, [define if the compiler supports static_cast<>])