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 ---------------------------------------------------------------------------
12 dnl ===========================================================================
13 dnl Objective-C(++) related macros
14 dnl ===========================================================================
15 m4_define([AC_WX_LANG_OBJECTIVEC],
20 m4_define([AC_WX_LANG_OBJECTIVECPLUSPLUS],
25 dnl ===========================================================================
26 dnl macros to find the a file in the list of include/lib paths
27 dnl ===========================================================================
29 dnl ---------------------------------------------------------------------------
30 dnl call WX_PATH_FIND_INCLUDES(search path, header name), sets ac_find_includes
31 dnl to the full name of the file that was found or leaves it empty if not found
32 dnl ---------------------------------------------------------------------------
33 AC_DEFUN([WX_PATH_FIND_INCLUDES],
36 for ac_dir in $1 /usr/include;
38 if test -f "$ac_dir/$2"; then
39 ac_find_includes=$ac_dir
45 dnl ---------------------------------------------------------------------------
46 dnl call WX_PATH_FIND_LIBRARIES(search path, header name), sets ac_find_libraries
47 dnl to the full name of the file that was found or leaves it empty if not found
48 dnl ---------------------------------------------------------------------------
49 AC_DEFUN([WX_PATH_FIND_LIBRARIES],
52 for ac_dir in $1 /usr/lib;
54 for ac_extension in a so sl dylib; do
55 if test -f "$ac_dir/lib$2.$ac_extension"; then
56 ac_find_libraries=$ac_dir
63 dnl ---------------------------------------------------------------------------
64 dnl Path to include, already defined
65 dnl ---------------------------------------------------------------------------
66 AC_DEFUN([WX_INCLUDE_PATH_EXIST],
68 dnl never add -I/usr/include to the CPPFLAGS
69 if test "x$1" = "x/usr/include"; then
72 echo "$2" | grep "\-I$1" > /dev/null
74 if test $result = 0; then
77 ac_path_to_include=" -I$1"
82 dnl ---------------------------------------------------------------------------
83 dnl Path to link, already defined
84 dnl ---------------------------------------------------------------------------
85 AC_DEFUN([WX_LINK_PATH_EXIST],
87 echo "$2" | grep "\-L$1" > /dev/null
89 if test $result = 0; then
92 ac_path_to_link=" -L$1"
96 dnl ===========================================================================
98 dnl ===========================================================================
100 dnl ---------------------------------------------------------------------------
101 dnl WX_CPP_NEW_HEADERS checks whether the compiler has "new" <iostream> header
102 dnl or only the old <iostream.h> one - it may be generally assumed that if
103 dnl <iostream> exists, the other "new" headers (without .h) exist too.
105 dnl call WX_CPP_NEW_HEADERS(actiof-if-true, action-if-false)
106 dnl ---------------------------------------------------------------------------
108 AC_DEFUN([WX_CPP_NEW_HEADERS],
113 AC_CHECK_HEADERS(iostream)
115 if test "$ac_cv_header_iostream" = "yes" ; then
116 ifelse([$1], , :, [$1])
118 ifelse([$2], , :, [$2])
124 dnl ---------------------------------------------------------------------------
125 dnl WX_CPP_BOOL checks whether the C++ compiler has a built in bool type
127 dnl call WX_CPP_BOOL - will define HAVE_BOOL if the compiler supports bool
128 dnl ---------------------------------------------------------------------------
130 AC_DEFUN([WX_CPP_BOOL],
132 AC_CACHE_CHECK([if C++ compiler supports bool], wx_cv_cpp_bool,
156 if test "$wx_cv_cpp_bool" = "yes"; then
161 dnl ---------------------------------------------------------------------------
162 dnl WX_CPP_EXPLICIT checks whether the C++ compiler support the explicit
163 dnl keyword and defines HAVE_EXPLICIT if this is the case
164 dnl ---------------------------------------------------------------------------
166 AC_DEFUN([WX_CPP_EXPLICIT],
168 AC_CACHE_CHECK([if C++ compiler supports the explicit keyword],
174 dnl do the test in 2 steps: first check that the compiler knows about the
175 dnl explicit keyword at all and then verify that it really honours it
178 class Foo { public: explicit Foo(int) {} };
186 class Foo { public: explicit Foo(int) {} };
187 static void TakeFoo(const Foo& foo) { }
203 if test "$wx_cv_explicit" = "yes"; then
204 AC_DEFINE(HAVE_EXPLICIT)
208 dnl ---------------------------------------------------------------------------
209 dnl a slightly better AC_C_BIGENDIAN macro which allows cross-compiling
210 dnl ---------------------------------------------------------------------------
212 AC_DEFUN([WX_C_BIGENDIAN],
213 [AC_CACHE_CHECK([whether byte ordering is bigendian], ac_cv_c_bigendian,
214 [ac_cv_c_bigendian=unknown
215 # See if sys/param.h defines the BYTE_ORDER macro.
216 AC_TRY_COMPILE([#include <sys/types.h>
217 #include <sys/param.h>], [
218 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
220 #endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
221 AC_TRY_COMPILE([#include <sys/types.h>
222 #include <sys/param.h>], [
223 #if BYTE_ORDER != BIG_ENDIAN
225 #endif], ac_cv_c_bigendian=yes, ac_cv_c_bigendian=no)])
226 if test $ac_cv_c_bigendian = unknown; then
227 AC_TRY_RUN([main () {
228 /* Are we little or big endian? From Harbison&Steele. */
232 char c[sizeof (long)];
235 exit (u.c[sizeof (long) - 1] == 1);
236 }], [ac_cv_c_bigendian=no], [ac_cv_c_bigendian=yes], [ac_cv_c_bigendian=unknown])
238 if test $ac_cv_c_bigendian = unknown; then
239 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])
241 if test $ac_cv_c_bigendian = yes; then
242 AC_DEFINE(WORDS_BIGENDIAN)
246 dnl ---------------------------------------------------------------------------
247 dnl override AC_ARG_ENABLE/WITH to cache the results in .cache file
248 dnl ---------------------------------------------------------------------------
250 AC_DEFUN([WX_ARG_CACHE_INIT],
252 wx_arg_cache_file="configarg.cache"
253 echo "loading argument cache $wx_arg_cache_file"
254 rm -f ${wx_arg_cache_file}.tmp
255 touch ${wx_arg_cache_file}.tmp
256 touch ${wx_arg_cache_file}
259 AC_DEFUN([WX_ARG_CACHE_FLUSH],
261 echo "saving argument cache $wx_arg_cache_file"
262 mv ${wx_arg_cache_file}.tmp ${wx_arg_cache_file}
265 dnl this macro checks for a three-valued command line --with argument:
266 dnl possible arguments are 'yes', 'no', 'sys', or 'builtin'
267 dnl usage: WX_ARG_SYS_WITH(option, helpmessage, variable-name)
268 AC_DEFUN([WX_ARG_SYS_WITH],
270 AC_MSG_CHECKING([for --with-$1])
272 AC_ARG_WITH($1, [$2],
274 if test "$withval" = yes; then
275 ac_cv_use_$1='$3=yes'
276 elif test "$withval" = no; then
278 elif test "$withval" = sys; then
279 ac_cv_use_$1='$3=sys'
280 elif test "$withval" = builtin; then
281 ac_cv_use_$1='$3=builtin'
283 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
287 LINE=`grep "$3" ${wx_arg_cache_file}`
288 if test "x$LINE" != x ; then
294 ac_cv_use_$1='$3='$DEFAULT_$3
298 if test "$no_cache" != 1; then
299 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
302 if test "$$3" = yes; then
304 elif test "$$3" = no; then
306 elif test "$$3" = sys; then
307 AC_MSG_RESULT([system version])
308 elif test "$$3" = builtin; then
309 AC_MSG_RESULT([builtin version])
311 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
315 dnl this macro checks for a command line argument and caches the result
316 dnl usage: WX_ARG_WITH(option, helpmessage, variable-name)
317 AC_DEFUN([WX_ARG_WITH],
319 AC_MSG_CHECKING([for --with-$1])
321 AC_ARG_WITH($1, [$2],
323 if test "$withval" = yes; then
324 ac_cv_use_$1='$3=yes'
330 LINE=`grep "$3" ${wx_arg_cache_file}`
331 if test "x$LINE" != x ; then
337 ac_cv_use_$1='$3='$DEFAULT_$3
341 if test "$no_cache" != 1; then
342 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
345 if test "$$3" = yes; then
352 dnl like WX_ARG_WITH but uses AC_ARG_ENABLE instead of AC_ARG_WITH
353 dnl usage: WX_ARG_ENABLE(option, helpmessage, variable-name, enablestring)
355 dnl enablestring is a hack and allows to show "checking for --disable-foo"
356 dnl message when running configure instead of the default "checking for
357 dnl --enable-foo" one whih is useful for the options enabled by default
358 AC_DEFUN([WX_ARG_ENABLE],
361 AC_MSG_CHECKING([for --${enablestring:-enable}-$1])
363 AC_ARG_ENABLE($1, [$2],
365 if test "$enableval" = yes; then
366 ac_cv_use_$1='$3=yes'
372 LINE=`grep "$3" ${wx_arg_cache_file}`
373 if test "x$LINE" != x ; then
379 ac_cv_use_$1='$3='$DEFAULT_$3
383 if test "$no_cache" != 1; then
384 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
387 if test "$$3" = yes; then
395 dnl ===========================================================================
396 dnl Linker features test
397 dnl ===========================================================================
399 dnl ---------------------------------------------------------------------------
400 dnl WX_VERSIONED_SYMBOLS checks whether the linker can create versioned
401 dnl symbols. If it can, sets LDFLAGS_VERSIONING to $CXX flags needed to use
402 dnl version script file named versionfile
404 dnl call WX_VERSIONED_SYMBOLS(versionfile)
405 dnl ---------------------------------------------------------------------------
406 AC_DEFUN([WX_VERSIONED_SYMBOLS],
410 dnl FIXME - doesn't work, Solaris linker doesn't accept wildcards
412 dnl dnl Check for known non-gcc cases:
413 dnl case "${host}" in
415 dnl if test "x$GCC" != "xyes" ; then
416 dnl LDFLAGS_VERSIONING="-M $1"
417 dnl found_versioning=yes
422 dnl Generic check for GCC or GCC-like behaviour (Intel C++, GCC):
423 if test $found_versioning = no ; then
424 AC_CACHE_CHECK([if the linker accepts --version-script], wx_cv_version_script,
426 echo "VER_1 { *; };" >conftest.sym
427 echo "int main() { return 0; }" >conftest.cpp
430 $CXX -o conftest.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
431 -Wl,--version-script,conftest.sym >/dev/null 2>conftest.stderr]) ; then
432 if test -s conftest.stderr ; then
433 wx_cv_version_script=no
435 wx_cv_version_script=yes
438 wx_cv_version_script=no
440 rm -f conftest.output conftest.stderr conftest.sym conftest.cpp
442 if test $wx_cv_version_script = yes ; then
443 LDFLAGS_VERSIONING="-Wl,--version-script,$1"
449 dnl ===========================================================================
450 dnl "3rd party" macros included here because they are not widely available
451 dnl ===========================================================================
453 dnl ---------------------------------------------------------------------------
454 dnl test for availability of iconv()
455 dnl ---------------------------------------------------------------------------
457 dnl From Bruno Haible.
461 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
462 dnl those with the standalone portable GNU libiconv installed).
464 AC_ARG_WITH([libiconv-prefix],
465 [ --with-libiconv-prefix=DIR search for libiconv in DIR/include and DIR/lib], [
466 for dir in `echo "$withval" | tr : ' '`; do
467 if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi
468 if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi
472 AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
473 am_cv_func_iconv="no, consider installing GNU libiconv"
475 AC_TRY_LINK([#include <stdlib.h>
477 [iconv_t cd = iconv_open("","");
478 iconv(cd,NULL,NULL,NULL,NULL);
480 am_cv_func_iconv=yes)
481 if test "$am_cv_func_iconv" != yes; then
484 AC_TRY_LINK([#include <stdlib.h>
486 [iconv_t cd = iconv_open("","");
487 iconv(cd,NULL,NULL,NULL,NULL);
490 am_cv_func_iconv=yes)
494 if test "$am_cv_func_iconv" = yes; then
495 AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
496 AC_CACHE_CHECK([if iconv needs const], wx_cv_func_iconv_const,
504 #if defined(__STDC__) || defined(__cplusplus)
505 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
511 wx_cv_func_iconv_const="no",
512 wx_cv_func_iconv_const="yes"
517 if test "x$wx_cv_func_iconv_const" = "xyes"; then
521 AC_DEFINE_UNQUOTED(ICONV_CONST, $iconv_const,
522 [Define as const if the declaration of iconv() needs const.])
525 if test "$am_cv_lib_iconv" = yes; then
531 dnl ---------------------------------------------------------------------------
532 dnl AC_SYS_LARGEFILE (partly based on the code from autoconf 2.5x)
533 dnl ---------------------------------------------------------------------------
535 dnl WX_SYS_LARGEFILE_TEST
537 dnl NB: original autoconf test was checking if compiler supported 6 bit off_t
538 dnl arithmetic properly but this failed miserably with gcc under Linux
539 dnl whereas the system still supports 64 bit files, so now simply check
540 dnl that off_t is big enough
541 define(WX_SYS_LARGEFILE_TEST,
543 unsigned int field: sizeof(off_t) == 8;
548 dnl WX_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, CACHE-VAR)
549 define(WX_SYS_LARGEFILE_MACRO_VALUE,
551 AC_CACHE_CHECK([for $1 value needed for large files], [$3],
553 AC_TRY_COMPILE([#define $1 $2
554 #include <sys/types.h>],
555 WX_SYS_LARGEFILE_TEST,
561 if test "$$3" != no; then
563 AC_DEFINE_UNQUOTED([$1], [$$3])
570 dnl By default, many hosts won't let programs access large files;
571 dnl one must use special compiler options to get large-file access to work.
572 dnl For more details about this brain damage please see:
573 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
574 AC_DEFUN([AC_SYS_LARGEFILE],
575 [AC_ARG_ENABLE(largefile,
576 [ --disable-largefile omit support for large files])
577 if test "$enable_largefile" != no; then
578 dnl _FILE_OFFSET_BITS==64 is needed for Linux, Solaris, ...
579 dnl _LARGE_FILES -- for AIX
581 WX_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64, ac_cv_sys_file_offset_bits)
582 if test "x$wx_largefile" != "xyes"; then
583 WX_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1, ac_cv_sys_large_files)
586 AC_MSG_CHECKING(if large file support is available)
587 if test "x$wx_largefile" = "xyes"; then
588 AC_DEFINE(HAVE_LARGEFILE_SUPPORT)
590 AC_MSG_RESULT($wx_largefile)
595 dnl Available from the GNU Autoconf Macro Archive at:
596 dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_const_cast.html
598 AC_DEFUN([AC_CXX_CONST_CAST],
599 [AC_CACHE_CHECK(whether the compiler supports const_cast<>,
600 ac_cv_cxx_const_cast,
603 AC_TRY_COMPILE(,[int x = 0;const int& y = x;int& z = const_cast<int&>(y);return z;],
604 ac_cv_cxx_const_cast=yes, ac_cv_cxx_const_cast=no)
607 if test "$ac_cv_cxx_const_cast" = yes; then
608 AC_DEFINE(HAVE_CONST_CAST,,[define if the compiler supports const_cast<>])
612 dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_reinterpret_cast.html
613 AC_DEFUN([AC_CXX_REINTERPRET_CAST],
614 [AC_CACHE_CHECK(whether the compiler supports reinterpret_cast<>,
615 ac_cv_cxx_reinterpret_cast,
618 AC_TRY_COMPILE([#include <typeinfo>
619 class Base { public : Base () {} virtual void f () = 0;};
620 class Derived : public Base { public : Derived () {} virtual void f () {} };
621 class Unrelated { public : Unrelated () {} };
622 int g (Unrelated&) { return 0; }],[
623 Derived d;Base& b=d;Unrelated& e=reinterpret_cast<Unrelated&>(b);return g(e);],
624 ac_cv_cxx_reinterpret_cast=yes, ac_cv_cxx_reinterpret_cast=no)
627 if test "$ac_cv_cxx_reinterpret_cast" = yes; then
628 AC_DEFINE(HAVE_REINTERPRET_CAST,,
629 [define if the compiler supports reinterpret_cast<>])
633 dnl and http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_static_cast.html
634 AC_DEFUN([AC_CXX_STATIC_CAST],
635 [AC_CACHE_CHECK(whether the compiler supports static_cast<>,
636 ac_cv_cxx_static_cast,
639 AC_TRY_COMPILE([#include <typeinfo>
640 class Base { public : Base () {} virtual void f () = 0; };
641 class Derived : public Base { public : Derived () {} virtual void f () {} };
642 int g (Derived&) { return 0; }],[
643 Derived d; Base& b = d; Derived& s = static_cast<Derived&> (b); return g (s);],
644 ac_cv_cxx_static_cast=yes, ac_cv_cxx_static_cast=no)
647 if test "$ac_cv_cxx_static_cast" = yes; then
648 AC_DEFINE(HAVE_STATIC_CAST,, [define if the compiler supports static_cast<>])
652 dnl http://autoconf-archive.cryp.to/ac_cxx_dynamic_cast.html
653 AC_DEFUN([AC_CXX_DYNAMIC_CAST],
654 [AC_CACHE_CHECK(whether the compiler supports dynamic_cast<>,
655 ac_cv_cxx_dynamic_cast,
658 AC_TRY_COMPILE([#include <typeinfo>
659 class Base { public : Base () {} virtual void f () = 0;};
660 class Derived : public Base { public : Derived () {} virtual void f () {} };],[
661 Derived d; Base& b=d; return dynamic_cast<Derived*>(&b) ? 0 : 1;],
662 ac_cv_cxx_dynamic_cast=yes, ac_cv_cxx_dynamic_cast=no)
665 if test "$ac_cv_cxx_dynamic_cast" = yes; then
666 AC_DEFINE(HAVE_DYNAMIC_CAST,,[define if the compiler supports dynamic_cast<>])