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, lib 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],
54 for ac_extension in a so sl dylib dll.a; do
55 if test -f "$ac_dir/lib$2.$ac_extension"; then
56 ac_find_libraries=$ac_dir
63 dnl ---------------------------------------------------------------------------
64 dnl return list of standard library paths
65 dnl ---------------------------------------------------------------------------
66 dnl return all default locations:
67 dnl - /usr/lib: standard
68 dnl - /usr/lib32: n32 ABI on IRIX
69 dnl - /usr/lib64: n64 ABI on IRIX
70 dnl - /usr/lib/64: 64 bit ABI on Solaris and Linux x86-64
72 dnl NB: if any of directories in the list is not a subdir of /usr, code setting
73 dnl wx_cv_std_libpath needs to be updated
74 AC_DEFUN([WX_STD_LIBPATH], [/usr/lib /usr/lib32 /usr/lib/64 /usr/lib64])
76 dnl ---------------------------------------------------------------------------
77 dnl Path to include, already defined
78 dnl ---------------------------------------------------------------------------
79 AC_DEFUN([WX_INCLUDE_PATH_EXIST],
81 dnl never add -I/usr/include to the CPPFLAGS
82 if test "x$1" = "x/usr/include"; then
85 echo "$2" | grep "\-I$1" > /dev/null
87 if test $result = 0; then
90 ac_path_to_include=" -I$1"
95 dnl ---------------------------------------------------------------------------
96 dnl Usage: WX_LINK_PATH_EXIST(path, libpath)
98 dnl Set ac_path_to_link to nothing if path is already in libpath of to -Lpath
99 dnl if it is not, so that libpath can be set to "$libpath$ac_path_to_link"
100 dnl after calling this function
101 dnl ---------------------------------------------------------------------------
102 AC_DEFUN([WX_LINK_PATH_EXIST],
104 dnl never add -L/usr/libXXX explicitely to libpath
105 if test "$1" = "default location"; then
108 echo "$2" | grep "\-L$1" > /dev/null
110 if test $result = 0; then
113 ac_path_to_link=" -L$1"
118 dnl ===========================================================================
119 dnl C++ features test
120 dnl ===========================================================================
122 dnl ---------------------------------------------------------------------------
123 dnl WX_CPP_NEW_HEADERS checks whether the compiler has "new" <iostream> header
124 dnl or only the old <iostream.h> one - it may be generally assumed that if
125 dnl <iostream> exists, the other "new" headers (without .h) exist too.
127 dnl call WX_CPP_NEW_HEADERS(actiof-if-true, action-if-false)
128 dnl ---------------------------------------------------------------------------
130 AC_DEFUN([WX_CPP_NEW_HEADERS],
135 AC_CHECK_HEADERS(iostream)
137 if test "$ac_cv_header_iostream" = "yes" ; then
138 ifelse([$1], , :, [$1])
140 ifelse([$2], , :, [$2])
146 dnl ---------------------------------------------------------------------------
147 dnl WX_CPP_BOOL checks whether the C++ compiler has a built in bool type
149 dnl call WX_CPP_BOOL - will define HAVE_BOOL if the compiler supports bool
150 dnl ---------------------------------------------------------------------------
152 AC_DEFUN([WX_CPP_BOOL],
154 AC_CACHE_CHECK([if C++ compiler supports bool], wx_cv_cpp_bool,
178 if test "$wx_cv_cpp_bool" = "yes"; then
183 dnl ---------------------------------------------------------------------------
184 dnl WX_CPP_EXPLICIT checks whether the C++ compiler support the explicit
185 dnl keyword and defines HAVE_EXPLICIT if this is the case
186 dnl ---------------------------------------------------------------------------
188 AC_DEFUN([WX_CPP_EXPLICIT],
190 AC_CACHE_CHECK([if C++ compiler supports the explicit keyword],
196 dnl do the test in 2 steps: first check that the compiler knows about the
197 dnl explicit keyword at all and then verify that it really honours it
200 class Foo { public: explicit Foo(int) {} };
208 class Foo { public: explicit Foo(int) {} };
209 static void TakeFoo(const Foo& foo) { }
225 if test "$wx_cv_explicit" = "yes"; then
226 AC_DEFINE(HAVE_EXPLICIT)
230 dnl ---------------------------------------------------------------------------
231 dnl a slightly better AC_C_BIGENDIAN macro which allows cross-compiling
232 dnl ---------------------------------------------------------------------------
234 AC_DEFUN([WX_C_BIGENDIAN],
235 [AC_CACHE_CHECK([whether byte ordering is bigendian], ac_cv_c_bigendian,
236 [ac_cv_c_bigendian=unknown
237 # See if sys/param.h defines the BYTE_ORDER macro.
238 AC_TRY_COMPILE([#include <sys/types.h>
239 #include <sys/param.h>], [
240 #if !BYTE_ORDER || !BIG_ENDIAN || !LITTLE_ENDIAN
242 #endif], [# It does; now see whether it defined to BIG_ENDIAN or not.
243 AC_TRY_COMPILE([#include <sys/types.h>
244 #include <sys/param.h>], [
245 #if BYTE_ORDER != BIG_ENDIAN
247 #endif], ac_cv_c_bigendian=yes, ac_cv_c_bigendian=no)])
248 if test $ac_cv_c_bigendian = unknown; then
249 AC_TRY_RUN([main () {
250 /* Are we little or big endian? From Harbison&Steele. */
254 char c[sizeof (long)];
257 exit (u.c[sizeof (long) - 1] == 1);
258 }], [ac_cv_c_bigendian=no], [ac_cv_c_bigendian=yes], [ac_cv_c_bigendian=unknown])
260 if test $ac_cv_c_bigendian = unknown; then
261 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])
263 if test $ac_cv_c_bigendian = yes; then
264 AC_DEFINE(WORDS_BIGENDIAN)
268 dnl ---------------------------------------------------------------------------
269 dnl override AC_ARG_ENABLE/WITH to cache the results in .cache file
270 dnl ---------------------------------------------------------------------------
272 AC_DEFUN([WX_ARG_CACHE_INIT],
274 wx_arg_cache_file="configarg.cache"
275 echo "loading argument cache $wx_arg_cache_file"
276 rm -f ${wx_arg_cache_file}.tmp
277 touch ${wx_arg_cache_file}.tmp
278 touch ${wx_arg_cache_file}
281 AC_DEFUN([WX_ARG_CACHE_FLUSH],
283 echo "saving argument cache $wx_arg_cache_file"
284 mv ${wx_arg_cache_file}.tmp ${wx_arg_cache_file}
287 dnl this macro checks for a three-valued command line --with argument:
288 dnl possible arguments are 'yes', 'no', 'sys', or 'builtin'
289 dnl usage: WX_ARG_SYS_WITH(option, helpmessage, variable-name)
290 AC_DEFUN([WX_ARG_SYS_WITH],
292 AC_MSG_CHECKING([for --with-$1])
294 AC_ARG_WITH($1, [$2],
296 if test "$withval" = yes; then
297 ac_cv_use_$1='$3=yes'
298 elif test "$withval" = no; then
300 elif test "$withval" = sys; then
301 ac_cv_use_$1='$3=sys'
302 elif test "$withval" = builtin; then
303 ac_cv_use_$1='$3=builtin'
305 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
309 LINE=`grep "$3" ${wx_arg_cache_file}`
310 if test "x$LINE" != x ; then
316 ac_cv_use_$1='$3='$DEFAULT_$3
320 if test "$no_cache" != 1; then
321 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
324 if test "$$3" = yes; then
326 elif test "$$3" = no; then
328 elif test "$$3" = sys; then
329 AC_MSG_RESULT([system version])
330 elif test "$$3" = builtin; then
331 AC_MSG_RESULT([builtin version])
333 AC_MSG_ERROR([Invalid value for --with-$1: should be yes, no, sys, or builtin])
337 dnl this macro checks for a command line argument and caches the result
338 dnl usage: WX_ARG_WITH(option, helpmessage, variable-name, [withstring])
339 AC_DEFUN([WX_ARG_WITH],
342 AC_MSG_CHECKING([for --${withstring:-with}-$1])
344 AC_ARG_WITH($1, [$2],
346 if test "$withval" = yes; then
347 ac_cv_use_$1='$3=yes'
353 LINE=`grep "$3" ${wx_arg_cache_file}`
354 if test "x$LINE" != x ; then
360 ac_cv_use_$1='$3='$DEFAULT_$3
364 if test "$no_cache" != 1; then
365 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
368 if test "$$3" = yes; then
375 dnl like WX_ARG_WITH but uses AC_ARG_ENABLE instead of AC_ARG_WITH
376 dnl usage: WX_ARG_ENABLE(option, helpmessage, variable-name, enablestring)
378 dnl enablestring is a hack and allows to show "checking for --disable-foo"
379 dnl message when running configure instead of the default "checking for
380 dnl --enable-foo" one whih is useful for the options enabled by default
381 AC_DEFUN([WX_ARG_ENABLE],
384 AC_MSG_CHECKING([for --${enablestring:-enable}-$1])
386 AC_ARG_ENABLE($1, [$2],
388 if test "$enableval" = yes; then
389 ac_cv_use_$1='$3=yes'
395 LINE=`grep "$3" ${wx_arg_cache_file}`
396 if test "x$LINE" != x ; then
402 ac_cv_use_$1='$3='$DEFAULT_$3
406 if test "$no_cache" != 1; then
407 echo $ac_cv_use_$1 >> ${wx_arg_cache_file}.tmp
410 if test "$$3" = yes; then
418 dnl ===========================================================================
419 dnl Linker features test
420 dnl ===========================================================================
422 dnl ---------------------------------------------------------------------------
423 dnl WX_VERSIONED_SYMBOLS checks whether the linker can create versioned
424 dnl symbols. If it can, sets LDFLAGS_VERSIONING to $CXX flags needed to use
425 dnl version script file named versionfile
427 dnl call WX_VERSIONED_SYMBOLS(versionfile)
428 dnl ---------------------------------------------------------------------------
429 AC_DEFUN([WX_VERSIONED_SYMBOLS],
433 dnl FIXME - doesn't work, Solaris linker doesn't accept wildcards
435 dnl dnl Check for known non-gcc cases:
436 dnl case "${host}" in
438 dnl if test "x$GCC" != "xyes" ; then
439 dnl LDFLAGS_VERSIONING="-M $1"
440 dnl found_versioning=yes
445 dnl Generic check for GCC or GCC-like behaviour (Intel C++, GCC):
446 if test $found_versioning = no ; then
447 AC_CACHE_CHECK([if the linker accepts --version-script], wx_cv_version_script,
449 echo "VER_1 { *; };" >conftest.sym
450 echo "int main() { return 0; }" >conftest.cpp
453 $CXX -o conftest.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
454 -Wl,--version-script,conftest.sym >/dev/null 2>conftest.stderr]) ; then
455 if test -s conftest.stderr ; then
456 wx_cv_version_script=no
458 wx_cv_version_script=yes
461 wx_cv_version_script=no
464 dnl There's a problem in some old linkers with --version-script that
465 dnl can cause linking to fail when you have objects with vtables in
466 dnl libs 3 deep. This is known to happen in netbsd and openbsd with
469 dnl To test for this we need to make some shared libs and
470 dnl unfortunately we can't be sure of the right way to do that. If the
471 dnl first two compiles don't succeed then it looks like the test isn't
472 dnl working and the result is ignored, but if OTOH the first two
473 dnl succeed but the third does not then the bug has been detected and
474 dnl the --version-script flag is dropped.
475 if test $wx_cv_version_script = yes
477 echo "struct B { virtual ~B() { } }; \
478 struct D : public B { }; \
479 void F() { D d; }" > conftest.cpp
482 $CXX -shared -fPIC -o conftest1.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
483 -Wl,--version-script,conftest.sym >/dev/null 2>/dev/null]) &&
485 $CXX -shared -fPIC -o conftest2.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
486 -Wl,--version-script,conftest.sym conftest1.output >/dev/null 2>/dev/null])
489 $CXX -shared -fPIC -o conftest3.output $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.cpp
490 -Wl,--version-script,conftest.sym conftest2.output conftest1.output >/dev/null 2>/dev/null])
492 wx_cv_version_script=yes
494 wx_cv_version_script=no
499 rm -f conftest.output conftest.stderr conftest.sym conftest.cpp
500 rm -f conftest1.output conftest2.output conftest3.output
502 if test $wx_cv_version_script = yes ; then
503 LDFLAGS_VERSIONING="-Wl,--version-script,$1"
509 dnl ===========================================================================
510 dnl "3rd party" macros included here because they are not widely available
511 dnl ===========================================================================
513 dnl ---------------------------------------------------------------------------
514 dnl test for availability of iconv()
515 dnl ---------------------------------------------------------------------------
517 dnl From Bruno Haible.
521 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
522 dnl those with the standalone portable GNU libiconv installed).
524 AC_ARG_WITH([libiconv-prefix],
525 [ --with-libiconv-prefix=DIR search for libiconv in DIR/include and DIR/lib], [
526 for dir in `echo "$withval" | tr : ' '`; do
527 if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi
528 if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi
532 AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
533 am_cv_func_iconv="no, consider installing GNU libiconv"
535 AC_TRY_LINK([#include <stdlib.h>
537 [iconv_t cd = iconv_open("","");
538 iconv(cd,NULL,NULL,NULL,NULL);
540 am_cv_func_iconv=yes)
541 if test "$am_cv_func_iconv" != yes; then
544 AC_TRY_LINK([#include <stdlib.h>
546 [iconv_t cd = iconv_open("","");
547 iconv(cd,NULL,NULL,NULL,NULL);
550 am_cv_func_iconv=yes)
554 if test "$am_cv_func_iconv" = yes; then
555 AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
556 AC_CACHE_CHECK([if iconv needs const], wx_cv_func_iconv_const,
564 #if defined(__STDC__) || defined(__cplusplus)
565 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
571 wx_cv_func_iconv_const="no",
572 wx_cv_func_iconv_const="yes"
577 if test "x$wx_cv_func_iconv_const" = "xyes"; then
581 AC_DEFINE_UNQUOTED(ICONV_CONST, $iconv_const,
582 [Define as const if the declaration of iconv() needs const.])
585 if test "$am_cv_lib_iconv" = yes; then
591 dnl ---------------------------------------------------------------------------
592 dnl AC_SYS_LARGEFILE (partly based on the code from autoconf 2.5x)
593 dnl ---------------------------------------------------------------------------
595 dnl WX_SYS_LARGEFILE_TEST
597 dnl NB: original autoconf test was checking if compiler supported 6 bit off_t
598 dnl arithmetic properly but this failed miserably with gcc under Linux
599 dnl whereas the system still supports 64 bit files, so now simply check
600 dnl that off_t is big enough
601 define(WX_SYS_LARGEFILE_TEST,
603 unsigned int field: sizeof(off_t) == 8;
608 dnl WX_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, VALUE, CACHE-VAR)
609 define(WX_SYS_LARGEFILE_MACRO_VALUE,
611 AC_CACHE_CHECK([for $1 value needed for large files], [$3],
613 AC_TRY_COMPILE([#define $1 $2
614 #include <sys/types.h>],
615 WX_SYS_LARGEFILE_TEST,
621 if test "$$3" != no; then
623 AC_DEFINE_UNQUOTED([$1], [$$3])
630 dnl By default, many hosts won't let programs access large files;
631 dnl one must use special compiler options to get large-file access to work.
632 dnl For more details about this brain damage please see:
633 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
634 AC_DEFUN([AC_SYS_LARGEFILE],
635 [AC_ARG_ENABLE(largefile,
636 [ --disable-largefile omit support for large files])
637 if test "$enable_largefile" != no; then
638 dnl _FILE_OFFSET_BITS==64 is needed for Linux, Solaris, ...
639 dnl _LARGE_FILES -- for AIX
641 WX_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS, 64, ac_cv_sys_file_offset_bits)
642 if test "x$wx_largefile" != "xyes"; then
643 WX_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES, 1, ac_cv_sys_large_files)
646 AC_MSG_CHECKING(if large file support is available)
647 if test "x$wx_largefile" = "xyes"; then
648 AC_DEFINE(HAVE_LARGEFILE_SUPPORT)
650 AC_MSG_RESULT($wx_largefile)
655 dnl Available from the GNU Autoconf Macro Archive at:
656 dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_const_cast.html
658 AC_DEFUN([AC_CXX_CONST_CAST],
659 [AC_CACHE_CHECK(whether the compiler supports const_cast<>,
660 ac_cv_cxx_const_cast,
663 AC_TRY_COMPILE(,[int x = 0;const int& y = x;int& z = const_cast<int&>(y);return z;],
664 ac_cv_cxx_const_cast=yes, ac_cv_cxx_const_cast=no)
667 if test "$ac_cv_cxx_const_cast" = yes; then
668 AC_DEFINE(HAVE_CONST_CAST,,[define if the compiler supports const_cast<>])
672 dnl http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_reinterpret_cast.html
673 AC_DEFUN([AC_CXX_REINTERPRET_CAST],
674 [AC_CACHE_CHECK(whether the compiler supports reinterpret_cast<>,
675 ac_cv_cxx_reinterpret_cast,
678 AC_TRY_COMPILE([#include <typeinfo>
679 class Base { public : Base () {} virtual void f () = 0;};
680 class Derived : public Base { public : Derived () {} virtual void f () {} };
681 class Unrelated { public : Unrelated () {} };
682 int g (Unrelated&) { return 0; }],[
683 Derived d;Base& b=d;Unrelated& e=reinterpret_cast<Unrelated&>(b);return g(e);],
684 ac_cv_cxx_reinterpret_cast=yes, ac_cv_cxx_reinterpret_cast=no)
687 if test "$ac_cv_cxx_reinterpret_cast" = yes; then
688 AC_DEFINE(HAVE_REINTERPRET_CAST,,
689 [define if the compiler supports reinterpret_cast<>])
693 dnl and http://www.gnu.org/software/ac-archive/htmldoc/ac_cxx_static_cast.html
694 AC_DEFUN([AC_CXX_STATIC_CAST],
695 [AC_CACHE_CHECK(whether the compiler supports static_cast<>,
696 ac_cv_cxx_static_cast,
699 AC_TRY_COMPILE([#include <typeinfo>
700 class Base { public : Base () {} virtual void f () = 0; };
701 class Derived : public Base { public : Derived () {} virtual void f () {} };
702 int g (Derived&) { return 0; }],[
703 Derived d; Base& b = d; Derived& s = static_cast<Derived&> (b); return g (s);],
704 ac_cv_cxx_static_cast=yes, ac_cv_cxx_static_cast=no)
707 if test "$ac_cv_cxx_static_cast" = yes; then
708 AC_DEFINE(HAVE_STATIC_CAST,, [define if the compiler supports static_cast<>])
712 dnl http://autoconf-archive.cryp.to/ac_cxx_dynamic_cast.html
713 AC_DEFUN([AC_CXX_DYNAMIC_CAST],
714 [AC_CACHE_CHECK(whether the compiler supports dynamic_cast<>,
715 ac_cv_cxx_dynamic_cast,
718 AC_TRY_COMPILE([#include <typeinfo>
719 class Base { public : Base () {} virtual void f () = 0;};
720 class Derived : public Base { public : Derived () {} virtual void f () {} };],[
721 Derived d; Base& b=d; return dynamic_cast<Derived*>(&b) ? 0 : 1;],
722 ac_cv_cxx_dynamic_cast=yes, ac_cv_cxx_dynamic_cast=no)
725 if test "$ac_cv_cxx_dynamic_cast" = yes; then
726 AC_DEFINE(HAVE_DYNAMIC_CAST,,[define if the compiler supports dynamic_cast<>])